def clean(self): amount = self.cleaned_data.get("amount") installment = self.cleaned_data.get("installment") user = self.request.user if not amount or not installment: return self.cleaned_data new_loan = Loan() new_loan.amount = int(amount) new_loan.installment = int(installment) new_loan.start_date = date.today() new_loan.finish_date = date.today() + timedelta(weeks=4 * int(installment)) new_loan.interest_rate = 0.2 loan_account = Accounts() loan_account.iban = generate_iban() loan_account.account_type = "Loan Account" loan_account.amount = int(amount) loan_account.created_at = date.today() loan_account.currency_type = Currency.objects.first() loan_account.user = user loan_account.save() new_loan.account = loan_account new_loan.save() for i in range(1, int(installment) + 1): monthlypayment = LoanAccountPayment() monthlypayment.account = loan_account monthlypayment.finish_date = date.today() + timedelta(weeks=(4 * i)) monthlypayment.installment_number = i monthlypayment.is_paid = False monthlypayment.is_active = True monthlypayment.loan = new_loan monthlypayment.amount = 1.2 * (int(amount) / int(installment)) monthlypayment.save() return self.cleaned_data
def signup_view(request): if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() newAccount = Accounts(accountName = request.POST['username'], userInstance = user) #This creates the Account model, has extended fields to the User model newAccount.save() login(request, user) return redirect('accounts:accountEdit',request.POST['username'] ) else: form = UserCreationForm() return render(request, 'accounts/signup.html', { 'form': form })
def post(self, request, *args, **kwargs): data = { 'username': request.data.get('username'), 'password': request.data.get('password'), } username = request.data.get('username') password = request.data.get('password') pepper = "184fc7ef21aab40368d0401f85041b6224eb4c09f02f8c7a9627b7bf1d893777" peppass = pepper + password salt = bcrypt.gensalt() newpass = peppass.encode("utf-8") newpassall = bcrypt.hashpw(newpass, salt) p = Accounts(username=username, password=newpassall, salt=salt) p.save() return Response({ "username": username, "password": newpass, "salt": salt, "newpassall": newpassall })
def save(self): account = Accounts(email=self.validated_data['email'], username=self.validated_data['username']) password = self.validated_data['password'] password2 = self.validated_data['password2'] if password != password2: raise serializers.ValidationError( {'password': '******'}) account.set_password(password) account.save() return account
def sign_up(request): if(request.method=="GET"): return render(request,'signup.html',{}) else: first_name = request.POST['first_name'] last_name = request.POST['last_name'] email_id = request.POST['email_id'] mobile_number = request.POST['mobile_number'] password = request.POST['password'] users = Accounts.objects.filter(email_id=email_id) if len(users)==0: a = Accounts() a.first_name = first_name a.last_name = last_name a.email_id = email_id a.mobile_number = mobile_number a.password = password a.save() else: messages.warning(request, f"Email-id already registered with us") return redirect(home) messages.success(request, f"Successfully Registered as : {email_id}") return redirect(home)
def approve(request): if request.method == 'POST': print(request.POST["app_id"]) v = Connection.objects.get(application_number=request.POST["app_id"]) ph = str(random.randint(9000000000, 9999999999)) p = Plans.objects.filter(plans_name="base plan") for plan in p: plantobeadded = plan c = Costing(flags=False, calls='0', data='0', sms='0') pr = Proofs(proof=v.proofFile) pr.save() prooftobeadded = Proofs.objects.filter(_id=pr.pk).first() print(prooftobeadded) sAccount = Accounts(account_type=v.connectiontype, phone_number=ph, main_balance=0, expiry="2029-05-20", amount_due="0", payment_deadline="2029-05-20", circle=v.circle, imei="998988989898989", current_usage=c) sAccount.save() sAccount.plan_activated.add(plantobeadded) sAccount.proofs_attached.add(prooftobeadded) sAccount.save() send_mail( 'Thank you for your choosing Voizfonica', 'Hi ' + v.first_name + ', \n\nYour connection request has been approved. Your assigned phone number is \'' + ph + '\'. You can signup with this phone number and get started with voizfonica. Thank you for being a part of Voizfinica family.', '*****@*****.**', [v.email], fail_silently=True, ) return HttpResponse("success")
def setUpTestData(cls): cls.acc_host_001 = Accounts.objects.create( is_superuser=False, username='******', email='*****@*****.**', is_active=True, is_staff=False, date_joined='2021-04-13 14:37:50.965870+00:00', is_host=True) cls.acc_host_001.set_password("123123123") cls.acc_host_001.save() cls.acc_cus_001 = Accounts( is_superuser=False, username='******', email='*****@*****.**', is_active=True, is_staff=False, date_joined='2021-04-13 14:37:50.965870+00:00', is_host=False) cls.acc_cus_001.set_password('123123123') cls.acc_cus_001.save() cls.acc_host_002 = Accounts( is_superuser=False, username='******', email='*****@*****.**', is_active=True, is_staff=False, date_joined='2021-04-13 14:37:50.965870+00:00', is_host=True) cls.acc_host_002.set_password('123123123') cls.acc_host_002.save() cls.acc_host_003 = Accounts.objects.create( is_superuser=False, username='******', email='*****@*****.**', is_active=True, is_staff=False, date_joined='2021-04-13 14:37:50.965870+00:00', is_host=True) cls.acc_host_003.set_password('123123123') cls.acc_host_003.save() cls.cus_001 = Customer.objects.get(account=cls.acc_cus_001) cls.cus_001.first_name = "first" cls.cus_001.last_name = "last" cls.cus_001.gender = "Male" cls.cus_001.address = "address" cls.cus_001.mobile = "0812345678" cls.cus_001.dob = "2021-04-13" cls.cus_001.customer_bio = "customer_bio" cls.cus_001.customer_dog_count = 0 cls.cus_001.customer_hosted_count = 4 cls.host_001 = Host.objects.get(account=cls.acc_host_001) cls.host_001.first_name = "first" cls.host_001.last_name = "last" cls.host_001.gender = "Female" cls.host_001.host_bio = "host_bio" cls.host_001.host_rating = 4.5 cls.host_001.host_hosted_count = 10 cls.host_001.host_area = 100 cls.host_001.address = "address" cls.host_001.mobile = "0812345678" cls.host_001.dob = "2021-04-13" cls.host_001.latitude = 10 cls.host_001.longitude = 10 cls.dog_001 = Dog.objects.create(gender='Male', customer=cls.cus_001, dog_name='dog_name', dog_bio='dog_bio', dog_status='dog_status', dog_create_date='2021-04-13', dog_dob='2021-04-13', dog_breed='dog_breed', dog_weight=251.32) cls.ava_date_001 = HostAvailableDate.objects.create(date='2021-04-20', host=cls.host_001)