def doSignup():
    id = randomString(16)
    usr = request.form.get("usr")
    pwd = request.form.get("pwd") + '#$%^&*$@' + usr
    eml = request.form.get("eml")
    pwd = md5(pwd.encode())
    acc = Account()
    ret = acc.add((id, usr, pwd.digest(), eml))
    if ret > 0:
        return redirect("/authen/signin")
    return render_template("authen/signup.html", err="Username Existed")
Exemple #2
0
def doSignup():
    id = randomStr(16)
    usr = request.form.get('usr')
    pwd = request.form.get('pwd') + '!@$*&#' + usr  #tranh crack pw
    eml = request.form.get('eml')
    pwd = md5(pwd.encode())
    acc = Account()
    ret = acc.add((id, usr, pwd.digest(), eml))
    if ret > 0:
        return redirect('/auth/signin')
    return render_template('auth/signup.html', err='Username exists')
    def post(self):
        requestDict = request.get_json()
        if not requestDict:
            response = {'error': 'No input data provided'}
            return response, status.HTTP_400_BAD_REQUEST
        curdatetime = datetime.now() - timedelta(hours=5)
        try:
            accountType = 1  #Cuenta Simple por defecto
            if 'accountType' in requestDict:
                accountType = int(requestDict['accountType'])
            idPerson = requestDict['idPerson']
            origin = requestDict['origin']
            prospectiveClient = ProspectiveClient.query.filter_by(
                idPerson=idPerson).first()
            client = Client.query.filter_by(
                idProspectiveClient=prospectiveClient.id).first()
            if not client:  #Apertura de cuentas no cliente
                client = Client(registerDate=curdatetime,
                                totalAccounts=1,
                                activeLoans=0,
                                active=1,
                                idProspectiveClient=prospectiveClient.id)
                client.add(client)
            else:
                client.totalAccounts += 1
                client.update()
            db.session.flush()
            orig = ""
            if origin == 1:
                orig = "Web"
            else:
                orig = "Ventanilla"
            salesRecord = SalesRecord(origin=orig,
                                      active=1,
                                      requestDate=curdatetime,
                                      idClient=client.id,
                                      idRecordStatus=1,
                                      idProduct=1)
            salesRecord.add(salesRecord)
            db.session.flush()
            currency = requestDict['currency']
            account = Account(accountNumber=GenerateAccount(),
                              balance=0.0,
                              openingDate=curdatetime,
                              closingDate=None,
                              cardNumber="1234-5678-1234-5678",
                              idAccountType=accountType,
                              idSalesRecord=salesRecord.id,
                              idCurrency=currency,
                              idClient=client.id,
                              active=1)
            account.add(account)
            db.session.flush()
            response1 = requestDict['response1']
            response2 = requestDict['response2']
            response3 = requestDict['response3']
            response4 = requestDict['response4']
            additionalQuestion = AdditionalQuestion(response1=response1,
                                                    response2=response2,
                                                    response3=response3,
                                                    response4=response4,
                                                    idAccount=account.id)
            additionalQuestion.add(additionalQuestion)

            #Commit changes
            db.session.commit()

            regClient = Client.query.get(client.id)
            regAccount = Account.query.get(account.id)
            regAccountType = AccountType.query.get(accountType)
            person = Person.query.get(prospectiveClient.idPerson)
            d = {}
            d['name'] = " ".join([
                person.firstName, person.middleName, person.fatherLastname,
                person.motherLastname
            ])
            d['accountNumber'] = regAccount.accountNumber
            d['cci'] = "0011-" + regAccount.accountNumber
            d['accountDetail'] = regAccountType.typeName
            d['openingDate'] = regAccount.openingDate.strftime('%d-%m-%Y')
            d['currency'] = ('Soles'
                             if regAccount.idCurrency == 1 else 'Dolares')
            d['email'] = prospectiveClient.email1

            from mailing import mail
            msg = Message("Tunke - Apertura de cuenta exitosa",
                          sender="*****@*****.**",
                          recipients=[d['email']])
            msg.body = 'Hola'
            msg.html = render_template('ejemplo.html',
                                       name=d['name'],
                                       accountNumber=d['accountNumber'],
                                       cci=d['cci'],
                                       accountDetail=d['accountDetail'],
                                       openingDate=d['openingDate'],
                                       currency=d['currency'])
            mail.send(msg)
            return d, status.HTTP_201_CREATED

        except SQLAlchemyError as e:
            db.session.rollback()
            response = {'error': str(e)}
            return response, status.HTTP_400_BAD_REQUEST
        except Exception as e:
            db.session.rollback()
            response = {
                'error':
                'An error ocurred. Contact cat-support asap. ' + str(e)
            }
            return response, status.HTTP_400_BAD_REQUEST