Revision ddc6960a snf-astakos-app/astakos/api/util.py

b/snf-astakos-app/astakos/api/util.py
89 89
    return all(map(is_integer, lst))
90 90

  
91 91

  
92
def validate_user(user):
93
    # Check if the user is active.
94
    if not user.is_active:
95
        raise faults.Unauthorized('User inactive')
96

  
97
    # Check if the token has expired.
98
    if user.token_expired():
99
        raise faults.Unauthorized('Authentication expired')
100

  
101
    # Check if the user has accepted the terms.
102
    if not user.signed_terms:
103
        raise faults.Unauthorized('Pending approval terms')
104

  
105

  
92 106
def user_from_token(func):
93 107
    @wraps(func)
94 108
    def wrapper(request, *args, **kwargs):
......
105 119
        except AstakosUser.DoesNotExist:
106 120
            raise faults.Unauthorized('Invalid X-Auth-Token')
107 121

  
108
        # Check if the user is active.
109
        if not user.is_active:
110
            raise faults.Unauthorized('User inactive')
111

  
112
        # Check if the token has expired.
113
        if user.token_expired():
114
            raise faults.Unauthorized('Authentication expired')
115

  
116
        # Check if the user has accepted the terms.
117
        if not user.signed_terms:
118
            raise faults.Unauthorized('Pending approval terms')
122
        validate_user(user)
119 123

  
120 124
        request.user = user
121 125
        return func(request, *args, **kwargs)

Also available in: Unified diff