예제 #1
0
 def get(self, action):
     config = Config.get()
     action = urllib.unquote(action)
     to = "http://%s%s" % (config.domain, self.request.GET.get('return', '/'))
     if action.startswith('login'):
         user = users.get_current_user()
         if user:
             if ':' in action:
                 action, to = action.split(":")
                 to = base64.b64decode(to)
             token = multipass.token(
                 dict(guid=user.email(), 
                     email=user.email(), 
                     display_name=user.email().split('@')[0], 
                     expires=(datetime.now() + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%S')),
                 api_key=config.api_key,
                 account_key=config.account)
             self.redirect("%s?sso=%s" % (to, urllib.quote(token)))
         else:
             to = base64.b64encode(to)
             self.redirect(users.create_login_url('/sso/login:%s' % to))
     elif action.startswith('logout'):
         user = users.get_current_user()
         if user:
             to = base64.b64encode(to or self.request.referrer)
             self.redirect(users.create_logout_url('/sso/logout:%s' % to))
         else:
             try:
                 action, to = action.split(":")
                 to = base64.b64decode(to)
             except ValueError:
                 pass
             self.redirect(to)
예제 #2
0
 def get(self, action):
     action = urllib.unquote(action)
     to = self.request.GET.get('to')
     if action.startswith('login'):
         user = users.get_current_user()
         if user:
             if ':' in action:
                 action, to = action.split(":")
                 to = base64.b64decode(to)
                 token = multipass.token(dict(
                     email=user.email(),
                     expires=(
                         datetime.now() +
                         timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%S')),
                                         api_key=MULTIPASS_API_KEY,
                                         account_key=MULTIPASS_ACCOUNT)
             self.redirect("%s?sso=%s" % (to, urllib.quote(token)))
         else:
             to = base64.b64encode(to)
             self.redirect(
                 users.create_login_url('/auth/multipass/login:%s' % to))
     elif action.startswith('logout'):
         user = users.get_current_user()
         if user:
             to = base64.b64encode(to or self.request.referrer)
             self.redirect(
                 users.create_logout_url('/auth/multipass/logout:%s' % to))
         else:
             try:
                 action, to = action.split(":")
                 to = base64.b64decode(to)
             except ValueError:
                 pass
             self.redirect(to)
예제 #3
0
파일: auth.py 프로젝트: djpetti/hd-domain
 def get(self, action):
     action = urllib.unquote(action)
     to = self.request.GET.get('to')
     if action.startswith('login'):
         user = users.get_current_user()
         if user:
             if ':' in action:
                 action, to = action.split(":")
                 to = base64.b64decode(to)
                 token = multipass.token(dict(email=user.email(), expires=(datetime.now() + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%S')),
                     api_key=MULTIPASS_API_KEY,
                     account_key=MULTIPASS_ACCOUNT)
             self.redirect("%s?sso=%s" % (to, urllib.quote(token)))
         else:
             to = base64.b64encode(to)
             self.redirect(users.create_login_url('/auth/multipass/login:%s' % to))
     elif action.startswith('logout'):
         user = users.get_current_user()
         if user:
             to = base64.b64encode(to or self.request.referrer)
             self.redirect(users.create_logout_url('/auth/multipass/logout:%s' % to))
         else:
             try:
                 action, to = action.split(":")
                 to = base64.b64decode(to)
             except ValueError:
                 pass
             self.redirect(to)