def register_user(): # pylint: disable=unused-argument """Register user via external services in the database :return: redirect to index or Bad request """ name = session["name"] email = session["email"] login = session["login"] form = RegisterForm() if form.validate_on_submit(): email = form.email.data name = form.name.data password = form.password.data resp_id = add_user(email, name, login, password, True) if resp_id is not None: return create_token(email, "main.home") return "Bad request", 400 form.name.data = name form.email.data = "" if email == "Empty" else email return render_template("register.html", form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): email = form.email.data password = form.password.data new_user = User(email=email, password=generate_password_hash(password, method='sha256')) db.session.add(new_user) db.session.commit() return redirect(url_for('auth.login')) return render_template('auth/register.html', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = RegisterForm() if form.validate_on_submit(): name = form.name.data email = form.email.data.lower() username = form.username.data password = form.password.data user = User(name=name, email=email, username=username) user.set_password(password) db.session.add(user) db.session.commit() token = generate_token(user=user, operation='confirm') send_confirm_email(user=user, token=token) flash('Confirm email sent, check your inbox.', 'info') return redirect(url_for('.login')) return render_template('auth/register.html', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for("dashboard")) form = RegisterForm() errors = {} if form.validate_on_submit(): if not form.validate_email(form.email): errors["email"] = True if not form.validate_username(form.username): errors["username"] = True if errors: return render_template("pages/register.html", error_email=errors["email"], error_username=errors["username"], form=form, page_title="Inscrever-se no Twitter") user = User( form.name.data, form.username.data, form.email.data, form.password.data, form.birth_date.data, local_timezone.localize(datetime.now()), ) db.session.add(user) db.session.commit() return redirect(url_for("login", success=True)) else: return render_template("pages/register.html", form=form, page_title="Inscrever-se no Twitter")
def home(): """root endpoint in application :return: redirect to index html or say that user is logged """ current_user = get_jwt_identity() if current_user is not None: return render_template("login.html", name=current_user) form = RegisterForm() if form.validate_on_submit(): email = form.email.data name = form.name.data password = form.password.data if send_confirmation_email(email, name): flash("Email send", "success") resp_id = add_user(email, name, "", password, False) if resp_id is not None: return redirect(url_for("main.home")) return "Bad request", 400 return render_template("index.html", form=form)
def signup(): form = RegisterForm() if form.validate_on_submit(): email = request.form.get('email') name = request.form.get('username') password = request.form.get('password') user = User.query.filter_by(email=email).first() # if this returns a user, then the email already exists in database if user: # if a user is found, we want to redirect back to signup page so user can try again flash('Email address already exists') return redirect(url_for('auth.signup')) # create new user with the form data. Hash the password so plaintext version isn't saved. new_user = User(email=email, name=name, password=generate_password_hash(password, method='sha256')) # add the new user to the database db.session.add(new_user) db.session.commit() return redirect(url_for('auth.login')) return render_template('signup.html', form=form)