def post(self): username = self.get_argument("username", None) email = self.get_argument("email", "").lower() password = self.get_argument("password", None) repeat_password = self.get_argument("repeat_password", None) if not (username and email and password and repeat_password): self.flash('Please fill the require fields', 'error') self.redirect(u"/account/signup") return if password != repeat_password: self.flash("Password doesn't match", 'error') self.redirect(u"/account/signup") return if username and not username_validator.match(username): self.flash('Username is invalid', 'error') self.redirect(u"/account/signup") return if email and not email_validator.match(email): self.flash('Not a valid email address', 'error') self.redirect(u"/account/signup") if username and self.db.user.find_one({'username': username}): self.flash('This username is already registered', 'error') self.redirect(u"/account/signup") return if email and self.db.user.find_one({'email' : email}): self.flash('This email is already registered', 'error') self.redirect(u"/account/signup") return hashed_password = encrypt_password(password) uid = self.db.auto_inc.find_and_modify( update={"$inc":{"user_id":1}}, query={"name":"user_id"}, new=True ).get("user_id") user = { "username": username, "password": hashed_password, "email": email, "registered_time": time.time(), "uid": uid, 'role': 1, "description": "", "website": "", "last_accesse_time": time.time(), } if self.db.user.save(user): self.flash("注册成功,可以登入了", "info") self.redirect(u"/account/signin")
def post(self): old_password = self.get_argument('old_password', None) new_password = self.get_argument('new_password', None) repeat_password = self.get_argument('repeat_password', None) user = self.db.user.find_one({'username': self.get_current_user()}) if not (old_password and new_password and repeat_password): self.flash('你至少得输入点东西吧,混蛋', 'error') self.redirect('/account/password') if new_password != repeat_password: self.flash('新密码和重复密码不一样,仔细再修改一次吧!', 'error') self.redirect('/account/password') if not validate_password(str(user['password']), old_password): self.flash('输入的旧密码不正确,请在多次几次', 'error') self.redirect('/account/password') self.db.user.update( {"username": self.get_current_user()}, {"$set": {"password": encrypt_password(new_password)}}) self.flash('密码修改完成, 请重新登陆', 'info') self.redirect('/account/signout')
def post(self): old_password = self.get_argument("old_password", None) new_password = self.get_argument("new_password", None) repeat_password = self.get_argument("repeat_password", None) user = self.db.user.find_one({"username": self.get_current_user()}) if not (old_password and new_password and repeat_password): self.flash("你至少得输入点东西吧,混蛋", "error") self.redirect("/account/password") if new_password != repeat_password: self.flash("新密码和重复密码不一样,仔细再修改一次吧!", "error") self.redirect("/account/password") if not validate_password(str(user["password"]), old_password): self.flash("输入的旧密码不正确,请在多次几次", "error") self.redirect("/account/password") self.db.user.update( {"username": self.get_current_user()}, {"$set": {"password": encrypt_password(new_password)}} ) self.flash("密码修改完成, 请重新登陆", "info") self.redirect("/account/signout")