예제 #1
0
    def check_auth(self, headers):
        api_key = headers.get('X-Authorisation')

        if api_key:
            try:
                payload = jwt.decode(api_key,
                                     current_app.config['SECRET_KEY'],
                                     algorithms=['HS256'])
            except jwt.DecodeError:
                return False
            return login_user(User(payload))

        return login_user(Guest())
예제 #2
0
def load_user(userid):
    usr = UserData()
    if not userid:
        raise TypeError("Please provide your user id.")
    try:
        role = usr.findById(int(userid))[2]
    except Exception as e:
        raise TypeError("Wrong username/password, please try again.")
    # initialise the class by the role
    if role == 'admin':
        return Admin(userid)
    elif role == 'student':
        return Student(userid)
    elif role in ["guest", "unguest"]:
        return Guest(userid)
    elif role == 'staff':
        return Staff(userid)
 def test_guest_initial_params_set(self):
     guest = Guest()
     self.assertEqual(guest.get_id(), 'guest')
     self.assertEqual(guest.groups, ['world'])