예제 #1
0
    def activate(self):
        query = ("UPDATE user SET user_status_key = %s "
                 "WHERE user.user_id = %s LIMIT 1")

        with admin_transaction() as cursor:
            try:
                cursor.execute(query, (self.STATUS_ACTIVE, self.id))
            except:
                conf.log.exception("Exception. Failed activating user with query '''%s'''." % query)
                raise

        UserCache.instance().clear_user_by_user(self)

        self.status = self.STATUS_ACTIVE
        return self.status
예제 #2
0
 def __init__(self):
     self.__cache = UserCache.instance()
     self.__authcache = AuthenticationCache.instance()
     self.USER_STATUS_LABELS = {
         User.STATUS_INACTIVE: 'inactive',
         User.STATUS_ACTIVE: 'active',
         User.STATUS_BANNED: 'banned',
         User.STATUS_DISABLED: 'disabled'
     }
     # Provide also opposite mapping: {'inactive':User.STATUS_INACTIVE}
     self.USER_STATUS_KEYS = dict((v, k) for k, v in self.USER_STATUS_LABELS.items())
예제 #3
0
    def _expire_cookie(self, req):
        """ Instruct the user agent to drop the auth cookie by setting the
            "expires" property to a date in the past.
        """
        if req.incookie.has_key(COOKIE_AUTH):
            cache = UserCache.instance()
            sql_safe_cookie_value = safe_string(req.incookie[COOKIE_AUTH].value)
            cache.clearUserCookieName(sql_safe_cookie_value)

            # Remove cached cookie
            self.cookie.remove(sql_safe_cookie_value)
            # Create cookie by setting expiration to past
            self._set_outcookie(req, cookie='', expires=(datetime.utcnow() - timedelta(10000)))
예제 #4
0
 def setUp(self):
     dbStub.addResult([
         # id, username, email, mobile, givenname, lastname, icon, pwHash (='password')
         [1, "name", "*****@*****.**", "12345", "Name", "Lastname",
          None, "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"]
     ])
     self._user = multiproject.core.users.User()
     self._user.id = 1
     self._user.username = '******'
     self._user.givenName = 'First'
     self._user.lastName = 'Last'
     self._user.mail = ''
     self._user.mobile = ''
     self._user.password = '******'
     #self._user.account_type = self._user.LOCAL_USER
     self.cache = UserCache.instance()
예제 #5
0
 def setUp(self):
     dbStub.addResult([
         # id, username, email, mobile, givenname, lastname, icon, pwHash (='password')
         [
             1, "name", "*****@*****.**", "12345", "Name", "Lastname", None,
             "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"
         ]
     ])
     self._user = multiproject.core.users.User()
     self._user.id = 1
     self._user.username = '******'
     self._user.givenName = 'First'
     self._user.lastName = 'Last'
     self._user.mail = ''
     self._user.mobile = ''
     self._user.password = '******'
     #self._user.account_type = self._user.LOCAL_USER
     self.cache = UserCache.instance()
예제 #6
0
    def _get_name_for_cookie(self, req, cookie, send_cookie = True):
        """ Fetch cookie->username from database based on cookie value
        """
        cache = UserCache.instance()
        sql_safe_cookie_value = safe_string(cookie.value)

        active = self.cookie.get(sql_safe_cookie_value)

        name = cache.getUserCookieName(sql_safe_cookie_value)
        if name:
            if not active:
                if send_cookie:
                    self._set_outcookie(req, sql_safe_cookie_value)
                self.cookie.add(sql_safe_cookie_value)
            return name

        row = None
        with admin_query() as cursor:
            try:
                cursor.execute("SELECT name FROM auth_cookie WHERE cookie=%s", (sql_safe_cookie_value,))
                row = cursor.fetchone()
            except Exception:
                self.log.exception("Failed to get the name for the cookie")

        if not row:
            # The cookie is invalid (or has been purged from the database), so
            # tell the user agent to drop it as it is invalid
            if send_cookie:
                self._expire_cookie(req)
            return None

        if not active:
            if send_cookie:
                self._set_outcookie(req, sql_safe_cookie_value)
            self.cookie.add(sql_safe_cookie_value)

        cache.setUserCookieName(sql_safe_cookie_value, row[0])
        return row[0]