本文整理匯總了Python中database.User.get_by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python User.get_by_id方法的具體用法?Python User.get_by_id怎麽用?Python User.get_by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類database.User
的用法示例。
在下文中一共展示了User.get_by_id方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def post(self):
try:
user = User.get_by_id(self.getUser())
self.sendActivationEmail(user.email, user.activationCode)
self.render("verify.html", color="green", status="Email Sent")
except:
self.render("verify.html", color="end", status="Email failed to send")
示例2: get
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def get(self):
AUTHORIZATION_CODE = self.request.get('code')
data = {
"client_id": constants.CLIENT_ID,
"client_secret": constants.CLIENT_SECRET,
"code":AUTHORIZATION_CODE
}
response = requests.post("https://api.venmo.com/v1/oauth/access_token", data)
response_dict = response.json()
# update user venmo info like email and venmoID
db_user = User.get_by_id(self.getUser())
if db_user.permission == "guest":
pass
else:
db_user.venmoID = int(response_dict.get('user').get('id'))
db_user.venmo_email = response_dict.get('user').get('email')
db_user.put()
access_token = response_dict.get('access_token')
user = response_dict.get('user').get('username')
self.session['venmo_token'] = access_token
self.session['venmo_username'] = user
self.session['signed_into_venmo'] = True
nextURL = self.request.get('next')
return self.redirect(nextURL if nextURL else '/home')
示例3: post
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def post(self):
user = User.get_by_id(self.getUser())
if "updatePassword" in self.request.POST:
password_success, password_error = "", ""
if validation.valid_pw(user.username,
self.request.get('currentPassword'),
user.passHash):
new_pass = self.request.get('new_password')
if new_pass == self.request.get('verifyNewPassword'):
user.passHash = validation.make_pw_hash(
user.username, new_pass)
user.put()
password_success = "Password Changed Successfully!"
else:
password_error = "New passwords are not the same"
else:
password_error = "That is not your current password"
self.render('admin.html',
user=user,
update_error=password_error,
update_success=password_success)
elif "otherChanges" in self.request.POST:
user_email = self.request.get('email')
venmo_email = self.request.get('venmo_email')
email = validation.edu_email(user_email)
venmo_email_verify = validation.email(venmo_email)
email_error, venmo_email_error, update_success, update_error = "", "", "", ""
if not email:
email_error = "That's not a valid email."
user_email = ""
if venmo_email != "" and venmo_email_verify is None:
venmo_email_error = "Invalid email. This is an optional field."
venmo_email = ""
if email and (venmo_email_error == ""):
try:
user.email = user_email
user.venmo_email = venmo_email
user.bio = self.request.get('bio')
user.put()
update_success = "Succesfully Updated!"
except:
update_error = "Could not save changes :("
self.render('admin.html',
user=user,
update_success=update_success,
update_error=update_error,
email_error=email_error,
venmo_email_error=venmo_email_error)
示例4: get
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def get(self):
recover, userID = False, ""
uid = self.request.get('userID')
code = self.request.get('code')
if uid and code:
user = User.get_by_id(int(uid))
if user and user.recoveryCode and user.recoveryCode == code:
# display password recovery
recover = True
userID = uid
self.render('recover.html', recover=recover, userID=userID)
示例5: get
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def get(self):
code = self.request.get("code")
user = User.get_by_id(self.getUser())
if not code:
self.render("verify.html")
else:
if code == user.activationCode:
user.activated = True
user.put()
#self.render("verify.html", color="green", status="Successfully Verified :)")
#sleep(2.0)
self.response.headers.add_header('Set-Cookie', str('is_user_activated=%s; Path=/' % "True"))
self.redirect("/view")
else:
self.render("verify.html", color="red", status="Not the right activation code :(")
示例6: post
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def post(self):
if "recoverUsername" in self.request.POST:
try:
email = self.request.get('email')
self.recoverUsernameUsingEmail(email)
self.render('recover.html', color="green", status="Sent recovery email to %s :)" % (email))
except:
self.render('recover.html', color="red", status="Could not send email to %s :(" % (email))
elif "recoverPassword" in self.request.POST:
try:
username = self.request.get('username')
email = ""
user = None
if username:
print username
user = User.gql("WHERE username=:username", username=username).get()
email = user.email
else:
email = self.request.get('email')
user = User.gql("WHERE email=:email", email=email).get()
salt = validation.make_salt(25)
link = "http://%s/recover?userID=%s&code=%s" % (self.request.host, user.key().id(), salt)
user.recoveryCode = salt
user.put()
self.sendPasswordRecoveryEmail(email, user, link)
self.render('recover.html', color="green",
status="Sent recovery email to a %s account :)" % (email.split("@")[1]))
except:
self.render('recover.html', color="red", status="Could not send email :(")
elif "resetPassword" in self.request.POST:
userID = self.request.get('userID')
user = User.get_by_id(int(userID))
newPass = self.request.get('newPassword')
passwordSuccess, passwordError = "", ""
if newPass == self.request.get('verifyNewPassword'):
user.passHash = validation.make_pw_hash(user.username, newPass)
user.recoveryCode = None
user.put()
passwordSuccess = "Password Changed Successfully!"
self.render('recover.html', color="green", status=passwordSuccess)
else:
passwordError = "New passwords are not the same"
self.render('recover.html', color="red", status=passwordError, recover=True, userID=userID)
示例7: get
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def get(self):
#Initialization
self.deleteOldRides()
#Get current user
userId = self.getUser()
user = User.get_by_id(userId)
#Finding the rides user is not in
rideIds = user.rideIds
rides = list(Ride.gql("ORDER BY startTime DESC LIMIT 10"))
rides = [r for r in rides if r.key().id() not in rideIds]
#Update ride information
for ride in rides:
ride.driverName = ride.driver.username
ride.seatsLeft = ride.passengerMax - len(ride.passIds)
#Finds the requests the user has made
# requests = list(db.GqlQuery("SELECT * FROM Request WHERE requesterId = :userId", userId=self.getUser()))
# requests = [x.rideId for x in requests]
# rides = [x for x in rides if x.key().id() not in requests]
# for ride in rides:
# ride.driverName = User.get_by_id(ride.driverId).username
sortType = self.request.get('sort', default_value='time')
raw_start = self.request.get('start')
raw_destination = self.request.get('dest')
if sortType == 'time':
rides = sorted(rides, key=lambda x:x.startTime)
elif sortType == 'cost':
rides = sorted(rides, key=lambda x:x.cost)
elif sortType == 'start':
try:
start = Geocoder.geocode(raw_start)
except:
error = 'We could not find your start location. Please check that you spelled it correctly.'
self.render_front(rides, rawStart, rawDestination, error)
return
rides = sorted(rides,
key=lambda x:self.getLocationInfo(start, Geocoder.geocode(x.start))['distance']['value'])
elif sortType == 'dest':
try:
destination = Geocoder.geocode(raw_destination)
except:
error = 'We could not find your destination. Please check that you spelled it correctly.'
self.render_front(rides, rawStart, rawDestination, error)
return
rides = sorted(rides,
key=lambda x: self.getLocationInfo(Geocoder.geocode(x.destination), destination)['distance']['value'])
elif sortType == 'start_and_dest':
try:
start = Geocoder.geocode(raw_start)
except:
error = 'We could not find your start location. Please check that you spelled it correctly.'
self.render_front(rides, rawStart, rawDestination, error)
return
try:
destination = Geocoder.geocode(raw_destination)
except:
error = 'We could not find your destination. Please check that you spelled it correctly.'
self.render_front(rides, rawStart, rawDestination, error)
return
total_distance = lambda x: self.getLocationInfo(start, Geocoder.geocode(x.start))['distance']['value'] + self.getLocationInfo(Geocoder.geocode(x.destination), destination)['distance']['value']
rides = sorted(rides,
key=total_distance)
self.render("rideSearch.html", rides=rides)
示例8: get
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def get(self):
user = User.get_by_id(self.getUser())
payments = user.payments
self.render('payments.html', payments=payments)
示例9: get
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_id [as 別名]
def get(self):
user = User.get_by_id(self.getUser())
self.render('admin.html', user=user)