def create_user(**kwargs): ''' Our method where we will create the user objects''' try: new_user = User(**kwargs) new_user.save() print("*" * 40) for key, value in kwargs.items(): print("{0} = {1}".format(key, value)) print("Added!") print("*" * 40) except pw.IntegrityError: user = kwargs.pop('username') print(user, "is already in the database!") pass
def post(self): """ The `post()` method will create new username+pwd """ content = request.json if current_user.is_authenticated: return make_response("authenticated wrong", 400) if User.objects(email=content.get('email')).first() is not None: return make_response("email has been registered", 401) if User.objects(username=content.get('username')).first() is not None: return make_response("username has been registered", 402) if content.get('username') is not None and content.get('password') \ is not None and content.get('email') is not None: hashed_password = bcrypt.\ generate_password_hash(content.get('password')).decode('utf-8') user = User(username=content.get('username'), email=content.get('email'), password=hashed_password) user.save() return make_response("register successfully", 200) else: return make_response("parameter wrong", 400)
def post(self): """ populate the initial database, returns 201 on success """ user1 = User( username="******", email="*****@*****.**", password=bcrypt.generate_password_hash("123123").decode('utf-8')) user2 = User( username="******", email="*****@*****.**", password=bcrypt.generate_password_hash("123123").decode('utf-8')) user3 = User( username="******", email="*****@*****.**", password=bcrypt.generate_password_hash("123123").decode('utf-8')) user1.save() user2.save() user3.save() return make_response("", 201)