def post(self): #get parameters out of the request user_username = self.request.get('username') user_password = self.request.get('password') username = valid_username(user_username) password = valid_password(user_password) params = {"username": username, "password": password} errors = {"username": "******", "password": "******"} #login is validated if username and password: user_logged_in = self.check_if_logged_in()[0] if user_logged_in: previous_url = memcache.get("current path") self.redirect(previous_url) if not user_logged_in: #if first time, set a cookie new_cookie_val = make_secure_val(username) self.response.headers.add_header('Set-Cookie', 'username = %s' % str(new_cookie_val), path = '/') u = User(username = username, password = new_cookie_val) u.put() #need to change this to url just came from if can previous_url = memcache.get("current path") self.redirect(previous_url) else: #figure out which is in error username_error = "" password_error = "" password = "" for param in params: if params[param] == False or params[param] == None: if param == 'username': username_error = errors[param] if param == 'password': password_error = errors[param] self.write_form(username_error, password_error,user_username, password)
def post(self): # get parameters out of the request user_username = self.request.get("username") user_password = self.request.get("password") user_vpassword = self.request.get("verify") user_email = self.request.get("email") username = valid_username(user_username) password = valid_password(user_password) vpassword = valid_password(user_vpassword) email = valid_email(user_email) match = password == vpassword params = {"username": username, "password": password, "vpassword": match, "email": email} errors = { "username": "******", "password": "******", "vpassword": "******", "email": "That is not a valid email address.", } been_here = visit_cookie_str = self.request.cookies.get("username") users = db.GqlQuery("SELECT * from User") error_flag = False for user in users: if user.username == username: params["username"] = False errors["username"] = "******" error_flag = True if not error_flag and username and password: # log them in if not self.check_if_logged_in()[0]: self.log_in_user(username) # sore user and redirect them to main page new_cookie_val = make_secure_val(username) u = User(username=username, password=new_cookie_val) u.put() self.redirect("/") else: # figure out which is in error username_error = "" password_error = "" matchpw_error = "" email_error = "" password = "" vpassword = "" for param in params: if params[param] == False or params[param] == None: if param == "username": username_error = errors[param] if param == "password": password_error = errors[param] if param == "vpassword": matchpw_error = errors[param] if param == "email": email_error = errors[param] self.write_form( username_error, password_error, matchpw_error, email_error, user_username, password, vpassword, user_email, )