def login(self, skey="", *args, **kwargs):
if users.get_current_user():
addSkel = skeletonByKind(self.userModule.addSkel().kindName) # Ensure that we have the full skeleton
currentUser = users.get_current_user()
uid = currentUser.user_id()
userSkel = addSkel().all().filter("uid =", uid).getSkel()
if not userSkel:
# We'll try again - checking if there's already an user with that email
userSkel = addSkel().all().filter("name.idx =", currentUser.email().lower()).getSkel()
if not userSkel: # Still no luck - it's a completely new user
if not self.registrationEnabled and not users.is_current_user_admin():
# Registration is disabled, it's a new user and that user is not admin
logging.warning("Denying registration of %s", currentUser.email())
raise errors.Forbidden("Registration for new users is disabled")
userSkel = addSkel() # We'll add a new user
userSkel["uid"] = uid
userSkel["name"] = currentUser.email()
isAdd = True
else:
isAdd = False
now = datetime.datetime.now()
if isAdd or (now-userSkel["lastlogin"]) > datetime.timedelta(minutes=30):
# Conserve DB-Writes: Update the user max once in 30 Minutes
userSkel["lastlogin"] = now
if users.is_current_user_admin():
if not userSkel["access"]:
userSkel["access"] = []
if not "root" in userSkel["access"]:
userSkel["access"].append("root")
userSkel["gaeadmin"] = True
else:
userSkel["gaeadmin"] = False
assert userSkel.toDB()
return self.userModule.continueAuthenticationFlow(self, userSkel["key"])
raise errors.Redirect( users.create_login_url( self.modulePath+"/login") )
评论列表
文章目录