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


Python Utils.status方法代码示例

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


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

示例1: login

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
  def login(self):

    body = json.JSONDecoder().decode( cherrypy.request.body.read() )
    
    check = Utils.arg_check(body, ["username","password"])
    if (check[0]):
		return check[1]

    matchingUsers = Utils.query("SELECT * FROM Users u WHERE u.username=%s AND u.password=SHA1(CONCAT(%s, u.salt))", (body["username"], body["password"]))
    
    if(len(matchingUsers) == 0):
      return json.JSONEncoder().encode({
        "status" : Utils.status(324,"Could not locate user")
      })
    elif (len(matchingUsers) == 1):
      sessionID = str(uuid.uuid4())
      Utils.execute("INSERT INTO User_Sessions(user_id, session_token) VALUES(%s, %s)",(matchingUsers[0]["user_id"], sessionID))
      
      return json.JSONEncoder().encode({
        "token": sessionID,
        "status" : Utils.status(0, "OK")
      })
    else:
      return json.JSONEncoder().encode({
        "status" : Utils.status(323,"The system is in an invalid state.")
      })
开发者ID:petryjc,项目名称:WhatDoIDo,代码行数:28,代码来源:core.py

示例2: logout

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
  def logout(self):
    body = json.loads( cherrypy.request.body.read() )

    count = Utils.execute("DELETE FROM User_Session WHERE session_token = %s",(body["token"]))
    if(count > 0):
      return json.JSONEncoder().encode({
        "status" : Utils.status(0, "OK")
      })
    else:
      return json.JSONEncoder().encode({
        "status" : Utils.status(125, "Could not locate user with provided token")
      })
开发者ID:sternetj,项目名称:BaseballAuction,代码行数:14,代码来源:core.py

示例3: deleteAccount

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
 def deleteAccount(self):
   body = json.loads( cherrypy.request.body.read() )
   
   count = Utils.execute("DELETE u FROM User_Session us LEFT JOIN User u ON us.user_id = u.user_id WHERE username = %s and password = %s",(body["username"], body["password"]))
   
   if(count > 0):
     return json.JSONEncoder().encode({
       "status" : Utils.status(0, "OK")
     })
   else:
     return json.JSONEncoder().encode({
       "status" : Utils.status(433, "Could not delete user account.")
     })
开发者ID:sternetj,项目名称:BaseballAuction,代码行数:15,代码来源:core.py

示例4: register

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
  def register(self):
    body = json.loads( cherrypy.request.body.read() )

    count = Utils.execute("INSERT INTO User (username, password, email, salt) VALUES (%s, %s, %s, 'ABCDEFG')", (body['username'], body['password'], body['email']) )

    if(count == 1):
      return json.JSONEncoder().encode({
        "status" : Utils.status(0, "OK")
      })
    else:
      return json.JSONEncoder().encode({
        "status" : Utils.status(431, "Could not register user account.")
      })
开发者ID:sternetj,项目名称:BaseballAuction,代码行数:15,代码来源:core.py

示例5: deleteAccount

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
  def deleteAccount(self):

    body = json.JSONDecoder().decode( cherrypy.request.body.read() )
    check = Utils.arg_check(body, ["username","password"])
    if (check[0]):
            return check[1]
    
    count = Utils.execute("DELETE u FROM Users u WHERE u.username = %s and u.password = SHA1(CONCAT(%s, u.salt))",(body["username"], body["password"]))
    
    if(count > 0):
      return json.JSONEncoder().encode({
        "status" : Utils.status(0, "OK")
      })
    else:
      return json.JSONEncoder().encode({
        "status" : Utils.status(433, "Could not delete user account.")
      })
开发者ID:petryjc,项目名称:WhatDoIDo,代码行数:19,代码来源:core.py

示例6: register

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
 def register(self):
   body = json.JSONDecoder().decode( cherrypy.request.body.read() )
   
   check = Utils.arg_check(body, ["username","password", "email"])
   if (check[0]):
           return check[1]
   
   
   password_hash = str(uuid.uuid4())
   count = Utils.execute("INSERT INTO Users (username, password, email, salt) VALUES (%s, SHA1(CONCAT(%s, %s)), %s, %s)", (body['username'], body['password'], password_hash, body['email'], password_hash) )
   
   if(count == 1):
     return json.JSONEncoder().encode({
       "status" : Utils.status(0, "OK")
     })
   else:
     return json.JSONEncoder().encode({
       "status" : Utils.status(431, "Could not register user account.")
     })
开发者ID:petryjc,项目名称:WhatDoIDo,代码行数:21,代码来源:core.py

示例7: pending_requests

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
  def pending_requests(self): 
    body = json.JSONDecoder().decode( cherrypy.request.body.read() )
    check = Utils.arg_check(body, ["token"])

    if (check[0]): 
      return check[1]

    # Find the user ID of the person making the request.
    user_check = Utils.validate_user(body["token"])
    if(user_check[0]):
      return user_check[1]
    user_id = user_check[1]

    requests = Utils.query("""SELECT user_id,username,email 
                              FROM Users u
                              JOIN Buddies b ON u.user_id = b.requester_id
                              WHERE b.requestee_id=%s AND b.approved=0""", 
              (user_id))
              
    return json.JSONEncoder().encode( {"status": Utils.status(0,"OK"),"requests":requests } )
开发者ID:petryjc,项目名称:WhatDoIDo,代码行数:22,代码来源:buddies.py

示例8: get_configuration

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
  def get_configuration(self):
    length  = cherrypy.request.headers[ 'Content-Length' ]
    rawbody = cherrypy.request.body.read( int( length ) )
    body    = json.loads( rawbody )

    db = Utils.database()

    cur = db.cursor()
    cur.execute( "SELECT * FROM User_Session WHERE session_token = '%s'" % body["token"] )

    data = cur.fetchall()
    db.close()

    if not data: # There's a valid session
      return json.JSONEncoder().encode(
        {
            "status" : Utils.status(245, "You do not have a valid session token")
        } )

    return """
开发者ID:sternetj,项目名称:BaseballAuction,代码行数:22,代码来源:core.py

示例9: accept

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
  def accept(self): 
    body = json.JSONDecoder().decode( cherrypy.request.body.read() )
    check = Utils.arg_check(body, ["token","buddy_id"])

    if (check[0]): 
      return check[1]

    # Find the user ID of the person making the request.
    user_check = Utils.validate_user(body["token"])
    if(user_check[0]):
      return user_check[1]
    user_id = user_check[1]

    try:
        Utils.execute("""UPDATE Buddies
                         SET approved=1
                         WHERE requester_id=%s AND requestee_id=%s""",
                         (body["buddy_id"],user_id))
    except Exception:
        return json.JSONEncoder().encode({"status": Utils.status(3981,"Could not approve buddy")})

    return json.JSONEncoder().encode(Utils.status_more(0, "OK"))
开发者ID:petryjc,项目名称:WhatDoIDo,代码行数:24,代码来源:buddies.py

示例10: request

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import status [as 别名]
  def request(self): 
    body = json.JSONDecoder().decode( cherrypy.request.body.read() )
    check = Utils.arg_check(body, ["token","buddy"])

    if (check[0]): 
      return check[1]

    # Find the user ID of the person making the request.
    user_check = Utils.validate_user(body["token"])
    if(user_check[0]):
      return user_check[1]
    user_id = user_check[1]

    matching_users = Utils.query("""SELECT * FROM Users WHERE username=%s OR email=%s""", 
              (body["buddy"],body["buddy"]))

    if len(matching_users) == 0:
      return json.JSONEncoder().encode( Utils.status_more( 112, "Could not locate user" ) )
    
    matching_user = matching_users[0]
    
    if matching_user["user_id"] == user_id:
      return json.JSONEncoder().encode( Utils.status_more( 115, "Cannot be buddies with yourself" ) )

    in_buddies = Utils.query("""SELECT * FROM Buddies WHERE (requester_id = %s AND requestee_id = %s) OR (requester_id = %s AND requestee_id = %s)""", (user_id,matching_user["user_id"],matching_user["user_id"],user_id))

    if any(in_buddies):
      return json.JSONEncoder().encode( Utils.status_more( 115, "Cannot request buddy when you are already buddies or there is already a pending request between you." ) )

    try:
        Utils.execute("""INSERT INTO Buddies(requester_id, requestee_id, approved) VALUE(%s,%s,0)""",
          (user_id,matching_user["user_id"]))
    except Exception:
        return json.JSONEncoder().encode({"status": Utils.status(3981,"Could not request buddy")})

    return json.JSONEncoder().encode(Utils.status_more(0, "OK"))
开发者ID:petryjc,项目名称:WhatDoIDo,代码行数:38,代码来源:buddies.py


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