def register(): form = RegisterForm(request.form) if form.validate_on_submit(): usr = insert_user(name=form.name.data, surname=form.surname.data, email=form.email.data, password=form.password.data, dateofbirth=form.dateofbirth.data, university=form.university.data, course=form.course.data) if isinstance(usr, (int, long)): return redirect(url_for("user.register")) token = generate_confirmation_token(usr.email) confirm_url = url_for('user.confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(usr.email, subject, html) login_user(usr) flash('A confirmation email has been sent via email.', 'success') return redirect(url_for("main.home")) return render_template('user/register.html', form=form)
def resend_confirmation(): token = generate_confirmation_token(current_user.email) confirm_url = url_for('user.confirm_email', token=token, _external=True) html = render_template('user/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" send_email(current_user.email, subject, html) flash('A new confirmation email has been sent.', 'success') return redirect(url_for('user.unconfirmed'))
def resend_confirm(): token = generate_confirmation_token(current_user.email) confirm_url = url_for('confirm_email', token=token, _external=True) html = render_template('email/email_confirm.html', confirm_url=confirm_url, user_email=current_user.email) subject = "Пожалуйста, подтвердите свою электронную почту" send_email(current_user.email, subject, html) flash('Мы отправили новое письмо с подтверждением', 'success') return redirect(url_for('uncofirm'))
def user_panel_register(): if current_user.is_authenticated: return redirect(url_for('user_panel_index')) form = RegisterForm() if form.validate_on_submit(): user_check_login = user.query.filter_by(login=form.login.data).first() if user_check_login: flash( 'Такой логин уже используется в системе! Введите другой логин') return redirect(url_for('user_panel_register')) user_check_email = user.query.filter_by(email=form.email.data).first() if user_check_email: flash( 'Такой email уже используется в системе! Введите другой email') return redirect(url_for('user_panel_register')) hash_passwd = generate_password_hash(form.password.data) new_user = user(login=form.login.data, name=form.name.data, surname=form.surname.data, patronymic=form.patronymic.data, street=form.street.data, house_number=form.house_number.data, apartment_number=form.apartment_number.data, phone=form.phone.data, email=form.email.data, password=hash_passwd) db.session.add(new_user) db.session.commit() token = generate_confirmation_token(form.email.data) confirm_url = url_for('confirm_email', token=token, _external=True) html = render_template('email/email_confirm.html', confirm_url=confirm_url, user_email=user.email) subject = "Пожалуйста, подтвердите свою электронную почту" send_email('*****@*****.**', subject, html) login_user(new_user) flash('Ваш аккаунт был создан. Подтвердите Email', 'success') return redirect(url_for('uncofirm')) return render_template('UserPanel/register.html', form=form)
def forgot(): form = ForgotForm(request.form) if form.validate_on_submit(): user = User.query.filter_by( email=form.email.data).first() # TODO: use utils methods token = generate_confirmation_token(user.email) user.password_reset_token = token db.session.commit() reset_url = url_for('user.forgot_new', token=token, _external=True) html = render_template('user/reset.html', username=user.email, reset_url=reset_url) subject = "Reset your password" send_email(user.email, subject, html) flash('A password reset email has been sent via email.', 'success') return redirect(url_for("main.home")) return render_template('user/forgot.html', form=form)