def edit_profile(request): url = '/rango/' try: profile = request.user.userprofile except UserProfile.DoesNotExist: profile = UserProfile(user=request.user) if request.method == 'POST': profile_form = UserProfileForm(data=request.POST, instance=profile) if profile_form.is_valid(): profile_form.save(commit=False) if 'picture' in request.FILES: print "picture" profile.picture = request.FILES['picture'] profile.save() return redirect(url) else: print profile_form.errors else: profile_form = UserProfileForm(instance=profile) return render(request, 'rango/edit_profile.html', {'profile_form': profile_form} )
def register(request): if request.method == 'POST': user_form = UserForm(data=request.POST) if user_form.is_valid(): user = User() user.email = user_form.cleaned_data['email'] user.username = user.email user.set_password(user_form.cleaned_data['password']) user.save() user_profile = UserProfile() user_profile.user = user user_profile.website = user_form.cleaned_data['website'] if 'picture' in request.FILES: user_profile.picture = request.FILES['picture'] user_profile.save() login(request, user) send_confirmation_email(request, user) messages.success(request,'Registration successfully happened. Now confirm your email.') return redirect('index') else: print(user_form.errors) messages.error(request,'Check out your data, invalid form!.') else: user_form = UserForm() context_dict ={ 'user_form': user_form,} return render(request,'auth/register.html', context_dict)
def register(self, request, form_class): new_user = super(MyRegistrationView, self).register(request, form_class) user_profile = UserProfile() user_profile.user = new_user user_profile.website = form_class.cleaned_data['website'] user_profile.picture = form_class.cleaned_data['picture'] user_profile.save() return user_profile
def add_profile(request): if request.method == 'POST': name = str(request.GET[u'user']) user = User.objects.get(username=name) profile = UserProfile(user=user) profile.website = request.POST[u'website'] profile.picture = request.FILES['picture'] profile.save() return redirect('/rango/') else: profile = UserProfileForm() return render(request, 'rango/add_profile.html', {'profile': profile})
def add_user(user): try: u = User.objects.get(username=user['email']) except User.DoesNotExist: u = User() u.email = user['email'] u.username = user['email'] u.set_password(user['password']) u.save() try: user_profile = UserProfile.objects.get(user__username=user['email']) except UserProfile.DoesNotExist: user_profile = UserProfile() user_profile.user = u user_profile.website = user['website'] user_profile.save()
def register(self, request, **cleaned_data): # Create a new User username, email, password = cleaned_data['username'], cleaned_data[ 'email'], cleaned_data['password1'] new_user_object = UserModel().objects.create_user( username, email, password) # And links that user to a new (empty) UserProfile profile = UserProfile(user=new_user_object) profile.save() new_user = authenticate(username=username, password=password) login(request, new_user) signals.user_registered.send(sender=self.__class__, user=new_user, request=request) return new_user
if (Episode.objects.filter(show_link=stream).count() < 1): a = Episode(show=p, show_link=stream, season_episode=title) a.save() getLatestEpisodes() # TESTING CREATING FAKE USERS # USERNAME: USMAN PW:USMAN # USERNAME: MICHAEL PW:MICHAEL if authenticate(username='******', password='******')==None: a = User.objects.create_user(username='******', password='******', email='*****@*****.**') a.save() b = UserProfile(user_id=a.id) b.newuser = False b.save() else: a = authenticate(username='******', password='******') # if authenticate(username='******', password='******')==None: # c = User.objects.create_user(username='******', password='******', email='*****@*****.**', last_name='15146210791') # d = UserProfile(user_id=c.id) # d.newuser = False # c.save() # d.save() # else: # c = authenticate(username='******', password='******') for show in TvShows.objects.all(): show.users.add(a) b = UserProfile.objects.get(user=a)
a = Episode(show=p, show_link=stream, season_episode=title) a.save() getLatestEpisodes() # TESTING CREATING SAMPLE USERS # USERNAME: USMAN PW:USMAN # USERNAME: MICHAEL PW:MICHAEL if authenticate(username='******', password='******')==None: a = User.objects.create_user(username='******', password='******', email='*****@*****.**') a.save() b = UserProfile(user_id=a.id) b.newuser = False b.email_notification = False b.save() else: a = authenticate(username='******', password='******') if authenticate(username='******', password='******')==None: c = User.objects.create_user(username='******', password='******', email='*****@*****.**', last_name='15146210791') d = UserProfile(user_id=c.id) d.newuser = False c.save() d.email_notification = False d.save() else: c = authenticate(username='******', password='******') for show in TvShows.objects.all(): show.users.add(a)