def test_returns_none_when_user_does_not_exist(self): User( username='******', first_name='first', last_name='last', salt="$2a$12$DG39IJLyK/8DQ18Zz/GclO", password= "******", institution='university', email='*****@*****.**', ).save() user = UserService.get_user('not_a_username') assert user is None
def attempt_login(cls, username, password): user = UserService.get_user(username) if not user: return None hashed_pass = hash_password(password, user.salt) if hashed_pass != user.password: return None session = SessionService.get_session_by_user(user) if session: return session.token token = gen_token() SessionService.create_session(user, token) return token
def get(self, username): if not username: return jsonify(message=strings.USER_NO_USERNAME), 400 # try and get the object from the database try: user = UserService.get_user(username) # if we get more than one, something is horribly wrong except User.MultipleObjectsReturned: res = jsonify(message=strings.ENTITY_MULTIPLE_RESULTS) res.status_code = 500 # if it doesn't exist, inform the user except User.DoesNotExist: res = jsonify(message=strings.ENTITY_NOT_FOUND) res.status_code = 404 return res # return the object json = UserViewMapper.to_json_from_model(user) res = jsonify(json) res.status_code = 200 return res