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 'phone_number' in request.FILES: profile.picture = request.FILES['phone_number'] # 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( 'homepage/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
def farmerlogoutt(request): logout(request) form = UserForm(request.POST or None) context = { "form": form, } return render(request, 'homepage/farmer_login.html', context)
def register1(request): form = UserForm(request.POST or None) if form.is_valid(): user = form.save(commit=False) username = form.cleaned_data['username'] password = form.cleaned_data['password'] user.set_password(password) user.save() user = authenticate(username=username, password=password) if user is not None: if user.is_active: auth_login(request, user) farmers = farmer.objects.filter(user=request.user) return render(request, 'homepage/create_retailer_extra.html', {'farmers': farmers}) context = { "form": form, } return render(request, 'homepage/register1.html', context)
def register(request): registered=False if request.method=="POST": user_form=UserForm(data=request.POST) re_password=request.POST.get('re_password') password=request.POST.get('password') print(password,"\n",re_password) if re_password==password: if user_form.is_valid(): user=user_form.save() user.set_password(user.password) #hashing the password user.save() #save hash password to database registered=True else: print("something is fishy") else: raise forms.ValidationError("Passwords do not match.Please Re_enter them") raise forms.ValidationError("Passwords do not match") else: user_form=UserForm() return render(request,'homepage/registration.html',{'user_form':user_form,'registered':registered,})
def register(request): registered = False if request.method == 'POST': # Get info from "both" forms # It appears as one form to the user on the .html page user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) # Check to see both forms are valid if user_form.is_valid() and profile_form.is_valid(): # Save User Form to Database user=user_form.save() # Hash the password user.set_password(user.password) # Update with Hashed password user.save() # Now we deal with the extra info! # Can't commit yet because we still need to manipulate profile = profile_form.save(commit=False) # Set One to One relationship between # UserForm and UserProfileInfoForm profile.user = user # Check if they provided a profile picture if 'profile_pic' in request.FILES: print('found it') # If yes, then grab it from the POST form reply profile.profile_pic = request.FILES['profile_pic'] # Now save model profile.save() # Registration Successful! registered = True else: # One of the forms was invalid if this else gets called. print(user_form.errors, profile_form.errors) else: # Was not an HTTP post so we just render the forms as blank. user_form = UserForm() profile_form = UserProfileInfoForm() # This is the render and context dictionary to feed # back to the registration.html file page. return render(request,'homepage/registration.html', {'user_form':user_form, 'profile_form':profile_form, 'registered':registered})
def register(request): if request.user: if request.user.is_authenticated: user_logout(request) registered = False if request.method == 'POST': # print("Checkpoint 1") user_form = UserForm(request.POST, request.FILES) profile_form = UserProfileInfoForm(request.POST,request.FILES) if user_form.is_valid() and profile_form.is_valid(): # print("Checkpoint 2") user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'profile_pic' in request.FILES: # print('found it') if os.getenv('GAE_APPLICATION', None): file_obj = request.FILES['profile_pic'] # print(file_obj) destination_blob_name= "profile_pics/" + user.username + "_profile_pic.jpg" bucket_name = os.environ.get("BUCKET_NAME") upload_blob(bucket_name,file_obj, destination_blob_name) else: profile.profile_pic = request.FILES['profile_pic'] if 'resume' in request.FILES: if os.getenv('GAE_APPLICATION', None): file_obj = request.FILES['resume'] # print(file_obj) destination_blob_name= "resume/" + user.username + "_resume.pdf" bucket_name = os.environ.get("BUCKET_NAME") upload_blob(bucket_name,file_obj, destination_blob_name) profile.resume = None profile.profile_pic= None profile.save() else: print("Saving locally") profile.resume = request.FILES['resume'] profile.save() registered = True else: print("Checkpoint 4") print(user_form.errors,profile_form.errors) else: # print("Checkpoint 5") user_form = UserForm() profile_form = UserProfileInfoForm() return render(request,'./registration.html', {'user_form':user_form, 'profile_form':profile_form,'registered':registered})
def reset_password(request): print(request.user) if request.method == 'GET': user_form = UserForm() return render(request, './reset_password.html', {'user_form': user_form}) else: user_form = UserForm(request.POST, request.FILES) if user_form.is_valid(): user = user_form.save() user.reset_password(user.password) user.save() return render(request, './login.html', {}) else: return HttpResponse("Invalid credentials")
def register(request): registered = False if request.method == "POST": user_form = UserForm(data=request.POST) re_password = request.POST.get('re_password') password = request.POST.get('password') username = request.POST.get('username') email = request.POST.get('email') print(password, "\n", re_password) if re_password == password: if user_form.is_valid(): user = user_form.save() user.set_password(user.password) #hashing the password user.save() #save hash password to database registered = True AccountBalance.objects.create(user=user, balance=100) user = authenticate(username=username, password=password) id = User.objects.get(username=user.username).pk print("going") else: print("something is fishy") else: raise forms.ValidationError( "Passwords do not match.Please Re_enter them") raise forms.ValidationError("Passwords do not match") else: user_form = UserForm() return render(request, 'homepage/registration.html', { 'user_form': user_form, 'registered': registered, })
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 'phone_number' in request.FILES: profile.picture = request.FILES['phone_number'] # 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( 'homepage/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered }, context)