Esempio n. 1
0
def update_configurations(clean_data: dict) -> dict:
    """
    {
        'request URL': '/user/update/configurations',
        'methods': 'POST',
        'Query Params': {
            'input': {
                'auth_token': {
                    'nullable': False,
                    'type': 'string'
                },
                'configurations': {
                    'nullable': False,
                    'type': 'json'
                },
            },
        },
        'Response': {
            "code": '',
            "information": {
                'output': {}
            }
        },
        "message": "",
        "status": ""
    }
    """
    repo = UserRepository()
    res, tkns = repo.update(clean_data, 'update_configurations')
    res['auth_token'] = clean_data['auth_token']
    for tkn in tkns:
        redis_client.set(tkn.token, tkn.information)
    ret = dict()
    ret['data'] = res
    ret['code'] = UPDATE_CONFIGURATIONS_CODE
    ret['message'] = UPDATE_CONFIGURATIONS_MESSAGE
    ret['status'] = OK_STATUS
    return ret
Esempio n. 2
0
def recovery_by_answers(clean_data: dict) -> dict:
    """
    {
        'request URL': '/recovery-by/answers',
        'methods': 'POST',
        'Query Params': {
            'input': {
                'user_name': {
                    'nullable': False,
                    'type': 'string'
                },
                'answers': {
                    'nullable': False,
                    'type': 'json'
                },
            },
        },
        'Response': {
            "code": '',
            "information": {
                'output': {
                    'auth_token': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'role': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'real_or_legal': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'phone_number': {
                        'nullable': False,
                        'type': 'numerical string'
                    },
                    'email': {
                        'nullable': True,
                        'type': 'email'
                    },
                    'user_information': {
                        'nullable': True,
                        'type': 'json'
                    },
                    'company_information': {
                        'nullable': True,
                        'type': 'string'
                    },
                    'configurations': {
                        'nullable': True,
                        'type': 'json'
                    },
                }
            }
        },
        "message": "",
        "status": ""
    }
    """
    repo = UserRepository()
    res = repo.page_recovery(clean_data, 'recovery_by_answers')
    rkey, rval, ret = repo.login({
        'user_name': res['user_name'],
        'password': res['temporary_password'],
    })
    redis_client.set(rkey, rval)
    ret['code'] = RECOVERY_BY_ANSWERS_CODE
    ret['message'] = RECOVERY_BY_ANSWERS_MESSAGE
    ret['status'] = OK_STATUS
    return ret
Esempio n. 3
0
def login(clean_data: dict) -> dict:
    """
    {
        'request URL': '/login',
        'methods': 'POST',
        'Query Params': {
            'input': {
                'user_name': {
                    'nullable': False,
                    'type': 'string'
                },
                'password': {
                    'nullable': False,
                    'type': 'string'
                },
                'device_information': {
                    'nullable': False,
                    'type': 'json'
                },
            },
        },
        'Response': {
            "information": {
                'output': {
                    'auth_token': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'role': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'real_or_legal': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'phone_number': {
                        'nullable': False,
                        'type': 'numerical string'
                    },
                    'email': {
                        'nullable': True,
                        'type': 'email'
                    },
                    'user_information': {
                        'nullable': True,
                        'type': 'json'
                    },
                    'company_information': {
                        'nullable': True,
                        'type': 'string'
                    },
                    'configurations': {
                        'nullable': True,
                        'type': 'json'
                    },
                }
            }
        }
    }
    """
    repo = UserRepository()
    rkey, rval, ret = repo.login(clean_data)
    redis_client.set(rkey, rval)
    ret['code'] = LOGIN_CODE
    ret['message'] = LOGIN_MESSAGE
    ret['status'] = OK_STATUS
    return ret
Esempio n. 4
0
def update_password(clean_data: dict) -> dict:
    """
    {
        'request URL': '/user/update/password',
        'methods': 'POST',
        'Query Params': {
            'input': {
                'auth_token': {
                    'nullable': False,
                    'type': 'string'
                },
                'password': {
                    'nullable': False,
                    'max_length': 128,
                    'min_length': 8,
                    'type': 'string'
                },
            },
        },
        'Response': {
            "code": '',
            "information": {
                'output': {
                    'auth_token': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'role': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'real_or_legal': {
                        'nullable': False,
                        'type': 'string'
                    },
                    'phone_number': {
                        'nullable': False,
                        'type': 'numerical string'
                    },
                    'email': {
                        'nullable': True,
                        'type': 'email'
                    },
                    'user_information': {
                        'nullable': True,
                        'type': 'json'
                    },
                    'company_information': {
                        'nullable': True,
                        'type': 'string'
                    },
                    'configurations': {
                        'nullable': True,
                        'type': 'json'
                    },
                }
            }
        },
        "message": "",
        "status": ""
    }
    """
    repo = UserRepository()
    tkns, user_name = repo.update(clean_data, 'update_password')
    for tkn in tkns:
        redis_client.delete(tkn.token)
    rkey, rval, ret = repo.login({
        'user_name':
        user_name,
        'password':
        clean_data['password'],
        'device_information':
        clean_data['auth_token_info_extract']['device_information']
    })
    redis_client.set(rkey, rval)
    ret['code'] = UPDATE_PASSWORD_CODE
    ret['message'] = UPDATE_PASSWORD_MESSAGE
    ret['status'] = OK_STATUS
    return ret
Esempio n. 5
0
 def decorated_function():
     try:
         i_c_data = adata.input(request.form, rule)
         auth_token = i_c_data['auth_token']
         redis_value = redis_client.get(auth_token)
         if redis_value:
             import json
             auth_token_info_extract = json.loads(redis_value)
             i_c_data['user_id'] = auth_token_info_extract['user_id']
             i_c_data[
                 'auth_token_info_extract'] = auth_token_info_extract
             res = func(i_c_data)
             o_c_data = adata.output(res, rule)
             data = {}
             if 'information' in o_c_data:
                 if 'auth_token' in o_c_data['information']:
                     data['token'] = o_c_data['information'][
                         'auth_token']
                     del o_c_data['information']['auth_token']
                 if len(o_c_data['information']) > 0:
                     data['user'] = o_c_data['information']
                 if 'users' in o_c_data['information']:
                     del data['user']
                     data = o_c_data['information']['users']
             return make_response(
                 jsonify({
                     'succsess': True,
                     'message': o_c_data['message'],
                     'data': data,
                 }),
                 200,
             )
         else:
             auth_token = db.session.query(Token).filter(
                 Token.token == auth_token).first()
             if auth_token is not None:
                 redis_client.set(auth_token.token,
                                  auth_token.information)
                 import json
                 auth_token_info_extract = json.loads(
                     auth_token.information)
                 i_c_data['user_id'] = auth_token_info_extract[
                     'user_id']
                 i_c_data[
                     'auth_token_info_extract'] = auth_token_info_extract
                 res = func(i_c_data)
                 o_c_data = adata.output(res, rule)
                 data = {}
                 if 'information' in o_c_data:
                     if 'auth_token' in o_c_data['information']:
                         data['token'] = o_c_data['information'][
                             'auth_token']
                         del o_c_data['information']['auth_token']
                     if len(o_c_data['information']) > 0:
                         data['user'] = o_c_data['information']
                 return make_response(
                     jsonify({
                         'succsess': True,
                         'message': o_c_data['message'],
                         'data': data,
                     }),
                     200,
                 )
             else:
                 raise Exception(TOKEN_NOT_DEFINE_MESSAGE)
     except Exception as ex:
         return make_response(
             jsonify({
                 'succsess': False,
                 'message': ex.args,
                 'data': '',
             }), 200)