本文整理汇总了Python中utils.Utils.validate_user方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.validate_user方法的具体用法?Python Utils.validate_user怎么用?Python Utils.validate_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Utils
的用法示例。
在下文中一共展示了Utils.validate_user方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initUser
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import validate_user [as 别名]
def initUser(self):
username = "DemoTest"
password = "testing"
email = "[email protected]"
registerCommand = json.JSONEncoder().encode({
"username" : username,
"password" : password,
"email" : email
})
registrationResult = json.loads(self.callPostCommand(registerCommand, 'api/register'))
loginCommand = json.JSONEncoder().encode({
"username" : username,
"password" : password,
})
loginResult = json.loads(self.callPostCommand(loginCommand, 'api/login'))
print(loginResult)
print registrationResult
self.token =str(loginResult['token'])
self.user_id = Utils.validate_user(self.token)[1]
示例2: add
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import validate_user [as 别名]
def add(self):
body = json.loads( cherrypy.request.body.read() )
check = Utils.arg_check(body, ['token', 'latitude', 'longitude'])
if (check[0]):
return check[1]
user_check = Utils.validate_user(body["token"])
if(user_check[0]):
return user_check[1]
user_id = user_check[1]
base = "http://maps.googleapis.com/maps/api/geocode/json?"
params = "latlng={lat},{lon}&sensor={sen}".format(
lat=body['latitude'],
lon=body['longitude'],
sen=True
)
url = "{base}{params}".format(base=base, params=params)
response = requests.get(url)
if (response):
content = response.json()
if (content and content['results'] and content['results'][0] and content['results'][0]['formatted_address']):
savedLocations = Utils.query("""SELECT * FROM Locations WHERE address = %s""",
(content['results'][0]['formatted_address']))
#print savedLocations
if (len(savedLocations) == 1):
location_id = savedLocations[0]["location_id"]
elif (len(savedLocations) > 1):
return json.JSONEncoder().encode( Utils.status_more( 34, "Inconsistet database" ) )
else:
location_id = Utils.execute_id("""INSERT INTO Locations(latitude, longitude, address, place)
VALUES(%s, %s, %s, %s)""",
(body["latitude"], body["longitude"], content['results'][0]['formatted_address'], "I don't know"))
if (location_id != -1):
previousUserLocation = Utils.query("""SELECT location_id FROM Users_Locations
WHERE user_id = %s
ORDER BY time DESC LIMIT 1""", (user_id))
is_route = False
if previousUserLocation:
previousLocation = Utils.query("""SELECT * FROM Locations WHERE location_id = %s""", (previousUserLocation[0]["location_id"]))
if len(previousLocation) == 1 and self.checkDistance(previousLocation[0]["latitude"], previousLocation[0]["longitude"],body["latitude"],body["longitude"]) == 1:
is_route = True
Utils.execute("""INSERT INTO Users_Locations(user_id, location_id, time, is_route)
VALUES(%s, %s, %s, %s)""",
(user_id, location_id, datetime.now(), is_route))
return json.JSONEncoder().encode( Utils.status_more( 0, "OK" ) )
return json.JSONEncoder().encode( Utils.status_more( 35, "Could not save to database" ) )
return json.JSONEncoder().encode( Utils.status_more( 33, "Could not retrieve location information" ) )
示例3: pending_requests
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import validate_user [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 } )
示例4: accept
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import validate_user [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"))
示例5: request
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import validate_user [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"))