def modify_user():
     payload = request.get_json()['query_data']
     username = payload['username']
     new_password = payload['new_password']
     returned = UserController.password_change(
         username=username,
         old_password=new_password,
         new_password=new_password,
         by_admin=True
     )
     if returned == PASSWORD_CHANGE_SUCCESS:
         return jsonify(
             code='success',
             msg='User information changed successfully'
         )
     elif returned == PASSWORD_CHANGE_VALIDATION_FAILED:
         print(username, new_password)
         return jsonify(
             code='failed',
             msg='Provided information is invalid!'
         )
     elif returned == PASSWORD_CHANGE_PRIVILEGE_FAILED:
         return jsonify(
             code='failed',
             msg='Your privilege is invalid for this action!'
         )
Ejemplo n.º 2
0
 def register():
     user = request.get_json()['query_data']
     returned = UserController.register(mail_man, user, False)
     if returned == REGISTER_SUCCESS:
         return jsonify(code='success', msg='Registered successfully')
     elif returned == REGISTER_DUPLICATED_USERNAME_OR_EMAIL:
         return jsonify(code='failed', msg='username or email is duplicated')
     elif returned == REGISTER_VALIDATION_FAILED:
         return jsonify(code='failed', msg='Format validation failed')
Ejemplo n.º 3
0
 def change_password():
     user = request.get_json()['query_data']
     username = get_jwt_identity()['username']
     returned = UserController.password_change(
         username=username,
         old_password=user['password'],
         new_password=user['new_password'],
         by_admin=False
     )
     if returned == PASSWORD_CHANGE_SUCCESS:
         return jsonify(code='success', msg='Password changed successfully')
     elif returned == PASSWORD_CHANGE_FAILED:
         return jsonify(code='failed', msg='Old password is incorrect')
     elif returned == PASSWORD_CHANGE_LAST_FIVE_PASSWORDS:
         return jsonify(code='failed', msg='Duplicated with last 5 password')
     elif returned == PASSWORD_CHANGE_VALIDATION_FAILED:
         return jsonify(code='failed', msg='Provided information is invalid!')
Ejemplo n.º 4
0
 def login():
     user = request.get_json()['query_data']
     payload = UserController.login(user)
     if payload and payload['token']:
         return jsonify(code='success', msg='Logged in successfully', token=payload['token'])
     return jsonify(code='failed', msg='username or password is incorrect', signal=payload['signal'])
Ejemplo n.º 5
0
 def logout():
     payload = get_jwt_identity()
     action_id = payload['action_id']
     UserController.logout(action_id)
     return jsonify(code='success', msg='Logged out success')
Ejemplo n.º 6
0
 def list_all():
     return jsonify(UserController.list_all())
Ejemplo n.º 7
0
 def list_users():
     return jsonify(
         code='success',
         msg='Got all users information successfully',
         data=UserController.list_all()
     )
Ejemplo n.º 8
0
 def reset():
     user = request.get_json()['query_data']
     UserController.password_reset(mail_man, user['username'], user['email'])
     return jsonify(msg='success')
Ejemplo n.º 9
0
def test_reset(client):
    token = UserController.password_reset(mail_man, 'kuribohkute',
                                          '*****@*****.**')
    assert len(token) > 0
    response = client.get("/confirm/password_reset/{}".format(token))
    assert response.status_code == 200