Beispiel #1
0
    def identify(self, request):
        auth_header = request.headers.get('Authorization')
        if not auth_header:
            return return_fail_http_json_result('', 'No token information')

        auth_token_info = auth_header.split(" ")
        if (not auth_token_info or auth_token_info[0] != 'JWT'
                or len(auth_token_info) != 2):
            return return_fail_http_json_result(
                '', 'Authorization information incorrect')

        auth_token = auth_token_info[1]
        result, payload = self.decode_auth_token(auth_token)
        if not result:
            return return_fail_http_json_result('', payload)

        user = User.get(User, payload['data']['id'])
        if not user:
            return return_fail_http_json_result('', 'User not found')

        if (user.login_time != payload['data']['login_time']):
            return return_fail_http_json_result(
                '', 'Token has changed, Please login again')

        return return_success_http_json_result(user.id, 'Request success')
Beispiel #2
0
    def get_user(self):
        if self.db_user:
            return self.db_user
        
        # Try to fetch a User via cookie
        self.db_user = User.get( read_user_cookie( self ) )

        return self.db_user
Beispiel #3
0
 def get(self):
     result = Auth.identify(Auth, request)
     if (result['status'] and result['data']):
         user = User.get(User, result['data'])
         returnUser = {
             'id': user.id,
             'name': user.username,
             'email': user.email
         }
         result = return_success_http_json_result(returnUser, "Request success")
     return jsonify(result)
Beispiel #4
0
def load_user(id):
    return User.get(id)
Beispiel #5
0
    def post( self ):
        # Given a User uuid, create a Checkin obj. 
        user = User.get( self.request.get('user_uuid') )
        meal = Meal.get_current()

        Checkin.create( meal, user )
Beispiel #6
0
def getUserNamebyId(id):
    if id:
        return User.get(id)
    return '没人'