Exemple #1
0
def verification_email_request(subdomain='www'):
    if current_user.is_authenticated:
        if not (current_user.verified == 0 or current_user.verified is None):
            flash('Your account is already verified', 'success')
            return redirect(url_for("main.index", subdomain=subdomain))
        else:
            send_verification_email(current_user)
            flash("An email with instructions was sent to your address.",
                  "success")
            return redirect(url_for("auth.verify_account",
                                    subdomain=subdomain))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            if user.verified == 0 or user.verified is None:
                send_verification_email(user)
                flash("An email with instructions was sent to your address.",
                      "success")
            else:
                flash("Your account is already verified", "success")
        else:
            flash(
                "The email address is incorrect, use a valid email account or create an account.",
                "danger")
        return redirect(url_for("auth.login", subdomain=subdomain))
    return render_template("auth/send_email_verification.html",
                           subdomain=subdomain,
                           title="Request email verification token",
                           form=form)
Exemple #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    # so at this point we need to check if we have
    # a clean installation, just ask for admin
    # credentials
    if User.query.count() == 0:  # no users available
        form = AdminPasswordForm()
        if form.validate_on_submit():
            user = User(username='******', email='')
            user.set_password(form.password.data)
            user.first_name = 'System'
            user.last_name = 'Administrator'
            user.is_active = True
            user.administrator = True
            db.session.add(user)

            #user = User.query.get(1)
            #user.set_password(form.password.data)

            db.session.commit()

            flash('Password for the administrator account is now set!')
            return redirect(url_for('auth.login'))

        flash('No users in database! Enter an administrator password!')
        return render_template('auth/admin_password.html',
                               title='Set Administrator Password',
                               form=form)
    else:
        # proceed with the normal login procedure
        form = LoginForm()

        if form.validate_on_submit():
            user = User.query.filter_by(username=form.username.data).first()
            if user is None or not user.check_password(form.password.data):
                flash('Invalid username or password')
                msg = 'Invalid username or password (username={})'.format(
                    form.username.data)
                current_app.logger.info(msg)
                return redirect(url_for('auth.login'))
            if login_user(user, remember=form.remember_me.data):
                msg = 'User \'{}\' logged in!'.format(user.username)
                current_app.logger.info(msg)
                next_page = request.args.get('next')
                if not next_page or url_parse(next_page).netloc != '':
                    next_page = url_for('main.index')
                return redirect(next_page)
            else:
                msg = 'User account is not active!'
                flash(msg)
                current_app.logger.info(msg)
                return redirect(url_for('auth.login'))
        return render_template('auth/login.html',
                               title='Sign In',
                               form=form,
                               rform=RegistrationForm(),
                               pform=ResetPasswordRequestForm(),
                               mode='login')
Exemple #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    rform = RegistrationForm()
    if rform.validate_on_submit():
        user = User(username=rform.username.data,
                    email=rform.email.data,
                    first_name=rform.first_name.data,
                    last_name=rform.last_name.data)
        user.set_password(rform.password.data)
        db.session.add(user)
        db.session.commit()
        send_email_verify_email(user)
        flash(
            'Congratulations, you are now a registered user! An email was sent for confirmation!'
        )
        return redirect(url_for('auth.login'))

    # this is the case of an error!
    return render_template('auth/register.html',
                           title='Sign In',
                           form=LoginForm(),
                           rform=rform,
                           pform=ResetPasswordRequestForm(),
                           mode='signup')
def reset_password_request():
    """Request a password reset email if the password has been forgotten.
    
    Returns:
        Redirects to password reset form if form has not been submitted.
        Redirects to home page if user is already logged in.
        Redirects to login page if reset password email is successfully
            sent.
    """
    if current_user.is_authenticated:
        return redirect(url_for('coding.index'))

    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash('Check your email for the instructions to reset your password')
        return redirect(url_for('auth.login'))

    return render_template(
        'auth/reset_password_request.html',
        title='Reset Password',
        form=form,
    )
Exemple #5
0
def reset_password_request():
    """
    Page where user can request the reset of the password
    :return:
    """
    # if logged in, return to index.
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))

    # Instantiate the form object.
    form = ResetPasswordRequestForm()

    # if form validate successfully,
    if form.validate_on_submit():

        # Get user by email.
        user = User.query.filter_by(email=form.email.data).first()

        # if user EXIST, send email.
        if user:
            send_password_reset_email(user)

        # Display to inform user.
        flash("Check your email for the instruction to reset your password")

        # Redirect to login.
        return redirect(url_for("auth.login"))

    return render_template("auth/reset_password_request.html",
                           title="Reset Password",
                           form=form)
Exemple #6
0
def reset_password_request():
    if not email_configured():
        flash(
            "Sorry, self-service password resets are not currently available. Please contact an administrator for assistance.",
            "warning",
        )
        return redirect(url_for("auth.login"))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        validemail = validate_email(form.email.data)
        if not validemail:
            return redirect(url_for("auth.reset_password_request"))
        user = User.get_reset_token(validemail)
        if user:
            deliver_auth_link(user.email, user.password_reset_token, "reset")
        db.session.commit()
        flash("Check your email for the instructions to reset your password",
              "info")
        return redirect(url_for("auth.login"))
    return render_template(
        "auth/password_reset.html",
        title="Request Password Reset",
        form=form,
        pwrequest=True,
    )
def reset_password_request_receive_form():
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        account_email = form.email.data
        dest_url = 'http://' + Config.MAIL_SENDING_SERVICE_URL + '/api/reset-password/email-sending-by-account-email'
        result = requests.post(dest_url, data={'account_email': account_email})
        account_to_reset = get_api_info(result)
        return render_template('auth/email/inform_reset_email.html', account_email=account_email)
Exemple #8
0
def reset_password_request():
    """Request Password Reset endpoint."""
    if current_user.is_authenticated:
        return redirect(current_user.get_landing_page())
    form = ResetPasswordRequestForm()
    return render_template('auth/reset_password_request.html',
                           title='Reset Password',
                           form=form)
Exemple #9
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(_('Email sent, please check your inbox.'))
    return render_template('auth/reset_password_request.html', title='Reset password', form=form)
Exemple #10
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash('Controlla la tua casella email per conoscere le istruzione per il reset della password')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html', title='Reset password', form=form)
Exemple #11
0
def reset_password_request():
    if current_user.is_authenticated:  # redirect to index page if not logged in
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash('Please check your email to reset your password.')  # flash even if email is not recognized so this can't be used to figure out if someone is registered or not
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html', title='Reset Password', form=form)
Exemple #12
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash('Check your email for the instructions to reset your password')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html', title = 'Reset Password', form= form)
Exemple #13
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash('Link to reset password has been sent to the email entered.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html', title='Reset Password', form=form)
Exemple #14
0
def reset_password_request():
	if current_user.is_authenticated:
		return redirect(url_for('auth.index'))
	form=ResetPasswordRequestForm()
	if form.validate_on_submit():
		user=User.query.filter_by(email=form.email.data).first()
		if user:
			send_password_reset_email(user)
		flash('请查收邮件并根据邮件内容重置密码.')
		return redirect(url_for('auth.login'))
	return render_template('auth/reset_password_request.html',title='密码重置申请',form=form)
Exemple #15
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(_('If your email is found in the system, you will get a reset link soon.'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html.j2', title='Reset Password', form=form)
Exemple #16
0
def reset_password_request():
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
            flash('Check your email for reset instructions.', 'warning')
        else:
            flash('No user registered under that email address.', 'warning')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemple #17
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(_('请检查你的邮箱,进行重置密码操作'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('重置密码'), form=form)
Exemple #18
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user:
            flash(
                _(
                    "Check your email for the instructions "
                    "to reset your password."
                )
            )
            return redirect(url_for("auth.login"))

        confirming_value = user.get_random_base64_value()
        token = user.get_reset_password_token(confirming_value)
        now = datetime.utcnow()
        should_send_mail = False

        reset_password = ResetPassword.query.filter_by(
            user_id=user.did
        ).first()
        if reset_password:
            user.delete_expired_tokens(reset_password)
            if not reset_password.first_value:
                reset_password.first_value = confirming_value
                reset_password.first_date = now
                should_send_mail = True
            elif not reset_password.second_value:
                reset_password.second_value = confirming_value
                reset_password.second_date = now
                should_send_mail = True
            db.session.add(reset_password)
        else:
            reset_password_new = ResetPassword(
                first_value=confirming_value, first_date=now, user_id=user.did
            )
            db.session.add(reset_password_new)
            should_send_mail = True
        db.session.commit()
        if should_send_mail:
            send_password_reset_email(user, token)

        flash(
            _("Check your email for the instructions to reset your password.")
        )
        return redirect(url_for("auth.login"))
    return render_template(
        "auth/reset_password_request.html",
        title=_("Reset Password"),
        form=form,
    )
Exemple #19
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_rest_email(user)
        flash('Cek surel anda untuk mendapatkan petunjuk mengatur ulang password')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
            title='Reset Password', form=form)
Exemple #20
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:  # 用户存在
            send_password_reset_email(user)
        flash('邮件发送成功,请通过邮箱找回密码')
        return redirect(url_for('auth.login'))
    return render_template('reset_password_request.html',
                           title='Reset Password',
                           form=form)
Exemple #21
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(
            _("Jette un coup d'oeil à tes emails et suis les instructions de réinitialisation de ton mot de passe."))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Réinitialisation du mot de passe'), form=form)
Exemple #22
0
def reset_password_request():
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(
            'Veuillez vérifier votre boite mail pour savoir comment réinitialiser votre mot de passe.'
        )
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Réinitialiser votre mot de passe',
                           form=form)
Exemple #23
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(_('Проверьте свою почту и следуйте инструкциям'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Сброс пароля'),
                           form=form)
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(_('Kolla din mail för instruktioner'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Återställ lösenord'),
                           form=form)
Exemple #25
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('auth.index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('auth.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Password has changed')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemple #26
0
def RequestPaswordReset():
	if current_user.is_authenticated:
		return redirect(url_for('main.ShowIndex'))
	form = ResetPasswordRequestForm()
	if form.validate_on_submit():
		user = User.query.filter_by(email=form.email.data).first()
		if user:
			SendPasswordResetEmail(user)
			flash('The password reset email has been sent to you.')
			return redirect(url_for('auth.PerformLogin'))
		else:
			flash('The user has not been found.')
	return render_template('auth/request.html', form = form)
Exemple #27
0
def RequestPaswordReset():
	if current_user.is_authenticated:
		return redirect(url_for('main.ShowIndex'))
	form = ResetPasswordRequestForm()
	if form.validate_on_submit():
		user = User.query.filter_by(email=form.email.data).first()
		if user:
			SendPasswordResetEmail(user)
			flash('На вашу электронную почту отправлен запрос на сброс пароля.')
			return redirect(url_for('auth.PerformLogin'))
		else:
			flash('Такой пользователь не обнаружен.')
	return render_template('auth/request.html', form = form)
Exemple #28
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash('Письмо с информацией о смене пароля отправлено на почту')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Смена пароля',
                           form=form)
Exemple #29
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        _user = User.query.filter_by(email=form.email.data).first()
        if _user:
            send_password_reset_email(_user)
        flash("if ur legit, you'll receive a reset link in your inbox")
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_pw_request.html',
                           title='reset password',
                           form=form)
Exemple #30
0
def reset_password_request():
    # prevent the logged user to see this page
    if current_user.is_authenticated:
        return redirect(url_for('dashboard.overview'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash('Check your email for the instruction to reset your password.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Reset Password', form=form)