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


Python API.get_users方法代码示例

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


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

示例1: get_users

# 需要导入模块: from API import API [as 别名]
# 或者: from API.API import get_users [as 别名]
 def get_users(self, username=None, userid=None, usertype=None):
     # Check if the user is an admin
     if cherrypy.session.get("usertype", "user") == "admin":
         users = API.get_users(username, userid, usertype)
         if users:
             return [user.json for user in users]
         else:
             return json.dumps({"error": "No user matches the request"})
     else:
         return json.dumps({"error": "User not authorized for this request"})
开发者ID:zeagler,项目名称:tangerine,代码行数:12,代码来源:web_interface.py

示例2: admin

# 需要导入模块: from API import API [as 别名]
# 或者: from API.API import get_users [as 别名]
 def admin(self):
     # Check if the user is an admin
     if cherrypy.session.get("usertype", "user") == "admin":
         tmpl = lookup.get_template("admin.html.mako")
         if settings['web_use_auth'] == "true":
             return tmpl.render(
                                 username = cherrypy.session['username'],
                                 userimageurl = cherrypy.session['userimageurl'],
                                 usertype = cherrypy.session['usertype'],
                                 settings = settings,
                                 users = API.get_users(),
                                 hooks = API.get_hooks()
                               )
         else:
             return tmpl.render(
                                 username = cherrypy.session.get("username", "dev"),
                                 userimageurl = cherrypy.session.get("userimageurl", "dev"),
                                 usertype = cherrypy.session.get("usertype", "admin"),
                                 settings = settings,
                                 users = API.get_users(),
                                 hooks = API.get_hooks()
                               )
     else:
         return json.dumps({"error": "User not authorized for this request"})
开发者ID:zeagler,项目名称:tangerine,代码行数:26,代码来源:web_interface.py

示例3: login

# 需要导入模块: from API import API [as 别名]
# 或者: from API.API import get_users [as 别名]
    def login(self, code=None):
        # if the session is already authorized send the user to the main page
        if cherrypy.session.get("authorized", None):
            raise cherrypy.HTTPRedirect("/")

        # if the `code` parameter was POSTed, try to authenticate the user
        if code:
            # First check that the code is valid
            # Query GitHub for an access token for the code
            git_auth = "https://github.com/login/oauth/access_token?" + \
                       "client_id=" + settings['web_github_oauth_id'] + \
                       "&client_secret=" + settings['web_github_oauth_secret'] + \
                       "&code=" + code
            
            req = Request(git_auth)
            res = urlopen(req)
            
            # split the response into a dict
            response = {}
            for param in res.read().decode('utf-8').split("&"):
                response[param.split("=")[0]] = param.split("=")[1]
            
            # Second, get the GitHub acccount information
            # if the code resulted in a valid access token
            if "access_token" in response.keys():
                # Get the user information
                get_info = "https://api.github.com/user?access_token=" + response['access_token']
                req = Request(get_info)
                res = urlopen(req)

                # Parse the resulting JSON
                data = json.loads(res.read().decode('utf-8'))
                
                # if the user is in the authorized user list
                userdata = API.get_users(userid=str(data['id']))
                if userdata:    
                    user_data = userdata[0]
                    if user_data.username == data['login']:
                        # Modify the user session to indicated authorization

                        # store a SHA of the inital request information
                        # if this doesn't match force a new session
                        agent = cherrypy.request.headers['User-Agent']
                        # remote_ip = cherrypy.request.remote.ip
                        print(agent)
                        cherrypy.session["_ident"] = sha256(agent.encode('utf-8')).hexdigest()
                        
                        # Set the expiration time
                        cherrypy.session['expires'] = int(time()) + 1800 # 30 minutes from now

                        # Regenerate the session ID on successful login
                        cherrypy.session.regenerate()
                        
                        # Store user information in the session
                        cherrypy.session["authorized"] = "true"
                        cherrypy.session["userid"] = user_data.userid
                        cherrypy.session["username"] = user_data.username
                        cherrypy.session["usertype"] = user_data.usertype
                        cherrypy.session["userimageurl"] = data['avatar_url']
                        
                        # Send the authorized user to the main page or previous request
                        cherrypy.session["login_msg"] = None
                        redirect = cherrypy.session.get("redirect", "/")
                        raise cherrypy.HTTPRedirect(redirect)
                    
                    else:
                        cherrypy.session["login_msg"] = "Login failed."
                        return "Login failed. User '" + data['login'] + "' is not authorized"
                        
                # The user is not authorized
                else:
                    cherrypy.session["login_msg"] = "Login failed."
                    return "Login failed. User '" + data['login'] + "' is not authorized"

            # The code was not valid or not sent by GitHub
            else:
                cherrypy.session["login_msg"] = "Login failed."
                return "Login failed"

            cherrypy.session["login_msg"] = "Login failed."
            return "There was an error: " + str(response)
        
        # Regenerate the session ID before logging in
        cherrypy.session.regenerate()
        tmpl = lookup.get_template("login.html.mako")
        return tmpl.render(
                            client_id = settings['web_github_oauth_id'],
                            msg = cherrypy.session.get("login_msg", None)
                           )
开发者ID:zeagler,项目名称:tangerine,代码行数:91,代码来源:web_interface.py


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