예제 #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
예제 #2
0
    def create_user(email, password):
        """

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

        try:
            UserEntityDAO.select_by_email(email)
            raise UserAlreadyExistsException()
        except NoResultFound:
            pass

        salt = unicode(uuid.uuid4().hex)
        hashed_password = unicode(hashlib.sha512(password + salt).hexdigest())

        user_entity = UserEntity(email, hashed_password, salt)
        UserEntityDAO.save(user_entity)

        # TODO: Send an email.

        return UserAService.login(email, password)