Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 3
0
    def run(self):
        """
            Implements the class contract.
        """

        user = UserEntityDAO.select_by_id(self.user_id)
        reset_code = "%s%s%s%s%s%s" % (random.randint(0, 9),
                                       random.randint(0, 9),
                                       random.randint(0, 9),
                                       random.randint(0, 9),
                                       random.randint(0, 9),
                                       random.randint(0, 9))
        user.reset_password_code = reset_code

        #send the email
        EmailService.send_password_reset(user)