예제 #1
0
    def loginValidate(params):
        try:
            if 'password' not in params:
                username = params['username']
                if not Dbase.usernameExists(username):
                    response = make_response(json.dumps('InValid Username'),
                                             400)
                    response.headers['Content-Type'] = 'application/json'
                    return response
                response = make_response(json.dumps('Valid Username'), 200)
                response.headers['Content-Type'] = 'application/json'
                return response
            else:
                username = params['username']
                password = params['password']
                if not Dbase.verifyLoginPassword(username, password):
                    response = make_response(json.dumps('Invalid Credentials'),
                                             400)
                    response.headers['Content-Type'] = 'application/json'
                    return response

#login successful
                ssn = Dbase.getSecurityNumber(username)
                customername = Dbase.getCustomerName(ssn)
                login_session['ssn'] = ssn
                login_session['customername'] = customername
                login_session['username'] = username
                response = make_response(json.dumps('Valid Credentials'), 200)
                response.headers['Content-Type'] = 'application/json'
                return response
        except Exception as e:
            raise e
예제 #2
0
    def validate(params):
        try:
            if params['registerno'] == '1':
                verification_type = params['verificationtype']
                securitynumber = params['securitynumber']
                if Dbase.securitynumberExists(securitynumber):
                    response = make_response(
                        json.dumps('You have already registered with us'), 400)
                    response.headers['Content-Type'] = 'application/json'
                    return response

                number = params['number'].strip()
                resp = Validation.accountNumber(number, verification_type)
                if resp != None:
                    return resp
                password = params['password'].strip()
                resp = Validation.password(number, verification_type, password)
                if resp != None:
                    return resp

                resp = Validation.securitynumber(number, verification_type,
                                                 securitynumber)
                if resp != None:
                    return resp
                email = params['email'].strip()
                resp = Validation.email(email)
                if resp != None:
                    return resp
                mobileno = params['mobileno'].strip()
                resp = Validation.mobileno(mobileno)
                if resp != None:
                    return resp

            elif params['registerno'] == '2':
                username = params['username']
                userpassword = params['userpassword']
                resp = Validation.username(username)
                if resp != None:
                    return resp
                resp = Validation.userpassword(userpassword)
                if resp != None:
                    return resp

            elif params['registerno'] == '3':
                answer = params['answer']
                if len(answer) == 0:
                    response = make_response(json.dumps('Give a valid Answer'),
                                             400)
                    response.headers['Content-Type'] = 'application/json'
                    return response

            else:
                print(params['registerno'] == 'confirm')
                Dbase.register(params)
                customername = Dbase.getCustomerName(params['securitynumber'])
                login_session['ssn'] = params['securitynumber']
                login_session['customername'] = customername
                login_session['username'] = params['username']
                response = make_response(json.dumps('Registered'), 200)
                response.headers['Content-Type'] = 'application/json'
                return response
            response = make_response(json.dumps('Registered'), 200)
            response.headers['Content-Type'] = 'application/json'
            return response
        except Exception as e:
            raise e