def register(request): if request.method == 'POST': form_1 = RegistrationForm(request.POST) form_2 = UserProfileForm(request.POST) if form_1.is_valid() and form_2.is_valid(): new_user = form_1.save(commit=False) new_user.set_password(form_1.cleaned_data['password1']) new_user.save() UserProfile.objects.create(user=new_user, USN=form_2.cleaned_data['USN'], year=form_2.cleaned_data['year'], sem=form_2.cleaned_data['sem'], phone=form_2.cleaned_data['phone']) #subject = 'Thank you for registering with Book-Share' #message = 'Dear User,\n\n Hope you take the best advantage of UVCE Book-share platform . Have a nice time !\n\n Thank You' #from_email = settings.EMAIL_HOST_USER #to_list = [save_1.email] #send_mail(subject,message,from_email,to_list,fail_silently=True) messages.success(request, 'Thank you for registering ! Login Here ') return redirect('/login/') else: form_1 = RegistrationForm() form_2 = UserProfileForm() args = {'form_1': form_1, 'form_2': form_2} return render(request, 'account/register.html', args)
def signup_view(request): if request.method == "POST": user_profile_form = UserProfileForm(request.POST,request.FILES) user_form = UserForm(request.POST) if user_form.is_valid() and user_profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() user_profile = user_profile_form.save(commit=False) user_profile.user = user; if 'profile_image' in request.FILES: user_profile.profile_image = request.FILES['profile_image'] user_profile.save() return redirect("/login/") else: return HttpResponse("Form Not Valid !") else: user_form = UserForm() user_profile_form = UserProfileForm() context_dict ={"user_form":user_form,"user_profile_form":user_profile_form}; return render(request,'signup.html',context_dict)
def add_user(request): if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() try: user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() registered = True return redirect(reverse('sign-in')) except: return redirect(reverse('sign-in')) else: print (user_form.errors, profile_form.errors) return redirect(reverse('register')) else: return redirect(reverse('sign-in'))
def register(request): # Like before, get the request's context. context = RequestContext(request) # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user # Did the user provide a profile picture? # If so, we need to get it from the input form and put it in the UserProfile model. if 'picture' in request.FILES: profile.picture = request.FILES['picture'] # Now we save the UserProfile model instance. profile.save() # Update our variable to tell the template registration was successful. registered = True # Invalid form or forms - mistakes or something else? # Print problems to the terminal. # They'll also be shown to the user. else: print user_form.errors, profile_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render_to_response( 'login/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
def register(request): registered = False user_form = UserForm() profile_form = UserProfileForm() # Prevent logged in users from registering again if request.user.is_authenticated(): return redirect(reverse('index')) else: return render(request, 'register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) profile_form = UserProfileForm(request.POST) if form.is_valid() and profile_form.is_valid(): user = User.objects.create_user( username=form.cleaned_data['username'], password=form.cleaned_data['password'], email=form.cleaned_data['email'], first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], ) # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user #print profile_form.phone # Did the user provide a profile picture? # If so, we need to get it from the input form and put it in the UserProfile model. if 'picture' in request.FILES: profile.picture = request.FILES['picture'] # Now we save the UserProfile model instance. profile.save() return HttpResponseRedirect('/register/success/') else: form = RegistrationForm() profile_form = UserProfileForm() variables = RequestContext(request, { 'form': form, 'profile_form': profile_form }) return render_to_response( 'registration/register.html', variables, )
def add_instructor(request): if request.user.is_authenticated: if request.user.is_staff: instructor_registered = 0 if request.method == 'POST': register = UserForm(request.POST) registerprofile = UserProfileForm(request.POST) if register.is_valid() and registerprofile.is_valid(): newuser = register.save(commit=False) newuser.set_password(register.cleaned_data['password']) newuser.username = newuser.email newuser.save() newuser_extra = registerprofile.save(commit=False) newuser_extra.user = newuser newuser_extra.save() instructor_registered = 1 else: return render( request, 'add_instructor.html', { 'register': register, 'registerprofile': registerprofile, 'instructor_registered': instructor_registered }) register = UserForm() registerprofile = UserProfileForm() return render( request, 'add_instructor.html', { 'register': register, 'registerprofile': registerprofile, 'instructor_registered': instructor_registered }) else: return HttpResponseRedirect('/instructor/viewdeadline/') else: return HttpResponseRedirect("/login")
def signup_view(request): if request.method == "POST": user_profile_form = UserProfileForm(request.POST, request.FILES) user_form = UserForm(request.POST) if user_form.is_valid() and user_profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() user_profile = user_profile_form.save(commit=False) user_profile.user = user if 'profile_image' in request.FILES: user_profile.profile_image = request.FILES['profile_image'] user_profile.save() return redirect("/login/") else: return HttpResponse("Form Not Valid !") else: user_form = UserForm() user_profile_form = UserProfileForm() context_dict = { "user_form": user_form, "user_profile_form": user_profile_form } return render(request, 'signup.html', context_dict)
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() # user.set_password(user.password) profile = profile_form.save(commit=False) profile.user = user # profile.save() if 'profile_pic' in request.FILES: print('found it') profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileForm() return render( request, 'login/registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def registration(request): if request.method == 'POST': try: user_exists = User.objects.get(username=request.POST['username']) return Response("Username already taken") except User.DoesNotExist: uform = UserForm(data=request.POST) pform = UserProfileForm(data=request.POST) if uform.is_valid() and pform.is_valid(): user = uform.save() pw = user.password user.set_password(pw) user.save() profile = pform.save(commit=False) profile.user = user profile.save() return Response('/register success') else: form = UserForm() return Response('in post') return Response('register unsuccessful', )
def register(request): # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user # Did the user provide a profile picture? # If so, we need to get it from the input form and put it in the UserProfile model. if 'picture' in request.FILES: profile.picture = request.FILES['picture'] # Now we save the UserProfile model instance. profile.save() # Update our variable to tell the template registration was successful. registered = True # Invalid form or forms - mistakes or something else? # Print problems to the terminal. # They'll also be shown to the user. else: print user_form.errors, profile_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render( request, 'login/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def userprofile_form(request): if request.method == 'POST': form = UserProfileForm(request.POST) if form.is_valid(): form.save() return redirect('Profile:userprofile_form') else: form = UserProfileForm() #args = {'form': form} return render(request, 'Profile/userprofile_form.html', {'form': form})
def edit(request): if request.method == 'POST': profile_form = UserProfileForm(instance=request.user.userprofile, data=request.POST, files=request.FILES) try: if profile_form.is_valid(): profile_form.save() messages.success(request, "Your profile was updated successfully ") return redirect('/me/') except Exception as e: messages.warning(request, "Your profile could not be updated: Error{} ".format(e)) return redirect('/me/') else: profile_form = UserProfileForm(instance=request.user.userprofile) return render(request, 'account/edit.html', {'profile_form': profile_form})