def put(self): parser = reqparse.RequestParser() parser.add_argument('password', help='This field cannot be blank', required=True) parser.add_argument("newpassword", help='This argument cannot be blank', required=True) username = get_jwt_identity() current_user = UserModel.find_by_username(username) data = parser.parse_args() if UserModel.verify_hash(data['password'], current_user.password): current_user.password = UserModel.generate_hash( data['newpassword']) current_user.add_commit_data() return {'message': 'Your password was updated successfully!'} else: return {"message": 'Wrong password'}
def post(self): parser = reqparse.RequestParser() parser.add_argument('username', help='This field cannot be blank', required=True) parser.add_argument('password', help='This field cannot be blank', required=True) parser.add_argument('email') data = parser.parse_args() if UserModel.find_by_username(data['username']): return { 'message': 'User {} already exists'.format(data['username']) } if UserModel.find_by_email(data['email']): return { 'message': 'An user with email "{}" already exists'.format(data['email']) } new_user = UserModel(username=data['username'], password=UserModel.generate_hash( data['password']), email=data['email']) try: new_user.save_to_db() #access_token = create_access_token(identity = data['username']) #refresh_token = create_refresh_token(identity = data['username']) mailTo(username=data['username'], email=data['email'], template="userconfirmation.html") return { 'message': 'User {} was created, please check your email for varification' .format(data['username']), #'access_token': access_token, #'refresh_token': refresh_token, } except: return {'message': 'Something went wrong'}, 500