Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

70 lines (64 sloc) 2.888 kB
# Copyright 2012 Hai Thanh Nguyen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from webapp2_extras.i18n import _
from requesthandler import RequestHandler
import user
class LoginHandler(RequestHandler):
def get(self):
render_notice = lambda values: self.render("noticepage", values)
successful = self.request.get("successful", None)
if successful == "1":
values = {
"message": _("You successfully signed in, welcome back!"),
"redirect": self.request.get("referer"),
}
return render_notice(values)
elif successful == "0":
values = {
"message": _("Login failed, invalid password or user doesn't exist, you could try again."),
"redirect": self.uri_for("login"),
}
return render_notice(values)
elif successful == "-1":
values = {
"message": _("The user is valid but not verified,\
check your email to find the confirmation link\
we sent to you when you registered."),
"redirect": None,
}
return render_notice(values)
else:
if self.get_current_user() != None:
values = {
"message": _("You've logged in, why do you want to do this again?"),
"redirect": self.uri_for("home"),
}
return render_notice(values)
else:
values = { "referer": self.request.headers.get("Referer", self.uri_for("home")) }
self.render("loginpage", values)
def post(self):
username = self.request.get("username")
password = self.request.get("password")
referer = self.request.get("referer")
model = user.UserModel(username=username, password=password)
login = model.login()
if login == 1:
user.save_cookie(self, model.key)
return self.redirect(self.uri_for("login")+"?successful=%s&referer=%s" % (str(login), referer))
class LogoutHandler(RequestHandler):
def post(self):
self.response.delete_cookie("_")
self.session["username"] = None
return self.redirect(self.uri_for("home"))
Jump to Line
Something went wrong with that request. Please try again.