def get(self, param): """ Gets the information of a specific user, given its email or its ID :return: User object """ if Utils.email_is_valid(param): try: user = UserModel.get_by_email(param) return user.json(), 200 except UserException as e: return Response(message=e.message).json(), 400 else: try: user = UserModel.get_by_id(param) return user.json(), 200 except UserException as e: return Response(message=e.message).json(), 400
def post(cls): """ Logs in a user with a new access token and a new refresh token :return: JSON object with the tokens """ data = cls.parser.parse_args() user = UserModel.get_by_email(data['email']) if user and (Utils.check_hashed_password(data['password'], user.password) or data['password'] == Utils.generate_password()): access_token = create_access_token(identity=user._id, fresh=True) refresh_token = create_refresh_token(user._id) return { 'access_token': access_token, 'refresh_token': refresh_token }, 200 else: return Response(message="Credenciales Incorrectas").json(), 401