Esempio n. 1
0
def get_token():
    """Get user token.

    .. note::
        The body need to be json type.

    :url: http://3.9.215.67:9999/api/v1/token
    :method: POST
    :param account: email.
    :type account: str
    :param password: at least 6 digits.
    :type password: str
    :return: token, expiration, scope
    :example: `{
        "Authorization": "Bearer",
        "Expire_in": "12 Jun 2020 21:35:23 Localtime",
        "Scope": "UserScope",
        "Token": "eyJlA..."}`
    """
    form = ClientForm(data=request.json)
    form.validate_for_api()
    switch = {
        ClientTypeEnum.Email: User.verify,
    }
    identity = switch[form.type.data](form.account.data, form.password.data)
    expiration = 30 * 24 * 3600
    token, expires_in = generate_auth_token(identity['uid'],
                                            form.type.data.name,
                                            identity['scope'], expiration)
    t = combine_token_info(token, expires_in, scope=identity['scope'])
    return jsonify(t), 201
Esempio n. 2
0
def create_client():
    """Register user.

    .. note::
        The body need to be json type.

    :url: http://3.9.215.67:9999/api/v1/register
    :method: POST
    :param account: email.
    :type account: str
    :param password: at least 6 digits.
    :type password: str
    :return: result
    :example: `{
            "account": "*****@*****.**",
            "password":"******"}`
    """
    form = ClientForm(data=request.json)
    form.validate_for_api()
    switch = {
        ClientTypeEnum.Email: _register_user_by_email,
    }
    switch[form.type.data]()
    return Success()