Example #1
0
    def successful_login(self, user, assumed_by=None):
        login_rec = model.Login(user)
        login_rec.successful = True
        login_rec.session_id = str(uuid.uuid4())
        login_rec.assumed_by = assumed_by
        #session_id = "session_id:{}".format(login_rec.session_id)
        session_id_signature = actual_hmac_creation(login_rec.session_id)
        session_id_signed = login_rec.session_id + ":" + session_id_signature
        logger.debug("session_id_signed:", session_id_signed)

        if not user.id:
            user.id = ''

        session = dict(login_time=time.time(),
                       user_id=user.id,
                       user_name=user.full_name,
                       user_email_address=user.email_address)

        key = UserSession.cookie_name + ":" + login_rec.session_id
        logger.debug("Key when signing:", key)
        Redis.hmset(key, session)
        if self.remember_me:
            expire_time = self.remember_time
        else:
            expire_time = THREE_DAYS
        Redis.expire(key, expire_time)

        return session_id_signed
Example #2
0
 def unsuccessful_login(self, user):
     login_rec = model.Login(user)
     login_rec.successful = False
     db_session.add(login_rec)
     db_session.commit()