Created
September 26, 2011 06:14
-
-
Save dmitric/1241703 to your computer and use it in GitHub Desktop.
Logging in a user, and using cookies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def post(self): | |
user = self.get_argument("username") | |
pwd = self.get_argument("password") | |
login_info = self.db.logins.find_one({'$or' : [{'username': user.lower() }, {'email': user }]}) | |
if login_info is not None and bcrypt.hashpw(pwd, login_info['pwd_hash']) == login_info['pwd_hash']: | |
user = self.db.users.find_one({"user_id": login_info['user_id']}) | |
self.set_secure_cookie(options.cookie_user, pickle.dumps(user)) | |
self.redirect(self.get_argument("next","/")) | |
else: | |
self.set_secure_cookie(options.cookie_alerts, pickle.dumps([{'content': "Bad login", 'level': 'error'}])) | |
self.redirect("/{0}?next={1}".format(options.login_url,xhtml_escape(self.get_argument("next","")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment