def reset(): print(request.json['email']) email = request.json['email'].lower() user = User() user.get_user_with_email(email) if user: subject = "Password Reset Requested" token = ts.dumps(email, salt='recover-password') recover_url = url_for( 'reset_password', token=token, _external=True) html = render_template( 'email/recover.html', recover_url=recover_url) emails=[] emails.append(email) msg = Message(subject, sender=ADMINS[0], recipients=emails) msg.html = html with app.app_context(): mail.send(msg) return 'success' return 'error'
def confirm_email(token): try: email = ts.loads(token, salt="email-confirm-key", max_age=86400) except: abort(404) user = User() if user.get_user_with_email(email): user.email_confirmed() login_user(user, remember=True) return redirect('/profile') return redirect(url_for('login'))
def reset_password(token): try: email = ts.loads(token, salt='recover-password', max_age=86400) except: abort(404) form=passwordForm() if form.validate_on_submit(): user = User() if user.get_user_with_email(email): user.reset_password() login_user(user, remember=True) return redirect('/profile') return redirect(url_for('login'))
def login(): form = loginForm() email_form = emailForm() if form.validate_on_submit(): email = request.form.get('email').lower() userLog = User() user = userLog.get_user_with_email(email) if user and userLog.check_password(form.color.data) and user.is_active: login_user(user, remember=True) print("logged in"); return redirect('/profile') return redirect(url_for('login')) return render_template('login.html', form=form, email_form=email_form, colors=colors);