def test_invalid_confirmation_token(self): user1 = User(email='*****@*****.**', password='******', confirmed=False) user2 = User(email='*****@*****.**', password='******', confirmed=False) db.session.add(user1) db.session.add(user2) db.session.commit() token = generate_confirmation_token('*****@*****.**') confirm_token(token) self.assertFalse(user1.confirmed)
def reset_password(token): mailbox = confirm_token(token) os_mailuser = opalstack.get_mailuser(mailbox) if mailbox else None if not mailbox or os_mailuser is None: flash( 'Invalid token. Possibly expired. Request a new password-reset token.', 'danger') return redirect(url_for('main.home')) form = PasswordResetForm(request.form) if form.validate_on_submit(): success = opalstack.change_password(os_mailuser, form.password.data) if success: flash('Password successfully changed.', 'success') return redirect(url_for('main.reset_password_success')) else: flash( 'Password change was unsuccessful. Probably invaild. Try again.', 'danger') else: flash('You can now change your password.', 'success') return render_template('main/reset_passwod.html', form=form)
def forgot_new(token): email = confirm_token(token) user = User.query.filter_by(email=email).first_or_404() if user.password_reset_token is not None: form = ChangePasswordForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(email=email).first() if user: user.password = bcrypt.generate_password_hash(form.password.data) user.password_reset_token = None db.session.commit() login_user(user) flash('Password successfully changed.', 'success') return redirect(url_for('user.profile')) else: flash('Password change was unsuccessful.', 'danger') return redirect(url_for('user.profile')) else: flash('You can now change your password.', 'success') return render_template('user/forgot_new.html', form=form) else: flash('Can not reset the password, try again.', 'danger') return redirect(url_for('main.home'))
def confirm_email(token): try: email = confirm_token(token) except: flash('The confirmation link is invalid or has expired.', 'danger') user = User.query.filter_by(email=email).first_or_404() if user.confirmed: flash('Account already confirmed. Please login.', 'success') else: user.confirmed = True user.confirmed_on = datetime.datetime.now() db.session.add(user) db.session.commit() flash('You have confirmed your account. Thanks!', 'success') ################################################################################# ## This wold be a good place to implement the user's blockchain creds initiation. ## ## Required functions from Algorand SDK. ## handle = kcl.init_wallet_handle(wallet_id, wallet_pswd) ## private_key_1, address_1 = account.generate_account() ## ## ################################################################################# return redirect(url_for('main.home'))
def test_confirm_token_route_expired_token(self): # Ensure user cannot confirm account with expired token. user = User(email='*****@*****.**', password='******', confirmed=False) db.session.add(user) db.session.commit() token = generate_confirmation_token('*****@*****.**') self.assertFalse(confirm_token(token, -1))
def forgot_new(token): email = confirm_token(token) user = User.query.filter_by(email=email).first_or_404() if user.password_reset_token is not None: form = ResetPasswordForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(email=email).first() if user: user.set_password(form.password.data) user.password_reset_token = None db.session.commit() login_user(user) flash('Passwort wurde erfolgreich geändert.', 'success') return redirect(url_for('auth.login')) else: flash('Passwort konnte nicht geändert werden.', 'danger') return redirect(url_for('auth.login')) else: flash('Du kannst dein Passwort jetzt ändern.', 'success') return render_template('auth/forgot_new.html', form=form) else: flash( 'Das Passwort konnte nicht zurückgesetzt werden. Bitte erneut versuchen.', 'danger') return redirect(url_for('main.index'))
def forgot_new(token): email = confirm_token(token) user = User.query.filter_by(email=email).first_or_404() if user.password_reset_token is not None: form = ChangePasswordForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(email=email).first() if user: user.password = bcrypt.generate_password_hash( form.password.data) user.password_reset_token = None db.session.commit() login_user(user) flash('Password successfully changed.', 'success') return redirect(url_for('user.profile')) else: flash('Password change was unsuccessful.', 'danger') return redirect(url_for('user.profile')) else: flash('You can now change your password.', 'success') return render_template('user/forgot_new.html', form=form) else: flash('Can not reset the password, try again.', 'danger') return redirect(url_for('main.home'))
def confirm_email(token): try: email=confirm_token(token) except: flash("The confirmation link is invalid or expired",'danger') user=User.query.filter_by(email=email).first_or_404() if user.confirmed: flash("Account already confirmed",'success') else: user.confirmed=True user.confirmed_on=datetime.datetime.now() db.session.add(user) db.session.commit() flash("You have confirmed your account. Thanks!",'success') return redirect(url_for('auth.browse_missions'))
def confirm_email(token): try: email = confirm_token(token) except: flash('The confirmation link is invalid or has expired.', 'danger') user = User.query.filter_by(email=email).first_or_404() if user.confirmed: flash('Account already confirmed. Please login.', 'success') else: user.confirmed = True user.confirmed_on = datetime.datetime.now() db.session.add(user) db.session.commit() flash('You have confirmed your account. Thanks!', 'success') return redirect(url_for('home.home'))
def confirm_email(token): if current_user.confirmed: flash('Account already confirmed. Please login.', 'success') return redirect(url_for('main.home')) email = confirm_token(token) user = User.query.filter_by(email=current_user.email).first_or_404() if user.email == email: user.confirmed = True user.confirmed_on = datetime.datetime.now() db.session.add(user) db.session.commit() flash('You have confirmed your account. Thanks!', 'success') else: flash('The confirmation link is invalid or has expired.', 'danger') return redirect(url_for('main.home'))
def confirm_email(token): if current_user.confirmed: flash('Das Konto wurde bereits bestätigt. Bitte anmelden.', 'success') return redirect(url_for('main.index')) email = confirm_token(token) user = User.query.filter_by(email=current_user.email).first_or_404() if user.email == email: user.confirmed = True user.confirmed_on = datetime.utcnow() db.session.add(user) db.session.commit() flash('Du hast dein Konto bestätigt. Vielen Dank!', 'success') else: flash('Der Bestätigungslink ist nicht gültig oder abgelaufen.', 'danger') return redirect(url_for('main.index'))
def confirm_email(token): try: email = confirm_token(token) except: flash('The confirmation link is invalid or has expired.', 'danger') user = User.query.filter_by(email=email).first_or_404() if user.confirmed: flash(u'تم تأكيد الحساب بالفعل. الرجاء تسجيل الدخول', 'success') else: user.confirmed = True user.activate = True user.confirmed_on = datetime.datetime.now() db.session.add(user) db.session.commit() flash(u'لقد قمت بتأكيد حسابك. شكر!', 'success') return redirect(url_for('main.home'))
def newpassword_post(token): password=request.form.get('password') confirm_password=request.form.get('confirm_password') print("Password is "+password) print("Confirmed password is "+confirm_password) email=confirm_token(token) user=User.query.filter_by(email=email).first() if password==confirm_password: user.password=generate_password_hash(password) db.session.add(user) db.session.commit() flash('Password has been successfully reset','success') else: flash('Make sure confirm password and password are same','danger') return render_template('newpassword.html') return redirect(url_for('auth.index'))
def confirm_email(token): try: email = confirm_token(token) except: flash('El enlace de confirmación no es válido o ha caducado.', 'danger') con = engine.connect() init_session(con, email) if session['confirmed']: flash('Cuenta ya confirmada. Por favor Iniciar sesión.', 'success') else: confirm_user = text("""UPDATE public.usuario SET confirmado=TRUE , fecha_confirmado=now() WHERE usuario_id=:id""") con.execute(confirm_user, id=session['id']) session['confirmed'] = True flash('Has confirmado tu cuenta. ¡Gracias!', 'success') con.close() return redirect(url_for('user.perfil'))
def confirm_email(token): print "confirm email" try: email = confirm_token(token) print "email is" + email except: print "confirm failed" flash('The confirmation link is invalid or has expired', 'danger') user = User.query.filter_by(email=email).first_or_404() print "user" , user if user.confirmed: flash('Account already confirmed. Please login.', 'success') else: user.confirmed = True user.confirmed_on = datetime.datetime.now() db.session.add(user) db.session.commit() flash('You have confirmed your account. Thanks!', 'success') return redirect(url_for('main.home'))
def confirm_email(token): response_object = { 'status': 'success', 'message': 'Successfully logged out.' } try: email = confirm_token(token) except: response_object[ 'message'] = 'The confirmation link is invalid or has expired.', 'danger' user = Users.query.filter_by(email=email).first_or_404() if user.confirmed: response_object[ 'message'] = 'Account already confirmed. Please login.', 'success' return jsonify(response_object), 200 else: user.confirmed = True user.confirmed_on = datetime.datetime.now() db.session.add(user) db.session.commit() response_object['message'] = 'Account confirmed' return jsonify(response_object), 201