def user_logout():
    """
        logout
    :return: respond model
    """
    respond_model = RespondModel()
    respond_model.message = 'success'
    respond_model.token = ''
    respond_model.code = 20000
    return respond_model.dump_json(), 200
Example #2
0
def sign_up():
    """
        user sign up
    :return:
    """
    request_model = RequestModel(request)
    respond_model = RespondModel()
    respond_model.data = user_service.user_sign_up(request_model.data.get('user_info'))
    respond_model.code = 20000
    return respond_model.dump_json()
Example #3
0
def check_enable_sign_up():
    """
        check if the server enable user sign up
    : return: respond model with boolean
    """
    enable_sign_up = get_config(APP_CONFIG)['ENABLE_SIGN_UP']
    respond_model = RespondModel()
    respond_model.data = {"enable_sign_up": enable_sign_up}
    respond_model.message = 'success'
    respond_model.code = 20000
    return respond_model.dump_json(), 200
    def fun_dec(*args, **kwargs):
        request_model = RequestModel(request)
        if validate_master(request_model.data.get("token")):
            respond_model = api_function(*args, **kwargs)
            respond_model.code = 20000
            respond_model.message = 'success'
            return respond_model.dump_json(), 200

        else:
            respond_model = RespondModel()
            respond_model.message = 'authorization error'
            respond_model.code = 50012
            return respond_model.dump_json(), 403
def login():
    """
        user login
    :return: respond model with jwt token in headers
    """
    request_model = RequestModel(request)
    user_info_db = user_service.login(request_model.data.get('user_info'))
    respond_model = RespondModel()
    if user_info_db is not None:
        respond_model.token = generate_jwt(user_info_db)
        respond_model.message = 'login success'
        respond_model.code = 20000
    else:
        respond_model.message = 'username or password wrong!'
    return respond_model.dump_json()
Example #6
0
 def fun_dec(*args, **kwargs):
     request_model = RequestModel(request)
     if request_model.token and verify_jwt(request_model.token):
         respond_model = api_function(*args, **kwargs)
         if not respond_model.token:
             respond_model.token = renew_jwt(request_model.token)
         if respond_model.message == 'authorization error':
             respond_model.code = 50012
             return respond_model.dump_json(), 403
         respond_model.code = 20000
         respond_model.message = 'success'
         return respond_model.dump_json(), 200
     else:
         respond_model = RespondModel()
         respond_model.message = 'authentication error, please login'
         respond_model.code = 50012
         return respond_model.dump_json(), 401