Example #1
0
def setting():
    email_form = ChangeEmailForm()
    password_form = ChangePasswordForm()
    if email_form.validate_on_submit():
        if current_user.verify_password(email_form.password.data):
            new_email = 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('邮箱地址或密码错误')
    if password_form.validate_on_submit():
        if current_user.verify_password(password_form.old_password.data):
            current_user.password = password_form.password.data
            db.session.add(current_user)
            flash('您的密码已更改')
            return redirect(url_for('main.index'))
        else:
            flash('无效的密码')
    return render_template('auth/setting.html',
                           email_form=email_form,
                           password_form=password_form)
Example #2
0
File: views.py Project: shynp/ican
def profile_edit():
    form = EditProfileForm(obj=current_user)
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.email = form.email.data
        current_user.phone = form.phone.data
        if form.new_password.data and form.current_password.data:
            if current_user.verify_password(form.current_password.data):
                current_user.password = form.new_password.data
                db.session.add(current_user)
                db.session.commit()
                flash('Your profile has been updated')
            else:
                flash('Invalid current password; password not updated')
        else:
            db.session.add(current_user)
            db.session.commit()
            flash('Your profile has been updated')
        return redirect(url_for('.index'))
    form.name.data = current_user.name
    form.email.data = current_user.email
    form.phone.data = current_user.phone
    return render_template('student/profile-edit.html',
                           student=current_user,
                           form=form)
Example #3
0
def change_password():
	data = request.form
	print data
	oldpassword = noneIfEmptyString(data.get('oldpassword'))
	password = noneIfEmptyString(data.get('password'))
	repassword = noneIfEmptyString(data.get('repassword'))
	if not current_user.verify_password(oldpassword):
		result = {
		'successful':False,
		'error': 1
		}
		return jsonify(result)
	elif(password != repassword):
		result = {
				'successful':False,
				'error': 2
				}
		return jsonify(result)
	elif(password == None):
		result = {
				'successful':False,
				'error': 3
				}
		return jsonify(result)
	else:
		current_user.password = password
		db.session.add(current_user)
		result = {
		'successful':True,
		'url': url_for('main.index'),
		}
		return jsonify(result)
Example #4
0
 def validate_currentpassword(self, field):
     """
     Validates that the provided current password is correct.
     """
     if not current_user.verify_password(field.data):
         raise ValidationError(
             'The current password you have provided is incorrect.')
Example #5
0
 def validate_currentpassword(self, field):
     """
     Validates that the provided current password is correct.
     """
     if not current_user.verify_password(field.data):
         raise ValidationError(
             'The current password you have provided is incorrect.')
Example #6
0
def change_email_request():
    """Respond to existing user's request to change their 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)
            change_email_link = url_for_external('account.change_email',
                                                 token=token)
            get_queue().enqueue(
                send_email,
                recipient=new_email,
                subject='Confirm Your New Email',
                template='account/email/change_email',
                # current_user is a LocalProxy, we want the underlying user
                # object
                user=current_user._get_current_object(),
                change_email_link=change_email_link
            )
            flash('A confirmation link has been sent to {}.'.format(new_email),
                  'warning')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.', 'form-error')
    return render_template('account/manage.html', form=form)
Example #7
0
def change_password():
    form = ChangePasswordForm()
    context = {
        'form': form,
    }

    # Open Page
    if not form.validate_on_submit():
        return render_template('site_auth/change_password.html', **context)

    # 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(_('Password Changed'), 'success')

        add_log('[Site User][Change Password] Changed password')
        return redirect(url_for('index.index'))

    else:
        flash(_('Wrong old password'), 'danger')

        add_log('[Site User][Change Password] Try to change password but entered wrong old password')
        return redirect(url_for('site_auth.change_password'))
Example #8
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)
Example #9
0
def change_password():
    form = ChangePasswordForm()
    context = {
        'form': form,
    }

    # Open Page
    if not form.validate_on_submit():
        return render_template('site_auth/change_password.html', **context)

    # 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(_('Password Changed'), 'success')

        add_log('[Site User][Change Password] Changed password')
        return redirect(url_for('index.index'))

    else:
        flash(_('Wrong old password'), 'danger')

        add_log(
            '[Site User][Change Password] Try to change password but entered wrong old password'
        )
        return redirect(url_for('site_auth.change_password'))
Example #10
0
def change_email_request():
    """Respond to existing user's request to change their 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)
            change_email_link = url_for('account.change_email', token=token,
                                        _external=True)
            get_queue().enqueue(
                send_email,
                recipient=new_email,
                subject='Confirm Your New Email',
                template='account/email/change_email',
                # current_user is a LocalProxy, we want the underlying user
                # object
                user=current_user._get_current_object(),
                change_email_link=change_email_link
            )
            flash('A confirmation link has been sent to {}.'.format(new_email),
                  'warning')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.', 'form-error')
    return render_template('account/manage.html', form=form)
Example #11
0
def edit_profile():
	form = EditProfileInfoForm()
	if form.validate_on_submit():
		valid = True
		if not current_user.verify_password(form.current_password.data):
			flash('Invalid current password')
			valid = False
		if form.username.data != current_user.username:
			another_user = User.query.filter_by(username=form.username.data).first()
			if another_user:
				flash('Username already exists.')
				valid = False
		if valid:
			current_username = current_user.username
			current_user.username = form.username.data
			current_user.first_name = form.first_name.data
			current_user.last_name = form.last_name.data
			if form.password.data:
				current_user.password = form.password.data
			change_user_username_folder(current_username, form.username.data)
			if form.profile_picture.data:
				file = request.files[form.profile_picture.name]
				username = form.username.data
				picture_name = add_profile_picture(username, file)
				current_user.profile_picture = picture_name	
			db.session.add(current_user)
			db.session.commit()
			return redirect(url_for('main.profile'))
	form.username.data = current_user.username
	form.first_name.data = current_user.first_name
	form.last_name.data = current_user.last_name
	return render_template('users/edit_user_info.html', form=form)
 def check(self):
     if not current_user.is_admin:
         return False
     if self._password_required:
         if not self._password:
             return False
         return current_user.verify_password(self._password)
     return True
Example #13
0
def setting():
    """用户设置"""
    role_Permission = getattr(Permission, current_user.role)
    passwd_form = ChangePasswordForm()
    register_form = RegistrationForm()
    sidebarclass = init__sidebar("passwd")
    if request.method == "POST":
        # 更改密码
        if request.form["action"] == "passwd" and role_Permission >= Permission.ADMIN:
            sidebarclass = init__sidebar("passwd")
            if passwd_form.validate_on_submit():
                if current_user.verify_password(passwd_form.old_password.data):
                    current_user.password = passwd_form.password.data
                    db.session.add(current_user)
                    flash(u"密码更改成功")
                else:
                    flash(u"旧密码错误")
            else:
                for key in passwd_form.errors.keys():
                    flash(passwd_form.errors[key][0])
        # 用户注册
        if request.form["action"] == "register" and role_Permission >= Permission.ADMIN:
            sidebarclass = init__sidebar("register")
            if register_form.validate_on_submit():
                user = User(
                    username=register_form.username.data,
                    password=register_form.password.data,
                    role=register_form.role.data,
                )
                db.session.add(user)
                flash(u"用户添加成功")
            else:
                for key in register_form.errors.keys():
                    flash(register_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get("search", "")
        if search:
            # 搜索
            page = int(request.args.get("page", 1))
            sidebarclass = init__sidebar("edituser")
            res = search_res(User, "username", search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template(
                    "auth/setting.html",
                    thead=thead,
                    passwd_form=passwd_form,
                    register_form=register_form,
                    sidebarclass=sidebarclass,
                    pagination=pagination,
                    search_value=search,
                    items=items,
                )
    return render_template(
        "auth/setting.html", passwd_form=passwd_form, register_form=register_form, sidebarclass=sidebarclass
    )
Example #14
0
def modpass():
    form = ModPassword()
    if form.validate_on_submit():
        if current_user.verify_password(form.oldpassword.data):
                current_user.password = form.newpassword.data
                current_user.password_hash
                db.session.commit()
                flash('modify password success!')
    return render_template('mod.html', form=form)
Example #15
0
def setting():
    '''用户设置'''
    role_Permission = getattr(Permission, current_user.role)
    passwd_form = ChangePasswordForm()
    register_form = RegistrationForm()
    sidebarclass = init__sidebar('passwd')
    if request.method == "POST":
        # 更改密码
        if request.form['action'] == 'passwd' and \
                role_Permission >= Permission.ADMIN:
            sidebarclass = init__sidebar('passwd')
            if passwd_form.validate_on_submit():
                if current_user.verify_password(passwd_form.old_password.data):
                    current_user.password = passwd_form.password.data
                    db.session.add(current_user)
                    flash(u'密码更改成功')
                else:
                    flash(u'旧密码错误')
            else:
                for key in passwd_form.errors.keys():
                    flash(passwd_form.errors[key][0])
        # 用户注册
        if request.form['action'] == 'register' and \
                role_Permission >= Permission.ADMIN:
            sidebarclass = init__sidebar('register')
            if register_form.validate_on_submit():
                user = User(username=register_form.username.data,
                            password=register_form.password.data,
                            role=register_form.role.data)
                db.session.add(user)
                flash(u'用户添加成功')
            else:
                for key in register_form.errors.keys():
                    flash(register_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edituser')
            res = search_res(User, 'username', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template('auth/setting.html',
                                       thead=thead,
                                       passwd_form=passwd_form,
                                       register_form=register_form,
                                       sidebarclass=sidebarclass,
                                       pagination=pagination,
                                       search_value=search,
                                       items=items)
    return render_template('auth/setting.html',
                           passwd_form=passwd_form,
                           register_form=register_form,
                           sidebarclass=sidebarclass)
Example #16
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.oldpassword.data):
            current_user.password = form.newpassword.data
            db.session.add(current_user)
            db.session.commit()
            return redirect(url_for('main.logout'))
    return render_template('user_pages/change_password.html', form=form)
Example #17
0
 def post(self, *args, **kwargs):
     form = MTUserPwdForm()
     if form.validate_on_submit() and current_user.verify_password(form.old_pwd.data):
         current_user.password = form.new_pwd.data
         db.session.add(current_user)
         flash(u'密码修改成功', 'success')
     else:
         flash(u'密码修改失败,请检查后再试', 'danger')
     return redirect(url_for('user.password'))
Example #18
0
def ChangePassword():
    form=ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.oldPassword.data):
            current_user.password=form.newPassword.data
            db.session.add(current_user)
            return redirect(url_for('main.index'))
        else:
            flash('Your password is wrong')
    return render_template("auth/changepassword.html", form=form)
Example #19
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_change_email_token(form.email.data)
            send_mail(form.email.data, '修改邮箱确认', 'auth/email/change_email_confirm', user=current_user, token=token)
            flash('确认邮件已发送到该新邮箱,请登录新邮箱进行验证。')
        else:
            flash('密码错误,请重新输入!')
    return render_template('auth/change_email.html', form=form)
 def check(self):
     if not hasattr(self._obj, 'check_supervisor'):
         return False
     if not self._obj.check_supervisor(current_user):
         return False
     if self._password_required:
         if not self._password:
             return False
         return current_user.verify_password(self._password)
     return True
Example #21
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.oldpassword.data):
            current_user.password = form.newpassword.data
            db.session.add(current_user)
            flash('You password had be changed')
        else:
            flash('Wrong old password!')
    return render_template('auth/change_password.html',form=form)
Example #22
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('密码已修改')
        else:
            flash('密码错误或无效')
    return render_template('auth/change_password.html', form=form)
Example #23
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
            flash('你的密码已经修改')
            return redirect(url_for('main.index'))
        else:
            flash('无效的密码')
    return render_template('auth/change_password.html', form=form)
Example #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
            flash('你的密码已经修改')
            return redirect(url_for('main.index'))
        else:
            flash('无效的密码')
    return render_template('auth/change_password.html', form=form)
Example #25
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if not current_user.verify_password(form.old_password.data):
            flash('Invalid password')
        else:
            current_user.password = form.new_password.data
            flash('Your password has been changed. Please Log in with the new password.')
        return redirect(url_for('auth.login'))
    return render_template('auth/change_password.html', form=form)
Example #26
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('密码已修改')
        else:
            flash('密码错误或无效')
    return render_template('auth/change_password.html', form=form)
Example #27
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit() and \
            current_user.verify_password(form.old_password.data):
        current_user.password = form.new_password.data
        db.session.add(current_user)
        db.session.commit()
        flash('You have changed your password successfully')
        redirect(url_for('main.index'))
    return render_template('auth/change_password.html', form=form)
Example #28
0
def change_username():
    change_username_form = ChangeUsernameForm(prefix='change_username')
    if change_username_form.validate_on_submit():
        if current_user.verify_password(change_username_form.password.data):
            current_user.username = change_username_form.username.data.strip()
            db.session.add(current_user)
            flash({'success': u'昵称更新成功!'})
        else:
            flash({'error': u'密码错误!'})
    return render_template('auth/config/change_username.html', changeUsernameForm=change_username_form)
Example #29
0
def reset_password():
    form = ResetPassword()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            current_user.password = form.new_password.data
            db.session.add(current_user)
            flash(messages.reset_password_ok)
            return redirect(url_for('main.index'))
        flash(messages.reset_password_err)
    return render_template('auth/reset_password.html', form=form)
Example #30
0
def password():
    form = PasswordForm()
    if form.validate_on_submit():
        if not current_user.verify_password(form.old_password.data):
            form.old_password.errors.append("旧密码不正确")
            return render_template("setting/password.html", form=form)
        flash("密码修改成功")
        current_user.password = current_user.generate_password_hash(
            form.password.data)
        return render_template("setting/password.html", form=form)
    return render_template("setting/password.html", form=form)
Example #31
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_change_email_token(new_email=new_email)
            send_mail(current_user.email, "Change Email", "auth/email/change_email", user=current_user, token=token)
            flash("An email with instructions to confirm email address has been sent to you.")
        else:
            flash("Invalid email or password.")
    return render_template("auth/change_email.html", form=form)
Example #32
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)
Example #33
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(u"密码已更新.")
            return redirect(url_for("main.index"))
        else:
            flash(u"无效密码.")
    return render_template("auth/change_password.html", form=form)
Example #34
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_change_email_token(new_email=form.new_email.data)
            send_email(form.email.data,'change your email address','auth/email/change_email',token=token,user=current_user)
            flash('we have sent a mail to you.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.')
    return render_template('auth/change_email.html',form=form)
Example #35
0
def reset_password():
    form = ResetPasswordForm()
    if form.validate_on_submit():
        if not current_user.verify_password(form.password.data):
            flash(u'密码错误')
            return redirect(url_for('auth.reset_password'))
        current_user.password = form.password1.data
        db.session.add(current_user)
        flash(u'修改密码成功')
        return redirect(url_for('main.index',id=current_user.id))
    return render_template('auth/reset_password.html',form=form)
Example #36
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('Password anda telah diganti', 'success')
			return redirect(url_for('.index'))
		else:
			flash('Password lama salah', 'error')
	return render_template("change_password.html", form=form)
Example #37
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(u'你的密码已更新')
            return redirect(url_for('main.index'))
        else:
            flash(u'密码不合法')
    return render_template('auth/change_password.html', form = form)
Example #38
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('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/change_password.html", form=form)
Example #39
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('Your password has been updated!')
            return redirect(url_for('main.index'))
        else:
            flash('Invaid password.')
    return render_template('auth/change_password.html', form=form)
Example #40
0
def change_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('auth/config/change_password.html', changePasswordForm=change_password_form)
Example #41
0
def change_passwd():
    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'密码修改成功', 'success')
        else:
            flash(u'旧密码错误,请重试')
    return render_template('change_passwd.html', form=form)
Example #42
0
def change_pwd():
    change_pwd_form = ChangePwdForm()
    if change_pwd_form.validate_on_submit():
        if not current_user.verify_password(change_pwd_form.old_password.data):
            flash(u'密码输入错误')
        else:
            current_user.password = change_pwd_form.password.data
            db.session.add(current_user)
            db.session.commit()
            flash(u'密码修改成功')
    return render_template('auth/changepwd.html', form=change_pwd_form)
Example #43
0
def change_password():
	form = ChangepasswordForm()
	if form.validate_on_submit():
		if not current_user.verify_password(form.old_password.data):
			flash('Password is Wrong!')
		else:
			current_user.password = form.new_password.data
			db.session.add(current_user)
			flash('Update Password Succeed! Now You can Login!')
			return redirect(url_for('auth.login'))
	return render_template('auth/change_password.html', form=form)
Example #44
0
def change_pwd():
    change_pwd_form = ChangePwdForm()
    if change_pwd_form.validate_on_submit():
        if not current_user.verify_password(change_pwd_form.old_password.data):
            flash(u'密码输入错误')
        else:
            current_user.password = change_pwd_form.password.data
            db.session.add(current_user)
            db.session.commit()
            flash(u'密码修改成功')
    return render_template('auth/changepwd.html', form=change_pwd_form)
Example #45
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            current_user.password = form.new_password.data
            db.session.add(current_user)
            db.session.commit()
            flash('You have updated your password.')
            return redirect(url_for('auth.logout'))
        else:
            flash("Invalid password.")
    return render_template('auth/change_password.html', form=form)
Example #46
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('Your password has been updated.', 'info')
            logout_user()
            return redirect(url_for('user.login'))
        else:
            flash('Invalid password.', 'warning')
    return render_template("user/change_password.html", form=form)
Example #47
0
def change_password():
    form = ChangePwdForm()
    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)
            logout_user()
            flash('密码已更改, 请重新登录.')
            return redirect(url_for('auth.login'))
        else:
            flash('你的久密码不正确,请重新输入.')
    return render_template('auth/change_password.html', form=form)
Example #48
0
def change_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()
            flash({'success': u'您的账户密码已修改成功!'})
        else:
            flash({'error': u'无效的旧密码!'})

    return render_template('admin/change_password.html',
                           changePasswordForm=change_password_form)
Example #49
0
def changepwd():
    form = ChangePwd()
    if form.validate_on_submit():
        if current_user.verify_password(form.oldpwd.data):
            current_user.password = form.newpwd1.data
            db.session.add(current_user)
            db.session.commit()
            flash(u'你的密码已经修改')
            return redirect(url_for('.index'))
        else:
            flash(u'无效的密码')
    return render_template('changepwd.html', form=form)
Example #50
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
            g.db.add(current_user)
            g.db.commit()
            flash('Your password has been updated.')
            return redirect(url_for('general.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/change_password.html", form=form)
Example #51
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, u'确认邮箱地址', 'auth/email/change_email', user=current_user, token=token)
			flash(u'新邮箱地址确认邮件已发送.')
			return redirect(url_for('main.index'))
		else:
			flash(u'错误邮箱或密码.')
	return render_template("auth/change_email.html", form=form)
Example #52
0
def change_password():
    title = "更改密码"
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_app.password = form.password.data
            db.session.commit()
            flash("Password changed")
            logout_user()
            return redirect(url_for("auth.signin"))
        flash("Password is wrong")
    return render_template("/auth/form_template.html", form=form, title=title)
Example #53
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit() and \
        current_user.verify_password(form.old_password.data):
        current_user.password_hash = \
            generate_password_hash(form.new_password.data)
        db.session.add(current_user)
        db.session.commit()
        logout_user()
        flash(u'你的密码已被修改,请重新登录')
        return redirect(url_for('auth.login'))
    return render_template('auth/change_password.html', form=form)
Example #54
0
def changepassword():
    '''change password route url'''
    form = ChangepasswordForm()
    if request.method == "POST":
        if current_user.verify_password(form.oldpassword.data):
            current_user.password = form.newpassword.data
            db.session.add(current_user)
            flash(u'更改成功.')
            return redirect(url_for('main.index'))
        else:
            flash(u'更改失败.')
    return render_template("auth/changepassword.html", form=form)
Example #55
0
def change_password():
    '''修改函数,在用户提交原密码后可以修改密码'''
    form = ChangePassword()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            current_user.password = form.new_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)
Example #56
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        oldpassword = form.oldpassword.data
        if current_user.verify_password(oldpassword):
            current_user.password = form.newpassword.data
            db.session.add(current_user)
            db.session.commit()
            flash('Password change sucessful!')
            return redirect(url_for('main.index'))
        else:
            flash('Please input correct old password!')
    return render_template('auth/change_password.html', form=form)