def post(self): new_email = self.request.get("email") new_verify_email = self.request.get("verify_email") a_password = self.request.get("password") the_RU = check_user_id_cookie(self.request) if the_RU: if len(new_email) > 0: is_valid_email = passwordValid.valid_email(new_email) else: is_valid_email = False does_email_match = passwordValid.email_match(new_email, new_verify_email) is_password_correct = passwordValid.valid_pw(the_RU.name, a_password, the_RU.password_hashed) final_password_error = "" final_email_error = "" final_verify_email_error = "" if not (is_valid_email): final_email_error = "Invalid e-mail" if not (does_email_match): final_verify_email_error = "E-mail doesn't match" if not (is_password_correct): final_password_error = "Invalid password" if is_valid_email and does_email_match and is_password_correct: the_RU.email = new_email the_RU.put() time.sleep(0.1) # to delay so db table gets displayed correct self.render( "profile.html", a_name=the_RU.name, an_email=new_email, changed_message="Your e-mail has been changed", ) else: self.render( "editEmail.html", a_name=the_RU.name, email=new_email, email_error=final_email_error, email_verify=new_verify_email, verify_email_error=final_verify_email_error, password_error=final_password_error, ) else: # either user_id_cookie_value, username, or the_RU is None (see check_user_id_cookie()) self.redirect("/logout")
def post(self): new_email = self.request.get("email") new_verify_email = self.request.get("verify_email") a_password = self.request.get("password") the_RU = check_user_id_cookie(self.request) if the_RU: if len(new_email) > 0: is_valid_email = passwordValid.valid_email(new_email) else: is_valid_email = False does_email_match = passwordValid.email_match( new_email, new_verify_email) is_password_correct = passwordValid.valid_pw( the_RU.name, a_password, the_RU.password_hashed) final_password_error = "" final_email_error = "" final_verify_email_error = "" if not (is_valid_email): final_email_error = "Invalid e-mail" if not (does_email_match): final_verify_email_error = "E-mail doesn't match" if not (is_password_correct): final_password_error = "Invalid password" if is_valid_email and does_email_match and is_password_correct: the_RU.email = new_email the_RU.put() time.sleep(0.1) # to delay so db table gets displayed correct self.render("profile.html", a_name=the_RU.name, an_email=new_email, changed_message="Your e-mail has been changed") else: self.render("editEmail.html", a_name=the_RU.name, email=new_email, email_error=final_email_error, email_verify=new_verify_email, verify_email_error=final_verify_email_error, password_error=final_password_error) else: # either user_id_cookie_value, username, or the_RU is None (see check_user_id_cookie()) self.redirect("/logout")
def post(self): login_username_input = self.request.get('login_username') login_password_input = self.request.get('login_password') checkbox_stay_loggedIn = self.request.get('stay_logged_in') #check if username exists user_already_exists = False all_reg_users = db.GqlQuery( "SELECT * FROM RegisteredUsers ORDER BY created DESC") if all_reg_users: for users in all_reg_users: if users.name == login_username_input: user_already_exists = True the_user_hash = users.password_hashed break if user_already_exists: #check if password is correct if passwordValid.valid_pw(login_username_input, login_password_input, the_user_hash): secure_username = passwordValid.make_secure_val( login_username_input ) # return login_username_input|hash if checkbox_stay_loggedIn: # make sure to set cookie expire to never #logging.debug("checkbox_stay_loggedIn") self.response.headers.add_header( 'Set-Cookie', 'user_id=%s; Path=/; expires=Fri, 31-Dec-9999 10:05:41 GMT;' % str(secure_username)) else: # cookie expire when??? #logging.debug("NOT checkbox_stay_loggedIn") self.response.headers.add_header( 'Set-Cookie', 'user_id=%s; Path=/' % str(secure_username)) self.redirect("/frontpage") else: self.loginError(login_username_input) else: if login_username_input: self.loginError(login_username_input) else: self.loginError("") else: self.loginError("")
def post(self): new_password = self.request.get("new_password") new_verify_password = self.request.get("verify_new_password") a_password = self.request.get("old_password") the_RU = check_user_id_cookie(self.request) if the_RU: is_valid_new_password = passwordValid.valid_password(new_password) does_new_passwords_match = passwordValid.password_match(new_password, new_verify_password) is_password_correct = passwordValid.valid_pw(the_RU.name, a_password, the_RU.password_hashed) final_new_password_error = "" final_new_verify_password_error = "" final_old_password_error = "" if not (is_valid_new_password): final_new_password_error = "Invalid password" if not (does_new_passwords_match): final_new_verify_password_error = "Password doesn't match" if not (is_password_correct): final_old_password_error = "Invalid password" if is_valid_new_password and does_new_passwords_match and is_password_correct: the_RU.password_hashed = passwordValid.make_pw_hash( the_RU.name, new_password ) # the function returns hash|salt the_RU.put() time.sleep(0.1) # to delay so db table gets displayed correct self.render( "profile.html", a_name=the_RU.name, an_email=the_RU.email, changed_message="Your password has been changed", ) else: self.render( "editPassword.html", a_name=the_RU.name, new_password_error=final_new_password_error, verify_error=final_new_verify_password_error, password_error=final_old_password_error, ) else: # either user_id_cookie_value, username, or the_RU is None (see check_user_id_cookie()) self.redirect("/logout")
def post(self): new_password = self.request.get("new_password") new_verify_password = self.request.get("verify_new_password") a_password = self.request.get("old_password") the_RU = check_user_id_cookie(self.request) if the_RU: is_valid_new_password = passwordValid.valid_password(new_password) does_new_passwords_match = passwordValid.password_match( new_password, new_verify_password) is_password_correct = passwordValid.valid_pw( the_RU.name, a_password, the_RU.password_hashed) final_new_password_error = "" final_new_verify_password_error = "" final_old_password_error = "" if not (is_valid_new_password): final_new_password_error = "Invalid password" if not (does_new_passwords_match): final_new_verify_password_error = "Password doesn't match" if not (is_password_correct): final_old_password_error = "Invalid password" if is_valid_new_password and does_new_passwords_match and is_password_correct: the_RU.password_hashed = passwordValid.make_pw_hash( the_RU.name, new_password) # the function returns hash|salt the_RU.put() time.sleep(0.1) # to delay so db table gets displayed correct self.render("profile.html", a_name=the_RU.name, an_email=the_RU.email, changed_message="Your password has been changed") else: self.render("editPassword.html", a_name=the_RU.name, new_password_error=final_new_password_error, verify_error=final_new_verify_password_error, password_error=final_old_password_error) else: # either user_id_cookie_value, username, or the_RU is None (see check_user_id_cookie()) self.redirect("/logout")
def post(self): login_username_input = self.request.get("login_username") login_password_input = self.request.get("login_password") checkbox_stay_loggedIn = self.request.get("stay_logged_in") # check if username exists user_already_exists = False all_reg_users = db.GqlQuery("SELECT * FROM RegisteredUsers ORDER BY created DESC") if all_reg_users: for users in all_reg_users: if users.name == login_username_input: user_already_exists = True the_user_hash = users.password_hashed break if user_already_exists: # check if password is correct if passwordValid.valid_pw(login_username_input, login_password_input, the_user_hash): secure_username = passwordValid.make_secure_val( login_username_input ) # return login_username_input|hash if checkbox_stay_loggedIn: # make sure to set cookie expire to never # logging.debug("checkbox_stay_loggedIn") self.response.headers.add_header( "Set-Cookie", "user_id=%s; Path=/; expires=Fri, 31-Dec-9999 10:05:41 GMT;" % str(secure_username), ) else: # cookie expire when??? # logging.debug("NOT checkbox_stay_loggedIn") self.response.headers.add_header("Set-Cookie", "user_id=%s; Path=/" % str(secure_username)) self.redirect("/frontpage") else: self.loginError(login_username_input) else: if login_username_input: self.loginError(login_username_input) else: self.loginError("") else: self.loginError("")