I am planning on creating an application for the students of my school, and I want to restrict user registration to emails of the form person@myschool.edu. I would prefer to not manually create the user table and do the password hashing and such. Are there any libraries you c开发者_运维百科an recommend for this?
Thanks for the help.
Sometimes, if you just send the user to a login screen you will end in a redirect loop if the user is already logged with a Google Account. What i have found to be a good answer to this problem is to redirect the user to a log out page so he can later login with the domain you want.
I have used this for my code
user = users.get_current_user()
#Check if the user is in @mydomain.com
if user:
emailDomain = user.email().split("@")
if emailDomain[1] == "mydomain.com":
return True
else:
self.redirect(users.create_logout_url('/startPage'))
else:
self.redirect(users.create_login_url(self.request.uri))
This way, the application logs you out automatically and asks for your domain credentials
Since you said you don't know how the email are registered, that you don't want to manage a login/password database and you just need a regexp or somethings (I quote here!), I assume you could keep it very simple. Something like.
user = users.get_current_user()
if user:
emailDomain = user.email().split("@")
if emailDomain == "yourschool.edu":
doSomething()
That way, all the trouble of registering to your app is given to the users (who will need to get a Google Account).
精彩评论