Exemplo n.º 1
0
def token_verify_handler(token):
    """
    Takes a token and indicates if it is valid.  This view provides no
    information about a token's fitness for a particular use.
    """
    _user = Ouser.query_user_from_token(token)
    res = dict(user=UserSerializer(_user).data)
    return res
Exemplo n.º 2
0
def token_obtain_pair_handler(username, password):
    """
    Takes a set of user credentials and returns an access and refresh JSON web
    token pair to prove the authentication of those credentials.
    """
    ser = TokenObtainPairSerializer(data={
        get_username_field(): username,
        'password': password
    })
    ser.is_valid(raise_exception=True)
    update_last_login(None, ser.user)
    res = dict(refresh=ser.validated_data.get('refresh'),
               access=ser.validated_data.get('access'),
               user=UserSerializer(ser.user).data)
    return res
Exemplo n.º 3
0
def token_obtain_sliding_login_handler(request, username, password):
    """
    Takes a set of user credentials and returns a sliding JSON web token to
    prove the authentication of those credentials.
    """
    ser = TokenObtainSlidingSerializer(data={
        get_username_field(): username,
        'password': password
    })
    try:
        ser.is_valid(raise_exception=True)
    except:
        raise InvalidUser('用户名/密码输入错误')
    update_last_login(None, ser.user)
    session_user_update(request, ser.user)
    res = dict(token=ser.validated_data.get('token'),
               user=UserSerializer(ser.user).data)
    return res
Exemplo n.º 4
0
def token_user_password_change_handler(**kwrags):
    """用户根据id或者username+邮箱验证修改密码"""
    user_id = kwrags.get('id')
    res = dict(user=UserSerializer(user_id).data)
    # TODO:待开发
    pass