def passwordChange(request): if request.method == 'POST': forms = passwordForm(request.POST) # forms = UserFingerprintForm(request.POST,request.FILES,) if forms.is_valid(): password1 = forms.cleaned_data['password1'] password2 = forms.cleaned_data['password2'] attemptUser = AccessAttempt.objects.last() if password1 == password2: try: theuser = User.objects.filter(email=attemptUser.username) for object in theuser: object.password = make_password(password1) object.save() attemptUser.delete() messages.success(request, f'Password changed successfully!') return redirect('accounts:user_login') except User.DoesNotExist as e: messages.error(request, f'User Doesnot Exist') else: messages.error(request, "Passwords Donot Match.") else: forms = passwordForm() context = { 'forms': forms, } return render(request, 'accounts/password_change_form.html', context)
def OTPCheck(request): if request.method == 'POST': forms = OTPCheckForm( request.POST, request.FILES, ) if forms.is_valid(): gotOtp = forms.cleaned_data.get("otp") print(otp, gotOtp) if int(otp) == int(gotOtp): result = "matches" return redirect('accounts:password_change') else: result = "doesn't match" messages.error(request, f'Invalid OTP!') return redirect('accounts:OTP') else: forms = OTPCheckForm() result = 0 attemptUser = AccessAttempt.objects.first() context = { 'o': result, 'forms': forms, 'otp': otp, 'uSir': attemptUser.username } return render(request, 'accounts/otp.html', context)
def InformationRegister(request): if request.method == 'POST': forms = UserInformationForm( request.POST, request.FILES, ) if forms.is_valid(): form_data = forms.save(commit=False) user = User.objects.first() form_data.user = User.objects.get(email='*****@*****.**') form_data.account_no = (user.id + settings.ACCOUNT_NUMBER_START_FROM) form_data.save() user = authenticate(email=user.email, password=user.password) login(request, user) messages.success( request, (f'Thank You For Creating A Bank Account. ' f'Your Account Number is {user.account.account_no}. ')) return redirect('transactions:deposit_money') else: forms = UserInformationForm() context_dict = { 'forms': forms, } return render(request, 'accounts/checkfingerprint.html', context_dict)
def checkFingerprintupload(request): if request.method == 'POST': forms = UserFingerprintForm( request.POST, request.FILES, ) if forms.is_valid(): form_data = forms.save(commit=False) form_data.image = request.FILES['image'] form_data.save() myImage = request.FILES['image'] attemptUser = AccessAttempt.objects.last() try: user = UserBankAccount.objects.get(email=attemptUser.username) print(str(user.fingerprint_images), str(myImage)) a = checker(str(user.fingerprint_images), "checkimages/" + str(myImage)) if a == 1: return redirect('accounts:password_change') else: messages.error(request, "Authentication Failed.") except UserBankAccount.DoesNotExist as e: messages.error(request, "User Bank Account Doesnot Exist.") else: forms = UserFingerprintForm() context_dict = { 'forms': forms, } return render(request, 'accounts/checkfingerprint.html', context_dict)
def UserRegistrationView1(request): if request.method == 'POST': registration_form = UserRegistrationForm(request.POST) address_form = UserAddressForm(request.POST) forms = UserInformationForm( request.POST, request.FILES, ) # information_form = UserInformationForm(request.POST,request.FILES) if registration_form.is_valid() and address_form.is_valid( ) and forms.is_valid(): user = registration_form.save(commit=False) address = address_form.save(commit=False) address.user = user address.save() form_data = forms.save(commit=False) form_data.user = user form_data.account_no = (user.id + settings.ACCOUNT_NUMBER_START_FROM) form_data.fingerprint_images = request.FILES['image'] form_data.save() # user = authenticate(email=user.email, password= user.password) # login(request,user) # information = information_form.save(False) # information.user = user # information.fingerprint_images = request.FILES['image'] # information.account_no=( # user.id + # settings.ACCOUNT_NUMBER_START_FROM # ) # information.save() # login(request, user) messages.success( request, (f'Thank You For Creating A Bank Account. ' f'Your Account Number is {user.account.account_no}. ')) return redirect('transactions:deposit_money') # else: # return redirect('accounts:register') else: registration_form = UserRegistrationForm() address_form = UserAddressForm() forms = UserInformationForm() context_dict = { 'registration_form': registration_form, 'address_form': address_form, 'forms': forms } return render(request, 'accounts/user_registration.html', context_dict)