def login(username, password): verify_to_schema(UserLoginSchema, { "username": username, "password": password }) user = api.user.get_user(username_lower=username.lower()) if user is None: raise WebException("No user with that username exists!") if user.get("disabled", False): raise WebException("This account is disabled.") if confirm_password(password, user["password"]): if user["uid"] is not None: session["uid"] = user["uid"] if user["type"] == 0: session["admin"] = True session.permanent = True else: raise WebException("Login error. Error code: 1.") else: raise WebException("Wrong password.")
def test_032_get_non_existing(self): global cherrypy cherrypy.session = {'roles': ['admin', 'planner', 'driver']} response = user.get('nonexisting') self.assertEqual(response.content, '"Could not find nonexisting"')
def test_031_get_specific(self): global cherrypy cherrypy.session = {'roles': ['admin', 'planner', 'driver']} response = user.get('username') self.assertEqual(json.loads(response.content)['name'], 'name')
def test_030_get(self): global cherrypy cherrypy.session = {'roles': ['admin', 'planner', 'driver']} response = user.get(None) self.assertEqual(len(json.loads(response.content)['users']), 4)