def create_db(): db.create_all() password = bcrypt.generate_password_hash("jalal").decode('utf-8') user = UserModel("jalal", "jalal@", password, 3, True) db_user = UserModel.find_by_username(user.username) if db_user: db_user.activated = user.activated db_user.role = user.role db_user.save_to_db() else: user.save_to_db()
def post(self): data = create_request_parser(auth_list).parse_args() user = UserModel.find_by_username(data['username']) if not user or not bcrypt.check_password_hash(user.password, data['password']): return {"message": "invalid username or passwrod."}, 401 if not user.activated: return { 'message': 'not allowed to login please contact admin.' }, 405 return { "message": "Login Success.", "token": create_user_token(user.id), "user": user.json() }
def post(self): data = create_request_parser([*auth_list, _name_arg]).parse_args() password_required_lenght = 5 if len(data['password']) < password_required_lenght: return { "message": f"password must have at least\ {password_required_lenght} characters" }, 400 if UserModel.find_by_username(data['username']): return {"message": "username already exists"}, 400 user = UserModel(**data) user.password = bcrypt.generate_password_hash( user.password).decode('utf-8') try: user.save_to_db() except Exception as e: return get_internal_server_error() return { "message": "Registration success you must contact admin to activate your account." }, 405