示例#1
0
文件: views.py 项目: gitbenji/uru-crm
def change_password():
    user = None
    if current_user.is_authenticated():
        if not login_fresh():
            return login_manager.needs_refresh()
        current_user.change_password()
        user = current_user
    elif 'activation_key' in request.values and 'email' in request.values:
        activation_key = request.values['activation_key']
        email = request.values['email']
        user = User.query.filter_by(activation_key=activation_key) \
                         .filter_by(email=email).first()

    if user is None:
        abort(403)

    form = ChangePasswordForm(activation_key=user.activation_key)

    if form.validate_on_submit():
        user.change_password()

        flash(_("Your password has been changed, please log in again"),
              "success")
        return redirect(url_for("frontend.login"))

    return render_template("frontend/change_password.html", form=form)
示例#2
0
def usersuite_change_password():
    """Lets the user change his password.
    Requests the old password once (in case someone forgot to logout for
    example) and the new password two times.

    If the new password was entered correctly twice, LDAP performs a bind
    with the old credentials at the users DN and submits the passwords to
    modify_password(). This way each user can edit only his own data.

    Error code "-1" is an incorrect old or empty password.

    TODO: set a minimum character limit for new passwords.
    """
    form = ChangePasswordForm()

    if form.validate_on_submit():
        old = form.old.data
        new = form.new.data

        try:
            current_user.re_authenticate(old)
            current_user.change_password(old, new)
        except PasswordInvalid:
            flash(gettext("Altes Passwort war inkorrekt!"), "error")
        else:
            flash(gettext("Passwort wurde geändert"), "success")
            return redirect(url_for(".usersuite"))
    elif form.is_submitted():
        flash_formerrors(form)

    return render_template("usersuite/change_password.html", form=form)
示例#3
0
def change_passwd():
	form = ChangePasswdForm()
	if form.validate_on_submit():
		if current_user.verify_password(form.old_password.data):
			current_user.change_password(form.new_password.data)
			flash('Your accunt password has been change')
	return render_template('auth/change_passwd.html', form=form)
示例#4
0
文件: views.py 项目: eppel81/vehicles
def change_password():
    """
    Change user's password view
    """
    form = ChangePass(request.form)
    if request.method == 'POST' and form.validate():
        old_password = request.form.get('old_pass')
        new_password = request.form.get('new_pass')
        if current_user.check_password(old_password):
            current_user.change_password(new_password)
            db.session.add(current_user)
            db.session.commit()
            flash('Your password successfully changed', 'success')
            return redirect(url_for('index'))
    return render_template('change_pass.html', form=form)
示例#5
0
def change_password():
    if IsDeepDebug:
        print('--> change password:is_active:%s' % current_user.is_active)

    form = ChangePasswordForm()

    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            if not is_valid_pwd(form.password.data):
                flash('Invalid password syntax.')
            else:
                current_user.change_password(form.password.data)
                flash('Your password has been updated.')
                return default()
        else:
            flash('Invalid password.')
    elif not form.old_password.data:
        pass
    else:
        flash('ChangePasswordForm data is invalid.')

    if IsDeepDebug:
        print(
            '--> password invalid: [%s-%s-%s]' %
            (form.old_password.data, form.password.data, form.password2.data))

    kw = make_platform(mode='auth')

    kw.update({
        'title': gettext('WebPerso Change Password'),
        'page_title': gettext('WebPerso Reset Password'),
        'header_class': 'middle-header',
        'show_flash': True,
        'semaphore': {
            'state': ''
        },
        'sidebar': {
            'state': 0,
            'title': ''
        },
        'module': 'auth',
    })

    kw['vsc'] = vsc()

    link = 'auth/change_password%s.html' % (IsEdge() and '_default' or '')

    return render_template(link, form=form, **kw)
示例#6
0
def settings():
    """Show settings for authenticated user."""
    chpwd = ChangePasswordForm(prefix='pwd')
    chusr = ChangeUsernameForm(prefix='usr')

    if chpwd.submit.data and chpwd.validate_on_submit():
        current_user.change_password(chpwd.new_password.data)
        db.session.commit()
        flash('Changed password!', 'success')

    if chusr.submit.data and chusr.validate_on_submit():
        current_user.name = chusr.username.data
        db.session.commit()
        flash('Changed username!', 'success')

    return render_template('admin/settings.html', chpwd=chpwd, chusr=chusr)
示例#7
0
def settings():
    """Show settings for authenticated user."""
    chpwd = ChangePasswordForm(prefix='pwd')
    chusr = ChangeUsernameForm(prefix='usr')

    if chpwd.submit.data and chpwd.validate_on_submit():
        current_user.change_password(chpwd.new_password.data)
        db.session.commit()
        flash('Changed password!', 'success')

    if chusr.submit.data and chusr.validate_on_submit():
        current_user.name = chusr.username.data
        db.session.commit()
        flash('Changed username!', 'success')

    return render_template('admin/settings.html', chpwd=chpwd, chusr=chusr)
示例#8
0
def change_password():
    if request.method == 'POST':
        new_password = request.form.get('newpassword1', '')
        if not current_user.check_password(
                request.form.get('currentpassword', '')):
            flash(
                'Your current password was entered incorrectly. Please check and try again.'
            )
        elif new_password != request.form.get('newpassword2', ''):
            flash(
                'Password not changed: new passwords provided did not match.')
        elif len(new_password) < 8:
            flash(
                'Password not changed: Please use a password at least 8 characters long.'
            )
        else:
            current_user.change_password(new_password)
            return redirect(url_for('standings'))

    return render_template('changepassword.html')
示例#9
0
文件: usersuite.py 项目: gwTumm/sipa
def usersuite_change_password():
    """Frontend page to change the user's password"""
    form = ChangePasswordForm()

    if form.validate_on_submit():
        old = form.old.data
        new = form.new.data

        try:
            current_user.re_authenticate(old)
            current_user.change_password(old, new)
        except PasswordInvalid:
            flash(gettext("Altes Passwort war inkorrekt!"), "error")
        else:
            flash(gettext("Passwort wurde geändert"), "success")
            return redirect(url_for(".usersuite"))
    elif form.is_submitted():
        flash_formerrors(form)

    return render_template("usersuite/change_password.html", form=form)
示例#10
0
def usersuite_change_password():
    """Frontend page to change the user's password"""
    form = ChangePasswordForm()

    if form.validate_on_submit():
        old = form.old.data
        new = form.new.data

        try:
            current_user.re_authenticate(old)
            current_user.change_password(old, new)
        except PasswordInvalid:
            flash(gettext("Altes Passwort war inkorrekt!"), "error")
        else:
            flash(gettext("Passwort wurde geändert"), "success")
            return redirect(url_for(".usersuite"))
    elif form.is_submitted():
        flash_formerrors(form)

    return render_template("usersuite/change_password.html", form=form)