def post(self): user = User.get_by_id(self.getUser()) if "updatePassword" in self.request.POST: password_success, password_error = "", "" if validation.valid_pw(user.username, self.request.get('currentPassword'), user.passHash): new_pass = self.request.get('new_password') if new_pass == self.request.get('verifyNewPassword'): user.passHash = validation.make_pw_hash( user.username, new_pass) user.put() password_success = "Password Changed Successfully!" else: password_error = "New passwords are not the same" else: password_error = "That is not your current password" self.render('admin.html', user=user, update_error=password_error, update_success=password_success) elif "otherChanges" in self.request.POST: user_email = self.request.get('email') venmo_email = self.request.get('venmo_email') email = validation.edu_email(user_email) venmo_email_verify = validation.email(venmo_email) email_error, venmo_email_error, update_success, update_error = "", "", "", "" if not email: email_error = "That's not a valid email." user_email = "" if venmo_email != "" and venmo_email_verify is None: venmo_email_error = "Invalid email. This is an optional field." venmo_email = "" if email and (venmo_email_error == ""): try: user.email = user_email user.venmo_email = venmo_email user.bio = self.request.get('bio') user.put() update_success = "Succesfully Updated!" except: update_error = "Could not save changes :(" self.render('admin.html', user=user, update_success=update_success, update_error=update_error, email_error=email_error, venmo_email_error=venmo_email_error)
def post(self): user_username = self.request.get('username') user_password = self.request.get('password') user_verify = self.request.get('verify') user_email = self.request.get('email') venmo_email = self.request.get('venmo_email') bio = self.request.get('bio') username = validation.username(user_username) password = validation.password(user_password) verify = validation.verify(user_verify, user_password) email = validation.edu_email(user_email) venmo_email_verify = validation.email(venmo_email) userError="" passError="" verifyError="" emailError="" venmoEmailError = "" if not username: userError = "That's not a valid username." user_username="" if not password: passError = "That wasn't a valid password." if not verify: verifyError = "Your passwords didn't match." if not email: emailError = "That's not a valid email." user_email="" if venmo_email != "" and venmo_email_verify is None: venmoEmailError = "That's not a valid email. Leave empty if you don't have one" venmo_email="" if username and password and verify and email and (venmoEmailError == ""): passHash = validation.make_pw_hash(username, password) code = validation.make_salt() user = User(username = username, passHash=passHash, email=email, bio=bio, venmo_email=venmo_email, activationCode=code) u = User.all().filter('username ='******'Content-Type'] = 'text/plain' cookie_val = validation.make_secure_val(str(user_id)) self.response.headers.add_header('Set-Cookie',str('user=%s; Path=/' % cookie_val)) self.sendActivationEmail(email, code) self.redirect("/home") else: self.write_form(userError, passError, verifyError, emailError, venmoEmailError, user_username, user_email, bio=bio)
def post(self): if "recoverUsername" in self.request.POST: try: email = self.request.get('email') self.recoverUsernameUsingEmail(email) self.render('recover.html', color="green", status="Sent recovery email to %s :)" % (email)) except: self.render('recover.html', color="red", status="Could not send email to %s :(" % (email)) elif "recoverPassword" in self.request.POST: try: username = self.request.get('username') email = "" user = None if username: print username user = User.gql("WHERE username=:username", username=username).get() email = user.email else: email = self.request.get('email') user = User.gql("WHERE email=:email", email=email).get() salt = validation.make_salt(25) link = "http://%s/recover?userID=%s&code=%s" % (self.request.host, user.key().id(), salt) user.recoveryCode = salt user.put() self.sendPasswordRecoveryEmail(email, user, link) self.render('recover.html', color="green", status="Sent recovery email to a %s account :)" % (email.split("@")[1])) except: self.render('recover.html', color="red", status="Could not send email :(") elif "resetPassword" in self.request.POST: userID = self.request.get('userID') user = User.get_by_id(int(userID)) newPass = self.request.get('newPassword') passwordSuccess, passwordError = "", "" if newPass == self.request.get('verifyNewPassword'): user.passHash = validation.make_pw_hash(user.username, newPass) user.recoveryCode = None user.put() passwordSuccess = "Password Changed Successfully!" self.render('recover.html', color="green", status=passwordSuccess) else: passwordError = "New passwords are not the same" self.render('recover.html', color="red", status=passwordError, recover=True, userID=userID)