def post(self): username = self.get_argument("username", "").strip().lower() passwd = self.get_argument("password", "") nextpage = self.get_argument("next", "/") msg = "" # check the user level try: if User(username).level == "unverified": # email not verified so dont log in msg = "Email not verified" except QiitaDBUnknownIDError: msg = "Unknown user" # Check the login information login = None try: login = User.login(username, passwd) except IncorrectEmailError: msg = "Unknown user" except IncorrectPasswordError: msg = "Incorrect password" if login: # everything good so log in self.set_current_user(username) self.redirect(nextpage) else: self.render("index.html", user=None, loginerror=msg)
def post(self): username = self.get_argument("username", "") passwd = self.get_argument("password", "") # check the user level try: if User(username).level == 4: # 4 is id for unverified # email not verified so dont log in msg = "Email not verified" except QiitaDBUnknownIDError: msg = "Unknown user" # Check the login information login = None try: login = User.login(username, passwd) except IncorrectEmailError: msg = "Unknown user" except IncorrectPasswordError: msg = "Incorrect password" if login: # everthing good so log in self.set_current_user(username) self.redirect("/") return self.render("index.html", user=None, loginerror=msg)
def post(self): if r_client.get('maintenance') is not None: raise HTTPError(503, "Site is down for maintenance") username = self.get_argument("username", "").strip().lower() passwd = self.get_argument("password", "") nextpage = self.get_argument("next", None) if nextpage is None: if "auth/" not in self.request.headers['Referer']: nextpage = self.request.headers['Referer'] else: nextpage = "%s/" % qiita_config.portal_dir msg = "" # check the user level try: if User(username).level == "unverified": # email not verified so dont log in msg = ("Email not verified. Please check your email and click " "the verify link. You may need to check your spam " "folder to find the email.<br/>If a verification email" " has not arrived in 15 minutes, please email <a href='" "mailto:[email protected]'>[email protected]</a>") except QiitaDBUnknownIDError: msg = "Unknown user" except RuntimeError: # means DB not available, so set maintenance mode and failover r_client.set( "maintenance", "Database connection unavailable, " "please try again later.") self.redirect("%s/" % qiita_config.portal_dir) return # Check the login information login = None try: login = User.login(username, passwd) except IncorrectEmailError: msg = "Unknown user" except IncorrectPasswordError: msg = "Incorrect password" except UnverifiedEmailError: msg = "You have not verified your email address" if login: # everything good so log in self.set_current_user(username) self.redirect(nextpage) else: self.render("index.html", message=msg, level='danger')
def post(self): if r_client.get('maintenance') is not None: raise HTTPError(503, "Site is down for maintenance") username = self.get_argument("username", "").strip().lower() passwd = self.get_argument("password", "") nextpage = self.get_argument("next", None) if nextpage is None: if "auth/" not in self.request.headers['Referer']: nextpage = self.request.headers['Referer'] else: nextpage = "%s/" % qiita_config.portal_dir msg = "" # check the user level try: if User(username).level == "unverified": # email not verified so dont log in msg = ("Email not verified. Please check your email and click " "the verify link. You may need to check your spam " "folder to find the email.<br/>If a verification email" " has not arrived in 15 minutes, please email <a href='" "mailto:[email protected]'>[email protected]</a>") except QiitaDBUnknownIDError: msg = "Unknown user" except RuntimeError: # means DB not available, so set maintenance mode and failover r_client.set("maintenance", "Database connection unavailable, " "please try again later.") self.redirect("%s/" % qiita_config.portal_dir) return # Check the login information login = None try: login = User.login(username, passwd) except IncorrectEmailError: msg = "Unknown user" except IncorrectPasswordError: msg = "Incorrect password" except UnverifiedEmailError: msg = "You have not verified your email address" if login: # everything good so log in self.set_current_user(username) self.redirect(nextpage) else: self.render("index.html", message=msg, level='danger')
def post(self): if r_client.get('maintenance') is not None: raise HTTPError(503, "Site is down for maintenance") username = self.get_argument("username", "").strip().lower() passwd = self.get_argument("password", "") nextpage = self.get_argument("next", None) if nextpage is None: if "auth/" not in self.request.headers['Referer']: nextpage = self.request.headers['Referer'] else: nextpage = "/" msg = "" # check the user level try: if User(username).level == "unverified": # email not verified so dont log in msg = "Email not verified" except QiitaDBUnknownIDError: msg = "Unknown user" except RuntimeError: # means DB not available, so set maintenance mode and failover r_client.set( "maintenance", "Database connection unavailable, " "please try again later.") self.redirect("/") return # Check the login information login = None try: login = User.login(username, passwd) except IncorrectEmailError: msg = "Unknown user" except IncorrectPasswordError: msg = "Incorrect password" except UnverifiedEmailError: msg = "You have not verified your email address" if login: # everything good so log in self.set_current_user(username) self.redirect(nextpage) else: self.render("index.html", message=msg, level='danger')
def post(self): if r_client.get('maintenance') is not None: raise HTTPError(503, "Site is down for maintenance") username = self.get_argument("username", "").strip().lower() passwd = self.get_argument("password", "") nextpage = self.get_argument("next", None) if nextpage is None: if "auth/" not in self.request.headers['Referer']: nextpage = self.request.headers['Referer'] else: nextpage = "/" msg = "" # check the user level try: if User(username).level == "unverified": # email not verified so dont log in msg = "Email not verified" except QiitaDBUnknownIDError: msg = "Unknown user" except RuntimeError: # means DB not available, so set maintenance mode and failover r_client.set("maintenance", "Database connection unavailable, " "please try again later.") self.redirect("/") return # Check the login information login = None try: login = User.login(username, passwd) except IncorrectEmailError: msg = "Unknown user" except IncorrectPasswordError: msg = "Incorrect password" except UnverifiedEmailError: msg = "You have not verified your email address" if login: # everything good so log in self.set_current_user(username) self.redirect(nextpage) else: self.render("index.html", message=msg, level='danger')
def test_login_invalid_password(self): with self.assertRaises(IncorrectPasswordError): User.login("*****@*****.**", "SHORT")
def test_login_incorrect_password(self): with self.assertRaises(IncorrectPasswordError): User.login("*****@*****.**", "WRONGPASSWORD")
def test_login_incorrect_user(self): with self.assertRaises(IncorrectEmailError): User.login("*****@*****.**", "password")
def test_login(self): self.assertEqual(User.login("*****@*****.**", "password"), User("*****@*****.**"))