Exemple #1
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        current_user.verify_password(form.old_password.data)
        db.session.add(current_user)
        flash("Your password has been updated")
        return redirect(url_for("main.index"))
    else:
        flash("Invalid password")
    return render_template("auth/change_password.html", form=form)
Exemple #2
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        new_email = form.email.data
        current_user.verify_password(form.password.data)
        token = current_user.generate_confirmation_token()
        send_email(new_email, "Confirm Your Account", "auth/email/change_email", user=current_user, token=token)
        flash("An email with instructions has been sent")
        return redirect(url_for("main.index"))
    else:
        flash("Invalid password")
    return render_template("auth/change_email.html", form=form)
Exemple #3
0
def securitytwo(username):
    form = ChangePasswordForm(request.form)
    user = User.query.filter_by(username=username).first()
    print (str(user))
    if form.validate_on_submit():
        if form.validate_recpatcha(form.picture):
             print (str(user))
             print "form validated"
             user = User.query.filter_by(username=username).first()
             if current_user.verify_password(form.old_password.data):


                current_user.password = form.password.data


                db.session.add(current_user)
                db.session.commit()
                flash('Password updated')

                return redirect(url_for('main.user', username=current_user.username))
             else:
                 flash("invalid recapthca/password")
                 return redirect(url_for('auth.security', username=current_user.username))
        else:
            flash("invalid recapthca/password")
            return redirect(url_for('auth.security', username=current_user.username))
    return render_template('/auth/securitytwo.html', user=user, form=form)
Exemple #4
0
def setting_password():
    if request.method == 'GET':
        return render_template('user/setting_passwd.html', form=None)
    elif request.method == 'POST':
        _form = request.form
        cur_password = _form['old_password']
        new_password = _form['password']
        new_password_2 = _form['password2']

        message_cur, message_new = "", ""
        if not cur_password:
            message_cur = "The old password can not be empty."
        elif not current_user.verify_password(cur_password):
            message_cur = "The old password is not correct."

        if new_password != new_password_2:
            message_new = gettext("Passwords don't match.")
        elif new_password_2 == "" or new_password == "":
            message_new = gettext("Passwords can not be empty.")

        if message_cur or message_new:
            return render_template("user/setting_passwd.html", form=_form,
                                   message_cur=message_cur,
                                   message_new=message_new)
        else:
            current_user.password = new_password
            db.session.commit()
            message_success = gettext("Update password done!")
            return render_template("user/setting_passwd.html",
                                   message_success=message_success)
Exemple #5
0
def change_email_request():
    '''auth.change_email_request()'''
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data.strip().lower()
            token = current_user.generate_email_change_token(new_email)
            send_email(
                recipient=new_email,
                subject='确认您的邮箱账户',
                template='auth/mail/change_email',
                user=current_user._get_current_object(),
                token=token
            )
            flash('一封确认邮件已经发送至您的邮箱', category='info')
            add_user_log(
                user=current_user._get_current_object(),
                event='请求修改邮箱为:{}'.format(new_email),
                category='auth'
            )
            return redirect(url_for('auth.change_email_request'))
        flash('无效的用户名或密码', category='error')
        return redirect(url_for('auth.change_email_request'))
    return minify(render_template(
        'auth/change_email.html',
        form=form
    ))
Exemple #6
0
    def validate_current_password(self, field):
        """Raise an exception if current_password isn't the user's password.

        Raises:
            ValidationError: current_password's contents must match the
                             password of the logged in user.
        """
        if not current_user.verify_password(field.data):
            raise ValidationError('Password is incorrect!')
Exemple #7
0
def change_password():
	form = ChangePasswordForm()
	if form.validate_on_submit():
		if current_user.verify_password(form.password.data):
			 current_user.password = form.password.data
			 db.session.add(current_user)
			 flash('Password updated successfuly!')
			 return redirect(url_for('main.index'))
		else:
			flash('Invalid password.')
	return render_template('auth/updatePassword.html', form = form)
Exemple #8
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash('Tu contrasena fue actualizada.')
            return redirect(url_for('main.index'))
        else:
            flash('Contrasena invalida.')
    return render_template("auth/change_password.html", form=form)
Exemple #9
0
def modify_password():
    form = ModifyPasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash(u'密码修改成功!')
            return redirect(url_for('main.index'))
        else:
            flash(u'原密码错误!')
    return render_template('auth/modify_password.html', form=form)
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash('汝换了新的密码,好耶!')
            return redirect(url_for('main.index'))
        else:
            flash('( ̄ε(# ̄)☆╰╮( ̄▽ ̄///) 密码不对~')
    return render_template("auth/change_password.html", form=form)
Exemple #11
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash('密码修改成功.', "success")
            return redirect(url_for('main.index'))
        else:
            flash('无效的密码.')
    return render_template("auth/change_password.html", form=form)
Exemple #12
0
def password():
    change_password_form = ChangePasswordForm(prefix='change_password')
    if change_password_form.validate_on_submit():
        if current_user.verify_password(change_password_form.old_password.data.strip()):
            current_user.password = change_password_form.password.data.strip()
            db.session.add(current_user)
            flash({'success': u'您的账户密码已修改成功!'})
        else:
            flash({'error': u'无效的旧密码!'})

    return render_template('password.html', changePasswordForm=change_password_form)
Exemple #13
0
def reset_password():
    form = ResetPasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/reset_password.html", form=form)
Exemple #14
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash('你的密码已经更改!')
            return redirect(url_for('main.index'))
        else:
            flash('密码错误')
    return render_template('auth/change_password.html', form=form)
Exemple #15
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.set_password(form.password.data)
            current_user.save()
            flash('Your password has been updated')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/change_password.html", form=form)
Exemple #16
0
def changing_password():
    form = ChangingPasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            flash('Your password has been changed successfully.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/changing_password.html", form=form)
Exemple #17
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.new_password.data
            db.session.add(current_user)
            flash(u'密码已修改')
            return redirect(url_for('user.account'))
        else:
            flash(u'密码错误')
    return render_template("auth/change_password.html", form=form)
Exemple #18
0
def profile():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        print 'f1'
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.commit()
            flash('Ваш пароль был изменен.')
            return redirect(url_for('events'))
        else:
            flash('Не верный пароль.')
    return render_template('profile.html', form=form)
Exemple #19
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_email_change_token(new_email=form.email.data)
            send_email(to=form.email.data, subject='Change email', template='auth/email/change_email',
                       user=current_user, token=token)
            flash('Change email request have been sent to your new email.')
            return redirect(url_for('auth.login'))
        else:
            flash('Invalid password')
    return render_template('auth/change_email.html', form=form)
Exemple #20
0
def change_password():
    form = ChangerPasswordForm()
    if form.validate_on_submit():
        if current_user.is_authenticated and current_user.confirmed and current_user.verify_password(form.oldpassword.data):
            current_user.password = form.newpassword.data
            db.session.add(current_user)
            db.session.commit()
            flash('You have successfully changed your password. Please try to login again .')
            return redirect(url_for('auth.login'))
        else:
            flash("Something may be wrong . Please check you password and try again . ")
    return render_template('changepassword.html', form=form)
Exemple #21
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email, '邮箱确认', 'auth/email/change_email', user=current_user, token=token)
            flash('新邮箱的确认邮件已经发送')
            return redirect(url_for('main.index'))
        else:
            flash('无效的邮箱或密码')
    return render_template('auth/change_email.html', form=form)
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email, 'Confirm your email address', 'auth/email/change_email', user=current_user, token=token)
            flash('An email with instruction to confirm your new email address has been sent to you.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password')
    return render_template("auth/change_email.html", form=form)   
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            db.session.commit()
            flash('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/change_password.html", form=form, cdnroot=get_cdnroot())
Exemple #24
0
def change_password():
    form = ChangePasswordForm()

    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            db.session.commit()
            flash('修改密码成功!', 'success')
            return redirect(url_for('admin.account'))
        else:
            flash('修改密码失败!密码不正确!', 'danger')
            return redirect(url_for('admin.account'))
Exemple #25
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        new_password = form.new_password.data
        if not current_user.verify_password(form.old_password.data):
            flash(u'旧密码不匹配')
        else:
            current_user.password = new_password
            db.session.add(current_user)
            flash(u'修改密码成功')
            return redirect(url_for('main.index'))

    return render_template('auth/change_password.html', form=form)
Exemple #26
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.new_email.data
            token = current_user.generate_changing_email_request(new_email)
            send_email(new_email, 'Change your email address',
                       'auth/email/change_email', user=current_user, token=token)
            flash('An confrimation email has been sent to you.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password')
    return render_template('auth/change_email.html', form=form)
Exemple #27
0
def change_password():
    form = ChangePassword()
    if form.validate_on_submit():
        if current_user.verify_password(form.current.data):
            flash("Password has been updated")
            current_user.password = form.new.data
            db.session.add(current_user)
            db.session.commit()
            send_mail(current_user.email, 'Your password has changed',
                      'auth/email/password_change', user=current_user)
            return redirect(url_for('front_page.home_page'))
    current_app.logger.info("User {} has requested a password change".format(current_user.username))
    return render_template('auth/change_password.html', form=form)
Exemple #28
0
def change_password():
    form = PasswordChangeForm()

    if form.validate_on_submit():
        if (current_user.verify_password(form.old_password.data)):
            current_user.password = form.new_password.data
            db.session.add(current_user)
            flash('Your password has been changed!')
            return redirect( url_for('main.index') )
        else:
            flash('Incorrect password!')

    return render_template('auth/change_password.html', title='Change Password', user=current_user, form=form)
Exemple #29
0
def change_password():
    """Change an existing user's password."""
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.new_password.data
            db.session.add(current_user)
            db.session.commit()
            flash('Your password has been updated.', 'form-success')
            return redirect(url_for('main.index'))
        else:
            flash('Original password is invalid.', 'form-error')
    return render_template('account/manage.html', form=form)
Exemple #30
0
def edit_user_info():
    form2 = EditUserInfoForm()

    if form2.validate_on_submit():
        if current_user.verify_password(form2.password.data):
            current_user.username = form2.username.data
            current_user.email = form2.email.data
            db.session.add(current_user)
            db.session.commit()
            flash('修改用户信息成功!', 'success')
            return redirect(url_for('admin.account'))
        else:
            flash('修改用户信息失败!密码不正确!', 'danger')
            return redirect(url_for('admin.account'))
Exemple #31
0
def change_password():
    """
    修改密码
    :return:
    """
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if form.new_password.data == form.old_password.data:
            flash('新密码不能和原始密码相同')
        elif current_user.verify_password(form.old_password.data):
            current_user.password = form.new_password.data
            current_user.save()
            flash('密码修改成功')
            return redirect(url_for('main.index'))
        else:
            flash('原始密码错误')
    return render_template('auth/change_password.html', form=form)
Exemple #32
0
def change_password():
    '''
        define operation of change password
    :return: page
    '''

    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            db.session.commit()
            flash(u'您的密码已经被更新!')
            return redirect(url_for('index.index_page'))
        else:
            flash(u'旧密码无效!')
    return render_template('auth/change_password.html', form=form)
Exemple #33
0
def change_pass():
    form = ChangePasswordForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            if current_user.verify_password(form.old_password.data):
                current_user.password = form.password.data
                db.session.add(current_user)
                db.session.commit()
                flash('Ваш пароль был обновлен.')
                return jsonify(status='ok')
            else:
                return jsonify(status='Неверный старый пароль.')
        else:
            data = json.dumps(form.errors, ensure_ascii=False)
            return jsonify(data)
    return render_template('users/_change_password.html',
                           change_password_form=form)
Exemple #34
0
def change_email_request():
    """更改邮箱 发送邮件"""
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       '确认您的邮箱地址',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('已发送一封包含确认您的新电子邮件地址的说明的电子邮件。', 'info')
            return render_template("auth/change_email.html", form=form)
        else:
            flash('无效的邮箱或密码', 'danger')
    return render_template("auth/change_email.html", form=form)
Exemple #35
0
def request_email_change():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.new_email.data.lower()
            token = current_user.generate_email_change_token(new_email)
            send_email(form.new_email.data,
                       'Confirm your email address',
                       '/auth/email/change_email',
                       user=current_user,
                       token=token)
            flash(
                f'An email with instructions has been sent to: {form.new_email.data}'
            )
            return redirect(url_for('main.index'))
        flash('Invalid password.')
    return render_template('auth/change_email.html', form=form)
Exemple #36
0
def change_password():
    """Change an existing user's password."""
    badge_list = []
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.new_password.data
            db.session.add(current_user)
            db.session.commit()
            flash('Your password has been updated.', 'form-success')
            return redirect(url_for('main.index'))
        else:
            flash('Original password is invalid.', 'form-error')
    return render_template('account/manage.html',
                           form=form,
                           user=current_user,
                           badge_list=badge_list)
Exemple #37
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):  # 验证密码
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       'Confirm your email address',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)

            flash('修改邮箱确认邮件已经发送到您的邮箱,请前往邮箱确认')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.')
    return render_template("auth/change_email.html", form=form)
Exemple #38
0
def profile():
    form = ProfileForm()
    if form.validate_on_submit():
        if form.version_id.data != current_user.version_id:
            flash(
                "The profile has not been saved due to concurrent modification.",
                "error",
            )
            return redirect(url_for("index"))

        try:
            # check if all password fields are filled-in
            # check if the new password and confirmed new password are the same
            if (form.password_curr.data and form.password.data
                    and form.password_conf.data
                    and form.password.data == form.password_conf.data):
                # check if the current password is valid
                if current_user.verify_password(form.password_curr.data):
                    current_user.set_password(form.password.data)
                    database.session.commit()
                    flash("The password has been changed.")
                else:
                    flash("The current password is invalid.", "error")

            # current_user.xxx = form.yyy.data
            # database.session.commit()
            # flash('The profile has been saved.')
        except StaleDataError:
            database.session.rollback()
            flash(
                "The profile has not been saved due to concurrent modification.",
                "error",
            )

        return redirect(url_for("index"))
    elif request.method == "GET":
        form.version_id.data = current_user.version_id
        form.email.data = current_user.email
        # form.yyy.data = current_user.xxx

    return render_template(
        "authentication/profile.html.jinja",
        title="Profile",
        form=form,
        cancel_url=url_for("index"),
    )
Exemple #39
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.newemail.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       'Update your Email Address',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash(
                'A confirmation link has been sent to your new Email address')
            return redirect(url_for('auth.login'))
        else:
            flash('Invalid email or password')
    return render_template('auth/change_email.html', form=form)
Exemple #40
0
def change_email_request():
    #修改email请求路由
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       'Confirm your email address',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('验证信息已经发送,晴查收!')
            return redirect(url_for('main.index'))
        else:
            flash('邮箱或密码错误!')
    return render_template("auth/change_email.html", form=form)
Exemple #41
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        # 验证填写的密码是否正确
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       '修改邮箱地址',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('修改邮箱地址确认邮件已发送到新邮箱,请前去确认')
            redirect(url_for('main.index'))
        else:
            flash('密码错误')
    return render_template('auth/change_email.html', form=form)
Exemple #42
0
def change_email_request():
    form = ChangeEmailRequest()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_email_change_token(form.email.data)
            send_email('form.email.data',
                       'Confirm your account',
                       'auth/email/change_email_request',
                       form=form,
                       token=token)
            flash(
                'A confirmmation has been sent to you by the new email account!'
            )
        else:
            flash('Invalid email or password!')
        return redirect(url_for('auth.change_email_request'))
    return render_template('auth/changeemailrequest.html', form=form)
Exemple #43
0
def change_password():
    jsloads = ['js/zxcvbn.js', 'js/password.js']
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            db.session.commit()
            flash('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    else:
        current_app.logger.info(form.errors)
    return render_template("auth/change_password.html",
                           form=form,
                           jsloads=jsloads)
Exemple #44
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data.lower()
            token = current_user.generate_change_email_token(new_email)
            send_email(new_email,
                       'Change email',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash(
                'An email with instructions to change email has been sent to you.',
                'info')
            return redirect(url_for('main.index'))
        flash('Incorrect password.', 'warning')
    return render_template('auth/change_email.html', form=form)
Exemple #45
0
def request_change_email():
    form = RequestChangEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_new_email_confirmation_token(
                form.email.data)
            send_email(form.email.data,
                       'Change Your Email Address',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('An email with instructions to change your email has been '
                  'sent to you.')
            return redirect(url_for('auth.login'))
        else:
            flash('Invalid or password')
    return render_template('auth/request_change_email.html', form=form)
Exemple #46
0
    def validate_on_submit(self):
        if not super().validate_on_submit():
            return False

        if not current_user.verify_password(self.password.data):
            self.password.errors.append('Incorrect password')
            return False

        existing_user = User.objects(email=self.email.data).first()

        if current_user.email != self.email.data and existing_user:
            self.email.errors.append(
                'There is already an account with this email',
            )
            return False

        return True
Exemple #47
0
def change_password() -> Any:
    form: FlaskForm = ChangePasswordForm()

    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            db.session.commit()

            flash("Your password has been successfully changed.")

            return redirect(url_for("main.index"))

        else:
            flash("Invalid password.")

    return render_template("auth/change_password.html", form=form)
Exemple #48
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       'Подтвердите ваш электронный адрес',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('Вам отправлено электронное письмо с инструкциями'
                  ' для подтверждения вашего нового адреса электронной почты.')
            return redirect(url_for('main.index'))
        else:
            flash('Неправильный адрес электронной почты или пароль.')
    return render_template("auth/change_email.html", form=form)
Exemple #49
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       'Confirm your email address',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('An email with instructions to confirm your new email '
                  'address has been sent to you.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.')
    return render_template("auth/change_email.html", form=form)
Exemple #50
0
def chpassword():
    pagetitle = 'Change Password'
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            user = current_user._get_current_object()
            user.password = form.new_password.data
            db.session.add(user)
            db.session.commit()
            flash('Change Password Successfully!')
            return redirect(url_for('main.index'))
        else:
            flash('Old Password Error!')
            form.old_password.data = ""
            form.new_password.data = ""
    return render_template('auth/formpage.html',
                           form=form, pagetitle=pagetitle)
Exemple #51
0
def change_password():
    """
    Handle requests to url /change_password
    Allows user to change password
    """
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            # db.session.add(current_user)
            # db.session.commit()
            database.update(current_user)
            flash('Your password has been updated.', 'success')
            return redirect(url_for('main.index'))
        else:
            flash('Your old password is incorrect', 'danger')
    return render_template('users/change_password.html', form=form)
Exemple #52
0
def update_user_profile():
	data = request.get_json()
	# Set name
	current_user.name = data['name']
	# Set email
	updated_mail = False
	if data['email'] != '' and data['email'] != current_user.email:
		send_update_email(data['email'], current_user.email)
		updated_mail = data['email']
	# Check password
	if all(p in data for p in ['currentPasswd', 'newPasswd', 'confirmNewPasswd']):
		if current_user.verify_password(data['currentPasswd']) and data['newPasswd'] == data['confirmNewPasswd']:
			current_user.password_hash = current_user.hash_password(data['newPasswd'])
		else:
			return jsonify(bad_password=True), 400
	current_user.save()
	return jsonify(user=current_user.clean(), updated_mail=updated_mail)
Exemple #53
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        # 判断密码是否合法
        if current_user.verify_password(form.password.data):
            new_email = form.user_email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       '确认邮箱地址',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('确认新邮箱的邮件已发送至 %s' % new_email)
            return redirect(url_for('main.index'))
        else:
            flash('不合法的邮箱或密码。')
    return render_template('auth/change_email.html', form=form)
Exemple #54
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            if form.old_password.data == form.password2.data:
                flash("旧密码不能和新密码相同!")
                return render_template("auth/change_password.html", form = form)
            current_user.password = form.password2.data
            db.session.add(current_user)
            logout_user()
            flash("你已成功修改了密码,请重新登陆.")
            return redirect(url_for("auth.login"))
        else:
            flash("旧密码输入错误.")
    VcodeTuple = generate_verification_code()
    session["verificationCode"] = VcodeTuple[0]
    return render_template("auth/change_password.html", form = form, VcodeName = VcodeTuple[1])
Exemple #55
0
def change_email_request():
    ''' 修改邮箱请求 '''
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.new_email.data
            token = current_user.generate_change_email_token(new_email)
            send_email(form.new_email.data,
                       'Confirm Your New Email Address',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('A confirmation email has been sent to your new email.')
            return redirect(url_for('main.index'))
        flash('Invalid email or password.')
    form.new_email.data = current_user.email
    return render_template('auth/change_email.html', form=form)
Exemple #56
0
def update_email():
    form = UpdateEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data.lower()
            session['new_email'] = new_email
            token = current_user.generate_email_update_token(
                new_email=new_email)
            send_email(new_email,
                       'Account Updated',
                       'auth/mail/update_email',
                       token=token)
            flash('mail sent with instructions')
            return redirect(url_for('main.home'))
        else:
            flash('Check your password')
    return render_template('auth/update_email.html', form=form)
Exemple #57
0
def change_password():
    # Create new change password form
    form = ChangePasswordForm()
    # If the request contains a submitted form
    if form.validate_on_submit():
        # Verify the password is not the same as the old
        if current_user.verify_password(form.old_password.data):
            # Save new password
            current_user.password = form.password.data
            current_user.save()
            #db.session.add(current_user)
            flash('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    # Else, if there is no form submission send "change password" page
    return render_template("change_password.html", form=form)
Exemple #58
0
def change_pw():

    form = PasswordChangeForm()

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

        if not current_user.verify_password(form.old.data):
            flash("You incorrectly entered your old password")

        else:
            current_user.password = form.new.data
            flash("Successfully changed password!")
        return redirect(url_for("auth.change_pw"))

    return render_template("auth/change_pw.html", form=form)
Exemple #59
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            _user = mydb.user_get()
            _user.find_by_email(current_user.email)
            _user.password = form.password.data
            _user.modify()
            logout_user()
            # current_user.password = form.password.data
            # db.session.add(current_user)
            # db.session.commit()
            flash('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/change_password.html", form=form)
Exemple #60
0
def change_email_request():
    change_email_form = ChangeEmailForm()
    if change_email_form.validate_on_submit():
        # TODO 密码输入正确,发送邮件
        if current_user.verify_password(change_email_form.password.data):
            new_email = change_email_form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       '确认更改邮箱地址的邮件',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('确认更改邮箱地址的邮件已经发送')
            return redirect(url_for('main.index'))
        else:
            flash('非法的邮箱或者密码')
    return render_template('auth/change_email.html', form=change_email_form)