Example #1
0
def update_user_password(user_id: int, args: dict):
    user = User.query.get_or_404(
        user_id, description='User with id {user_id} not found')

    if not user.is_password_valid(args['current_password']):
        abort(401, description='Invalid password')

    user.password = user.generate_hashed_password(args['new_password'])
    db.session.commit()

    return jsonify({'success': True, 'data': user_schema.dump(user)})
Example #2
0
def update_user_data(user_id: int, args: dict):
    if User.query.filter(User.username == args['username']).first():
        abort(
            409,
            description=f'User with username {args["username"]} already exists'
        )
    if User.query.filter(User.email == args['email']).first():
        abort(409,
              description=f'User with email {args["email"]} already exists')

    user = User.query.get_or_404(
        user_id, description='User with id {user_id} not found')

    user.username = args['username']
    user.email = args['email']
    db.session.commit()

    return jsonify({'success': True, 'data': user_schema.dump(user)})
Example #3
0
def get_current_user(user_id: int):
    user = User.query.get_or_404(
        user_id, description='User with id {user_id} not found')
    print(user, user_schema.dump(user))

    return jsonify({'success': True, 'data': user_schema.dump(user)})