Ejemplo n.º 1
0
 def post():
     """
     Post method for user login .
     :return: Success code 1 on successful login  .
     """
     # get data from json.
     input_data = UserLogin.login_parser.parse_args()
     # corresponding user exist in database
     user = UserModel.find_user(input_data['email_id'])
     if user is not None:
         # print('user found progressing for password check')
         # we need to check for the password .
         if user.check_password(
                 user.password,
                 UserModel.set_password(input_data['password'])):
             # Mark user as a logged in .
             user.user_logged_in(True)
             # return success .
             return {
                 'user': user.json(),
                 'Login': '******',
                 'Success_Code': 1
             }, 200
         else:
             return {
                 'Login': '******',
                 'Success_Code': 0
             }, 404
     else:
         return {
             'Login': '******',
             'Success_Code': 0
         }, 404
Ejemplo n.º 2
0
 def post(cls):
     """
     Post method .
     :return: Success_Code : 1 when password updated successfully.
     """
     # input data.
     input_data = UpdateUser.update_user_parser.parse_args()
     # get user with email id .
     user = UserModel.find_user(input_data['email_id'])
     # update user password
     user.password = UserModel.set_password(input_data['new_password'])
     # save it in data base.
     user.save_data()
     return {'message': 'User password updated', 'Success_Code': 1}, 200
Ejemplo n.º 3
0
 def post(cls):
     """
     post method .
     :return: 'Success_Code': 1 if log out successful .
     """
     # input data.
     input_data = Logout.logout_user_parser.parse_args()
     # get user with email id .
     user = UserModel.find_user(input_data['email_id'])
     # if user is not none .
     if user is not None:
         # check user is logged in or not .
         if user.logged_in:
             user.logged_in = False
             user.save_data()
             return {
                 'message': 'User Logged out . ',
                 'Success_Code': 1
             }, 200
         else:
             return {
                 'message': 'User is already Logged out . ',
                 'Success_Code': 1
             }, 400
     else:
         return {
             'message': 'User not Logged out . ',
             'Success_Code': 0
         }, 404
Ejemplo n.º 4
0
 def post(cls):
     """
     Post method
     Example : { "leader_board_name" : "BigMan"}
     """
     # input data.
     input_data = LeaderBoard.leader_board_user_parser.parse_args()
     # return list of  users
     return UserModel.get_leader_board(input_data['leader_board_name'])
Ejemplo n.º 5
0
 def post():
     """
     Post Method for user registration.
     :return: Success code 1 on successful registration .
     """
     # get data from json.
     input_data = UserRegister.register_parser.parse_args()
     # corresponding user exist in database
     if UserModel.find_user(input_data['email_id']) is None:
         # create user.
         user = UserModel(
             input_data['username'],
             input_data['email_id'],
             input_data['password'],
             int(input_data['us_dollar']),
             input_data['device_id'],
         )
         # save user.
         user.save_data()
         return {
             'message': 'user created ',
             'user_details': user.json(),
             'Success_Code': 1
         }, 201
     else:
         return {
             'message': 'user already present with the email id',
             'Success_Code': 0
         }, 400
Ejemplo n.º 6
0
 def post(cls):
     """
     make a post with uuid  and updated money .
     it will update the us_dollar value in the database .
     :return: update user .
     Example: post contain json {'uuid':'420','us_dollar':'1000000000000'}
     """
     # input data.
     input_data = UpdateUserMoney.update_user_money.parse_args()
     # email id .
     user = UserModel.find_user(input_data['user_id'])
     # if user found.
     if user is not None:
         user.us_dollar = input_data['us_dollar']
         user.save_data()
         return {'message': user.json(), 'Success_Code': 1}, 200
     return {'message': 'No user found with this email id ', 'Success_Code': 0}, 404
Ejemplo n.º 7
0
 def post(cls):
     """
     Post method.
     :return: Success code 1 when user is found .
     """
     # get data from json.
     input_data = FindUser.Find_user_parser.parse_args()
     # corresponding user exist in database
     user = UserModel.find_user(input_data['email_id'])
     # if user null return error .
     if user is None:
         return {
             'message': 'No user found with this email id',
             'Success_Code': 0
         }, 404
     else:
         return {'message': 'User found', 'Success_Code': 1}, 200
Ejemplo n.º 8
0
 def post(cls):
     """
     make a post with uuid  and updated school id .
     it will update the school id value in the database .
     :return: update user .
     Example: post contain json {'uuid':'420','new_school_id':'999'}
     """
     # input data.
     input_data = UpdateUserSchoolId.update_user_school_id.parse_args()
     # email id .
     user = UserModel.find_user(input_data['user_id'])
     # if user found.
     if user is not None:
         old_school_id = user.school_id
         user.school_id = input_data['new_school_id']
         user.save_data()
         return {'message': user.json(), 'Success_Code': 1}, 200
     return {'message': 'No user found with this email id ', 'Success_Code': 0}, 404
Ejemplo n.º 9
0
 def post():
     """
     Post Method for user registration.
     :return: Success code 1 on successful registration .
     """
     # get data from json.
     input_data = UserRegister.register_parser.parse_args( )
     # corresponding user exist in database
     if UserModel.find_user(input_data['user_id']) is None:
         # create user.
         user = UserModel(user_unique_identifier=input_data['user_id'], school_id=input_data['school_id'],
                          us_dollar=input_data['us_dollar'])
         # save user.
         user.save_data()
         return {'message': 'user created ', 'user_details': user.json(), 'Success_Code': 1}, 201
     else:
         return {'message': 'user already present with the user id', 'Success_Code': 0}, 400
Ejemplo n.º 10
0
 def get(cls):
     """
     Get Method .
     :return: Users List those who are currently logged in .
     """
     return UserModel.find_users_logged_in()
Ejemplo n.º 11
0
 def get(cls):
     """
     Get Method
     :return: School with highest score .
     """
     return UserModel.school_leader_board()
Ejemplo n.º 12
0
 def get(cls):
     """
     Post method
     """
     # return list of  users
     return UserModel.user_leader_board()