def register(): if request.method == "POST": user_name = request.form.get("username") if not re.match(r"[^@]+@[^@]+\.[^@]+", user_name): return render_template("register.html", error="Invalid email address!") password = request.form.get("password") password2 = request.form.get("password2") if password != password2: return render_template("register.html", error="Password Confirmation Error!") if not validate_password(password): return render_template( "register.html", error="Password length should be between 8 and 30 characters.") next_page = request.form.get("next_page", url_for("home")) captcha_response = request.form.get("g-recaptcha-response") if not validate_captcha(captcha_response): return render_template("register.html", error="Recaptcha Fail") if is_abuse_check(request.remote_addr, prefix="register", threshold=10): return render_template("register.html", error="Abuse detected by your IP address.") try: User.add_user(email=user_name, password=password) except Exception as ex: logger.exception(ex) return render_template("register.html", error="Register Fail!") user = web_login(user_name, password) if not user: return render_template("register.html", error="Register Fail!") flash('Check your email to activate account.') return redirect(next_page) else: return render_template("register.html", error=None)
def test_user(self): User.add_user("*****@*****.**", "any") our_item = self.session.query(User).filter_by( email='*****@*****.**').first() usr = UserCH(our_item.id) self.assertEqual(usr.email, "*****@*****.**") self.assertEqual( cache.get_object("cached/{}/{}".format(usr.db_table, usr.id)), usr._data)