Exemple #1
0
    def login(email, password):
        """

        """
        assert isinstance(email, unicode)
        assert isinstance(password, unicode)
        assert email
        assert password

        try:
            user_entity = UserEntityDAO.select_by_email(email)
        except NoResultFound:
            raise InvalidCredentialsException()

        hashed_password = hashlib.sha512(password + user_entity.salt).hexdigest()

        if hashed_password != user_entity.password:
            raise InvalidCredentialsException()

        access_token_entity = AccessTokenEntity(
            user_entity,
            uuid.uuid4().hex,
        )
        AccessTokenDAO.save(access_token_entity)

        return access_token_entity.access_token