Ejemplo n.º 1
0
def set_password_token(user_id, token, new_password):
    """
    Sets new password provided reset-password token is correct.

    @clmview_guest
    @param_post{user_id} id of the User whose password should be set
    @param_post{token} token to set password
    @param_post{new_password,string} new password

    @response{dict} User's new data (if succeeded)
    """
    try:
        user = User.objects.get(id=user_id)
    except Exception:
        raise CLMException('user_get')

    if token_generator.check_token(user, int_to_base36(user_id) + u'-' + token):
        user.password = new_password
        try:
            user.save()
        except Exception:
            raise CLMException('user_set_password')
    else:
        raise CLMException('user_bad_token')
    return user.dict
Ejemplo n.º 2
0
def check_token(user_id, token):
    """
    @clmview_guest
    @parameter{user_id} user for whom token should be checked
    @parameter{token} token to check

    @response None
    """
    try:
        user = User.objects.get(id=user_id)
    except Exception:
        raise CLMException('user_get')

    if token_generator.check_token(user, int_to_base36(user_id) + u'-' + token):
        return
    raise CLMException('user_bad_token')
Ejemplo n.º 3
0
def check_token(user_id, token):
    """
    Check password-reset token correctness for User.

    @clmview_guest
    @param_post{user_id} User whose token should be checked
    @param_post{token} token to check

    @response None
    """
    try:
        user = User.objects.get(id=user_id)
    except Exception:
        raise CLMException('user_get')

    if token_generator.check_token(user, int_to_base36(user_id) + u'-' + token):
        return
    raise CLMException('user_bad_token')