def login(response, context): #logout(response) page = response.get_field("page") if not page: page = "/" username = response.get_field("username") password = response.get_field("password") if User.exists(username): user = User.get(username) context["firstname"] = user.get_first_name() context["user"] = username context["css"] = "login" if user.password_correct(password): message = "username: "******" password: "******"output"] = message response.set_cookie("User",username) response.redirect(page) else: message = "Wrong Password" firstname = user.get_first_name() context["output"] = message else: message = "User does not exist" context["output"] = message response.redirect(page)
def signup(response): username = response.get_field("username") firstname = response.get_field("firstname") lastname = response.get_field("lastname") email = response.get_field("email") password = response.get_field("password") school = response.get_field("school") print username if username and email and firstname and lastname and password and not User.exists( username): newUser = { "username": username, "firstname": firstname, "lastname": lastname, "email": email, "password": password, "school": school } User.add(newUser) print " I am here" x = User.get(username) print x # we're going to be hacky, and manually set a cookie, which shouldn't happen - # but we want to prevent the user from being redirected to the login page, straight # after signing up. response.set_cookie("User", username) response.redirect("/profile/" + username) else: #response.write(SIGNUP) title = "Sign Up" context = {"title": title, "css": "signup", "user": None} template.render_template("templates/signup.html", context, response)
def signup(response): username = response.get_field("username") firstname = response.get_field("firstname") lastname = response.get_field("lastname") email = response.get_field("email") password = response.get_field("password") school = response.get_field("school") print username if username and email and firstname and lastname and password and not User.exists(username): newUser = {"username": username, "firstname":firstname,"lastname":lastname,"email":email,"password":password,"school":school} User.add(newUser) print " I am here" x = User.get(username) print x # we're going to be hacky, and manually set a cookie, which shouldn't happen - # but we want to prevent the user from being redirected to the login page, straight # after signing up. response.set_cookie("User", username) response.redirect("/profile/" + username) else: #response.write(SIGNUP) title = "Sign Up" context = {"title":title, "css":"signup", "user":None} template.render_template("templates/signup.html", context, response)