def redirect(self, url, status=303): if status == 302: return web.found(url) elif status == 303: return web.seeother(url) elif status == 304: return web.notmodified(url) elif status == 306: return web.tempredirect(url) else: return web.seeother(url)
def redirect(self, url, status=303): if status == 302: return web.found(url) elif status == 303: return web.seeother(url) elif status == 304: return web.notmodified(url) elif status == 306: return web.tempredirect(url) else: return web.seeother(url)
def wrapper(self, *args, **kwargs): if web.ctx.path[0:6] == '/data/': languages = unicode(karesansui.config['application.default.locale']) if web.ctx.env.has_key('HTTP_AUTHORIZATION'): _http_auth = web.ctx.env['HTTP_AUTHORIZATION'].strip() if _http_auth[:5] == 'Basic': email, password = b64decode(_http_auth[6:].strip()).split(':') session = web.ctx.orm user = findby1email(session, email) languages = user.languages self._ = mako_translation(languages=[ unicode(languages), ]) return func(self, *args, **kwargs) if karesansui_database_exists() is False: return web.tempredirect(web.ctx.path + "init", absolute=False) if web.ctx.env.has_key('HTTP_AUTHORIZATION'): (user, email) = login() if user: self.me = user # Logout fname = '%s%s' % (LOGOUT_FILE_PREFIX, self.me.email,) if os.access(fname, os.F_OK): os.unlink(fname) return web.unauthorized() # Login: Success if user.languages in self.languages: x = self.languages.index(user.languages) self.languages.pop(x) self.languages.insert(0, user.languages) self.logger.info('user_id=%s,lang=%s : Method=%s - Basic Authentication=Success' % (self.me.id, ','.join(self.languages), self.__method__)) # __init__#self._ update!! self._ = mako_translation(languages=self.languages) return func(self, *args, **kwargs) else: # Login: Failure self.logger.info('user=%s : Method=%s - Basic Authentication=Failure' % (email, self.__method__)) return web.unauthorized() else: # Login: Anonymous self.logger.info('user=anonymous : Method=%s - Basic Authentication=Anonymous' % (self.__method__)) return web.unauthorized()
def _GET(self, *param, **params): self.view.database_bind = karesansui.config['database.bind'] self.view.default_locale = karesansui.config['application.default.locale'] self.view.locales = DEFAULT_LANGS.keys() if karesansui_database_exists() is True: return web.tempredirect("/", absolute=False) if self.is_mode_input(): return True else: return True return True
def last_month(): last_month = web.query("select month(max(date)) month, year(max(date)) year from images")[0] web.tempredirect(config.base_url+uihelper.build_link((("year", last_month.year),("month", last_month.month))))
def GET(self): session.login = False session.user = None session.kill() return web.tempredirect('/#login')
def GET(self): sid = web.input().get('sid', '') if not sid: print 'no sid' return client = OAuthClient(key=API_KEY, secret=SECRET) cookies = web.cookies() access_key = cookies.get('access_key') access_secret = access_tokens.get(access_key) if not access_key or not access_secret: request_key = web.input().get('oauth_token', '') request_secret = request_tokens.get(request_key) if request_key and request_secret: try: access_key, access_secret = \ client.get_access_token(request_key, request_secret) if access_key and access_secret: # store user access key in cookie, # not accessable by other people web.setcookie('access_key', access_key) access_tokens[access_key] = access_secret except Exception: access_token = None print '获取用户授权失败' return else: client = OAuthClient(key=API_KEY, secret=SECRET) key, secret = client.get_request_token() if key and secret: request_tokens[key] = secret url = client.get_authorization_url( key, secret, callback=HOST + PREFIX + '/collection?sid=' + sid) web.tempredirect(url) return else: print '获取 Request Token 失败' return service = DoubanService(api_key=API_KEY, secret=SECRET) movie = service.GetMovie(sid) html_header() search_panel() print '<h2>你希望收藏电影: %s</h2>' % (movie.title.text) print '<div class="obss" style="margin-top:20px">' print '<dl class="obs"><dt>' print '<a href="%s" title="%s"><img src="%s" class="m_sub_img"/></a>' % ( movie.GetAlternateLink().href, movie.title.text, movie.link[2].href) print '</dt><dd>' print '<a href="%s">%s</a>' % (movie.GetAlternateLink().href, movie.title.text) print '</dd>' print '</dl>' if access_key and access_secret: if service.ProgrammaticLogin(access_key, access_secret): try: entry = service.AddCollection('wish', movie, tag=['test']) if entry: print '<span>已添加到你的收藏</span>' else: print '<span>添加收藏失败</span>' except Exception: print '<span>添加收藏失败, 授权失效</span>' del access_tokens[access_key] web.setcookie('access_key', '', 0) else: print '<span>无法添加收藏,可能你因为你没有授权这个应用访问你在豆瓣的数据</span>' print '</div>' html_footer()
def wrapper(self, *args, **kwargs): if web.ctx.path[0:6] == '/data/': languages = unicode( karesansui.config['application.default.locale']) if web.ctx.env.has_key('HTTP_AUTHORIZATION'): _http_auth = web.ctx.env['HTTP_AUTHORIZATION'].strip() if _http_auth[:5] == 'Basic': email, password = b64decode( _http_auth[6:].strip()).split(':') session = web.ctx.orm user = findby1email(session, email) languages = user.languages self._ = mako_translation(languages=[ unicode(languages), ]) return func(self, *args, **kwargs) if karesansui_database_exists() is False: return web.tempredirect(web.ctx.path + "init", absolute=False) if not web.ctx.env.has_key('HTTP_AUTHORIZATION'): if web.ctx.env.has_key('Authorization'): web.ctx.env['HTTP_AUTHORIZATION'] = web.ctx.env[ 'Authorization'] if web.ctx.env.has_key('HTTP_AUTHORIZATION'): (user, email) = login() if user: self.me = user # Logout fname = '%s%s' % ( LOGOUT_FILE_PREFIX, self.me.email, ) if os.access(fname, os.F_OK): os.unlink(fname) return web.unauthorized() # Login: Success if user.languages in self.languages: x = self.languages.index(user.languages) self.languages.pop(x) self.languages.insert(0, user.languages) self.logger.info( 'user_id=%s,lang=%s : Method=%s - Basic Authentication=Success' % (self.me.id, ','.join(self.languages), self.__method__)) # __init__#self._ update!! self._ = mako_translation(languages=self.languages) return func(self, *args, **kwargs) else: # Login: Failure self.logger.info( 'user=%s : Method=%s - Basic Authentication=Failure' % (email, self.__method__)) return web.unauthorized() else: # Login: Anonymous self.logger.info( 'user=anonymous : Method=%s - Basic Authentication=Anonymous' % (self.__method__)) return web.unauthorized()
def GET(self): session.login = False session.user = None session.kill() return web.tempredirect('/#login')
def GET(self): sid = web.input().get('sid','') if not sid: print 'no sid' return client = OAuthClient(key=API_KEY, secret=SECRET) cookies = web.cookies() access_key = cookies.get('access_key') access_secret = access_tokens.get(access_key) if not access_key or not access_secret: request_key = web.input().get('oauth_token','') request_secret = request_tokens.get(request_key) if request_key and request_secret: try: access_key, access_secret = \ client.get_access_token(request_key, request_secret) if access_key and access_secret: # store user access key in cookie, # not accessable by other people web.setcookie('access_key', access_key) access_tokens[access_key] = access_secret except Exception: access_token = None print '获取用户授权失败' return else: client = OAuthClient(key=API_KEY, secret=SECRET) key, secret = client.get_request_token() if key and secret: request_tokens[key] = secret url = client.get_authorization_url(key, secret, callback=HOST+PREFIX+'/collection?sid='+sid) web.tempredirect(url) return else: print '获取 Request Token 失败' return service = DoubanService(api_key=API_KEY, secret=SECRET) movie = service.GetMovie(sid) html_header() search_panel() print '<h2>你希望收藏电影: %s</h2>' % (movie.title.text) print '<div class="obss" style="margin-top:20px">' print '<dl class="obs"><dt>' print '<a href="%s" title="%s"><img src="%s" class="m_sub_img"/></a>' % (movie.GetAlternateLink().href, movie.title.text, movie.link[2].href) print '</dt><dd>' print '<a href="%s">%s</a>' % (movie.GetAlternateLink().href, movie.title.text) print '</dd>' print '</dl>' if access_key and access_secret: if service.ProgrammaticLogin(access_key, access_secret): try: entry = service.AddCollection('wish', movie, tag=['test']) if entry: print '<span>已添加到你的收藏</span>' else: print '<span>添加收藏失败</span>' except Exception: print '<span>添加收藏失败, 授权失效</span>' del access_tokens[access_key] web.setcookie('access_key', '', 0) else: print '<span>无法添加收藏,可能你因为你没有授权这个应用访问你在豆瓣的数据</span>' print '</div>' html_footer()