当前位置: 首页>>代码示例>>Python>>正文


Python tornado.auth方法代码示例

本文整理汇总了Python中tornado.auth方法的典型用法代码示例。如果您正苦于以下问题:Python tornado.auth方法的具体用法?Python tornado.auth怎么用?Python tornado.auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado的用法示例。


在下文中一共展示了tornado.auth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: user_login

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def user_login(self, user):
        """
        This is an override of BaseAuthHandler since anonymous auth is special.
        Generates a unique session ID for this user and saves it in a browser
        cookie.  This is to ensure that anonymous users can't access each
        other's sessions.
        """
        logging.debug("NullAuthHandler.user_login(%s)" % user['upn'])
        # Make a directory to store this user's settings/files/logs/etc
        user_dir = os.path.join(self.settings['user_dir'], user['upn'])
        if not os.path.exists(user_dir):
            logging.info(_("Creating user directory: %s" % user_dir))
            mkdir_p(user_dir)
            os.chmod(user_dir, 0o700)
        session_info = {
            'session': generate_session_id()
        }
        session_info.update(user)
        #print session_info
        self.set_secure_cookie(
            "gateone_user", tornado.escape.json_encode(session_info)) 
开发者ID:jimmy201602,项目名称:django-gateone,代码行数:23,代码来源:authentication.py

示例2: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def __init__(self):
        handlers = [
            (r"/", MainHandler),
            (r"/auth/login", AuthLoginHandler),
            (r"/auth/logout", AuthLogoutHandler),
        ]
        settings = dict(
            cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
            login_url="/auth/login",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=True,
            facebook_api_key=options.facebook_api_key,
            facebook_secret=options.facebook_secret,
            ui_modules={"Post": PostModule},
            debug=True,
            autoescape=None,
        )
        tornado.web.Application.__init__(self, handlers, **settings) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:21,代码来源:facebook.py

示例3: get

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def get(self):
        """
        Deletes the 'gateone_user' cookie and handles some other situations for
        backwards compatibility.
        """
        # Get rid of the cookie no matter what (API auth doesn't use cookies)
        user = self.current_user
        self.clear_cookie('gateone_user')
        check = self.get_argument("check", None)
        if check:
            # This lets any origin check if the user has been authenticated
            # (necessary to prevent "not allowed ..." XHR errors)
            self.set_header('Access-Control-Allow-Origin', '*')
            logout = self.get_argument("logout", None)
            if logout:
                self.user_logout(user['upn'])
                return
        logging.debug('APIAuthHandler: user is NOT authenticated')
        self.write('unauthenticated')
        self.finish() 
开发者ID:jimmy201602,项目名称:django-gateone,代码行数:22,代码来源:authentication.py

示例4: _on_auth

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def _on_auth(self, user):
        if not user:
            raise tornado.web.HTTPError(500, "Google auth failed")
        author = self.db.get("SELECT * FROM authors WHERE email = %s",
                             user["email"])
        if not author:
            # Auto-create first author
            any_author = self.db.get("SELECT * FROM authors LIMIT 1")
            if not any_author:
                author_id = self.db.execute(
                    "INSERT INTO authors (email,name) VALUES (%s,%s)",
                    user["email"], user["name"])
            else:
                self.redirect("/")
                return
        else:
            author_id = author["id"]
        self.set_secure_cookie("user", str(author_id))
        self.redirect(self.get_argument("next", "/")) 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:blog.py

示例5: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def __init__(self):
        handlers = [
            (r"/", MainHandler),
            (r"/auth/login", AuthLoginHandler),
            (r"/auth/logout", AuthLogoutHandler),
        ]
        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/auth/login",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=True,
            facebook_api_key=options.facebook_api_key,
            facebook_secret=options.facebook_secret,
            ui_modules={"Post": PostModule},
            debug=True,
            autoescape=None,
        )
        tornado.web.Application.__init__(self, handlers, **settings) 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:facebook.py

示例6: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def __init__(self):
        handlers = [
            (r"/", MainHandler),
            (r"/auth/login", AuthLoginHandler),
            (r"/auth/logout", AuthLogoutHandler),
            (r"/a/message/new", MessageNewHandler),
            (r"/a/message/updates", MessageUpdatesHandler),
        ]
        settings = dict(
            cookie_secret="43oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/auth/login",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=True,
            autoescape="xhtml_escape",
        )
        tornado.web.Application.__init__(self, handlers, **settings) 
开发者ID:omererdem,项目名称:honeything,代码行数:19,代码来源:chatdemo.py

示例7: _on_access_token

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def _on_access_token(future, response):
        if response.error:
            future.set_exception(tornado.auth.AuthError('GitHub auth error: %s' % str(response)))
            return

        args = tornado.escape.parse_qs_bytes(tornado.escape.native_str(response.body))
        future.set_result(bool(args.get('access_token'))) 
开发者ID:tuna,项目名称:fishroom,代码行数:9,代码来源:oauth.py

示例8: _on_stream

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def _on_stream(self, stream):
        if stream is None:
            # Session may have expired
            self.redirect("/auth/login")
            return
        self.render("stream.html", stream=stream) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:facebook.py

示例9: get

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def get(self):
        my_url = (self.request.protocol + "://" + self.request.host +
                  "/auth/login?next=" +
                  tornado.escape.url_escape(self.get_argument("next", "/")))
        if self.get_argument("code", False):
            self.get_authenticated_user(
                redirect_uri=my_url,
                client_id=self.settings["facebook_api_key"],
                client_secret=self.settings["facebook_secret"],
                code=self.get_argument("code"),
                callback=self._on_auth)
            return
        self.authorize_redirect(redirect_uri=my_url,
                                client_id=self.settings["facebook_api_key"],
                                extra_params={"scope": "read_stream"}) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:17,代码来源:facebook.py

示例10: _on_auth

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def _on_auth(self, user):
        if not user:
            raise tornado.web.HTTPError(500, "Facebook auth failed")
        self.set_secure_cookie("fbdemo_user", tornado.escape.json_encode(user))
        self.redirect(self.get_argument("next", "/")) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:facebook.py

示例11: _on_auth

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def _on_auth(self, user):
        """
        Just a continuation of the get() method (the final step where it
        actually sets the cookie).
        """
        logging.debug("GoogleAuthHandler.on_auth(%s)" % user)
        if not user:
            raise tornado.web.HTTPError(500, _("Google auth failed"))
        # NOTE: Google auth 'user' will be a dict like so:
        # user = {'given_name': 'Joe',
        #    'verified_email': True,
        #    'hd': 'example.com',
        #    'gender': 'male',
        #    'email': 'joe.schmoe@example.com',
        #    'name': 'Joe Schmoe',
        #    'picture': 'https://lh6.googleusercontent.com/path/to/some.jpg',
        #    'id': '999999999999999999999',
        #    'family_name': 'Schmoe',
        #    'link': 'https://plus.google.com/999999999999999999999'}
        user['upn'] = user['email'] # Use the email for the upn
        self.user_login(user)
        next_url = self.get_argument("next", None)
        if next_url:
            self.redirect(next_url)
        else:
            self.redirect(self.settings['url_prefix']) 
开发者ID:jimmy201602,项目名称:django-gateone,代码行数:28,代码来源:authentication.py

示例12: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def __init__(self):
        handlers = [
            (r"/", HomeHandler),
            (r"/archive", ArchiveHandler),
            (r"/feed", FeedHandler),
            (r"/entry/([^/]+)", EntryHandler),
            (r"/compose", ComposeHandler),
            (r"/auth/login", AuthLoginHandler),
            (r"/auth/logout", AuthLogoutHandler),
        ]
        settings = dict(
            blog_title=u"Tornado Blog",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            ui_modules={"Entry": EntryModule},
            xsrf_cookies=True,
            cookie_secret="11oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/auth/login",
            autoescape=None,
        )
        tornado.web.Application.__init__(self, handlers, **settings)

        # Have one global connection to the blog DB across all handlers
        self.db = tornado.database.Connection(
            host=options.mysql_host, database=options.mysql_database,
            user=options.mysql_user, password=options.mysql_password) 
开发者ID:omererdem,项目名称:honeything,代码行数:28,代码来源:blog.py

示例13: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def __init__(self):
        handlers = [
            (r"/", MainHandler),
            (r"/auth/login", AuthHandler),
            (r"/auth/logout", LogoutHandler),
        ]
        settings = dict(
            cookie_secret="32oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/auth/login",
        )
        tornado.web.Application.__init__(self, handlers, **settings) 
开发者ID:omererdem,项目名称:honeything,代码行数:13,代码来源:authdemo.py

示例14: get

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def get(self):
        name = tornado.escape.xhtml_escape(self.current_user["name"])
        self.write("Hello, " + name)
        self.write("<br><br><a href=\"/auth/logout\">Log out</a>") 
开发者ID:omererdem,项目名称:honeything,代码行数:6,代码来源:authdemo.py

示例15: _on_auth

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import auth [as 别名]
def _on_auth(self, user):
        if not user:
            raise tornado.web.HTTPError(500, "Google auth failed")
        self.set_secure_cookie("user", tornado.escape.json_encode(user))
        self.redirect("/") 
开发者ID:omererdem,项目名称:honeything,代码行数:7,代码来源:authdemo.py


注:本文中的tornado.auth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。