def create_default_objects(): ''' Creates a list of default users and accounts for testing purposes ''' # Create a default Admin user Admin(username="******", password="******", first_name="Jack").save() print("Default Admin Created") cust1 = Customer(username="******", password="******", first_name="John") cust1.save() print("Default Customer Created") Checking_Account(account_number="1", owner=cust1).save() print("Default Checking Account Created") Savings_Account(account_number="2", owner=cust1).save() print("Default Savings Account Created") cust2 = Customer(username="******", password="******", first_name="Clark") cust2.save() print("Default Customer2 Created") Savings_Account(account_number="3", owner=cust2).save() print("Default Savings Account Created") Brokerage_Account(account_number="4", owner=cust1).save() print("Default Brokerage Account Created")
def create_default_objects(): ''' Creates a list of default users and accounts for testing purposes ''' # Create a default Admin user Admin(username="******", password="******", first_name="Jack").save() print("Default Admin Created") cust1 = Customer(username="******", password="******", first_name="John") cust1.save() print("Default Customer Created") Checking_Account(account_number="1", owner=cust1).save() print("Default Checking Account Created") Savings_Account(account_number="2", owner=cust1).save() print("Default Savings Account Created") cust2 = Customer(username="******", password="******", first_name="Clark") cust2.save() print("Default Customer2 Created") Savings_Account(account_number="3", owner=cust2).save() print("Default Savings Account Created") Brokerage_Account(account_number="4", owner=cust1).save() print("Default Brokerage Account Created")
def create_customer(self, username, password, first_name): ''' Creates a new customer object and returns it Takes two strings as parameters ''' if len(password) < 8: raise Exception("Password is too short") user_name_exists = False try: Admin.get(usemodelrname=username) user_name_exists = True except: pass if user_name_exists: raise Exception("Username is already in use") cust = Customer(username=username, password=password, first_name=first_name) cust.save() return cust
def create_customer(self, username, password, first_name): ''' Creates a new customer object and returns it Takes two strings as parameters ''' if len(password) < 8: raise Exception("Password is too short") user_name_exists = False try: Admin.get(usemodelrname=username) user_name_exists = True except: pass if user_name_exists: raise Exception("Username is already in use") cust = Customer(username=username, password=password, first_name=first_name) cust.save() return cust
def post(self): parser = reqparse.RequestParser() parser.add_argument(name="username", type=str, location="json") parser.add_argument(name="password", type=str, location="json") body = parser.parse_args() username = body.username password = body.password print("REGISTER SAVE") if username is None or password is None: return {"meassage": "Thiếu trường"}, 401 found_user = Customer.objects(username=username).first() if found_user is not None: print("User already exist") return redirect('api/login', 307) user = Customer(username=username, password=password) print({"name": user.username + ";password:" + user.password}) user.save() return redirect('api/login', 307)