예제 #1
0
파일: views.py 프로젝트: widiot/simple
def settings(option):
    # 设置中的表单
    change_username_form = ChangeUsername()
    change_introduction_form = ChangeIntroduction()
    change_password_form = ChangePasswordForm()
    change_email_form = ChangeEmailForm()

    # 如果是访问设置的主页,直接返回空表单,否则返回各个设置的表单。如果端点不存在,则返回404
    if option != 'index':
        if option == 'change-username':  # 修改昵称
            if change_username_form.validate_on_submit():
                current_user.username = change_username_form.username.data
                db.session.add(current_user._get_current_object())
                db.session.commit()
                flash('昵称修改成功')
            else:
                flash('昵称修改失败,请重试')
        elif option == 'change-introduction':  # 修改简介
            if change_introduction_form.validate_on_submit():
                current_user.introduction = change_introduction_form.introduction.data
                db.session.add(current_user._get_current_object())
                db.session.commit()
                flash('简介修改成功')
            else:
                flash('简介修改失败,请重试')
        elif option == 'change-password':  # 更改密码
            if change_password_form.validate_on_submit():
                current_user.set_password(change_password_form.password.data)
                db.session.add(current_user._get_current_object())
                db.session.commit()
                flash('密码更改成功')
            else:
                flash('密码更改失败,请重试')
        elif option == 'change-email':  # 更改邮箱
            if change_email_form.validate_on_submit():
                new_email = change_email_form.email.data
                token = current_user.generate_change_email_token(new_email)
                send_email(
                    new_email,
                    '验证你的邮箱',
                    'auth/email/change_email',
                    user=current_user,
                    token=token)
                flash('认证邮件已经发送,请登录你的邮箱进行确认')
            else:
                flash('邮箱更改失败,请重试')
        else:
            abort(404)

    # TextAreaField需要单独设置它的默认值
    change_introduction_form.introduction.data = current_user.introduction

    return render_template(
        'auth/settings.html',
        change_username_form=change_username_form,
        change_introduction_form=change_introduction_form,
        change_password_form=change_password_form,
        change_email_form=change_email_form)
예제 #2
0
def change_email():
    form = ChangeEmailForms()
    if form.validate_on_submit():
        token = current_user.generate_change_email_token(form.mail.data)
        send_mail(form.mail.data, "Flasky-Confirm Email", "auth/mail/change_email",
                  token=token, user=current_user)
        flash("account's email has changed, please check your emial and finish the follow steps")
        return redirect(url_for("main.index"))
    return render_template("auth/change_email.html", form=form, current_time=datetime.utcnow())
예제 #3
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        token = current_user.generate_change_email_token()
        current_user.new_email = form.new_email.data
        send_email(current_user.new_email, "Change Your Email", "auth/email/change_email", user=current_user,
                   token=token)
        flash("Please checking on your new Email address")
        return redirect(url_for("main.index"))
    return render_template("auth/change_email.html", form=form)
예제 #4
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)
            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)
예제 #5
0
def change_email_request():
	form = ChangeMailForm()
	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_mail(current_user.email, "Change your email",
			          "/auth/email/change_email", user=current_user, token=token)
			flash("A change email address email has been sent to your email.")
			return redirect(url_for("main.index"))
		else:
			flash("Invalid email or password.")
	return render_template("auth/change_email.html", form=form)
예제 #6
0
def change_email_request():
    form = ChangeEmailRequestForm()
    if form.validate_on_submit():
        newEmail = form.email.data
        user = User.query.filter_by(email=newEmail).first()
        if not user is None:
            flash('The email has been used by other users.')
            return redirect(url_for('auth.change_email_request'))
        token = current_user.generate_change_email_token(new_email = newEmail)
        send_email(newEmail,'Change Your Email', '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('main.index'))
    return render_template('auth/change_email.html', form =form)
예제 #7
0
def change_email_request():
    form = ChangeEmailForm(current_user)
    if form.validate_on_submit():
        new_email = form.newemail.data
        token = current_user.generate_change_email_token(new_email=new_email)
        send_email('Thay đổi email',
                   new_email,
                   'auth/email/change_email',
                   token=token,
                   user=current_user)
        flash('Email xác nhận đã được gửi tới %s.' % new_email)
        return redirect(url_for('auth.change_email_request'))
    return render_template('auth/change_email.html', form=form)
예제 #8
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        token = current_user.generate_change_email_token(form.email.data)
        send_email(current_user.email,
                   'Change your Email Address',
                   'auth/email/change_email',
                   user=current_user,
                   token=token)
        flash('An email with a confirmation link has been sent to your new '
              'email address.')
        return redirect(url_for('main.index'))
    return render_template('auth/change_email_request.html', form=form)
예제 #9
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        new_email = form.email.data
        token = current_user.generate_change_email_token(new_email)
        send_mail(subject="[书床]更换新邮箱",
                  sender="书床管理员 <{}>".format(os.getenv('MAIL_USERNAME')),
                  recipients=[new_email],
                  prefix_template="/auth/mail/change_email",
                  user=current_user,
                  token=token)
        flash('更换邮箱的邮件已重新发送到您新的邮箱,请查收')
        return redirect(url_for('auth.login'))
    return render_template('auth/change_email.html', form=form)
예제 #10
0
파일: views.py 프로젝트: csflyer/blogapp
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        Log.info('Try to Change Email:{}')
        token = current_user.generate_change_email_token(form.email.data)
        Log.info('Try to Send Change Email')
        send_mail(form.email.data,
                  "重设您的密码",
                  "mail/change_email",
                  token=token,
                  user=current_user)
        FlashMsg.info('重设邮件已发往新的邮件地址,请注意查收!')
        return redirect(url_for('main.index'))
    return render_template('baseform/form.html', form=form)
예제 #11
0
파일: views.py 프로젝트: vicigel/myflask
def change_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_change_email_token(new_email)
            send_mail(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)
예제 #12
0
def change_email_request():
    form = ChangeEmailForm()
    form.old_email.data = current_user.email
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_change_email_token(form.email.data)
            flash('一个包含新token令牌链接地址已生成,请点击该地址修改邮箱地址.')
            return render_template('auth/gets_token.html',
                                   endpoint='.change_email',
                                   token=token,
                                   user=current_user)
        else:
            flash('无效邮箱或是密码.')
    return render_template('auth/change_password.html', form=form)
예제 #13
0
파일: views.py 프로젝트: zhaokefei/flask
def email_change_request():
    form = EmailChangeRequestForm()
    if form.validate_on_submit():
        if current_user.verify_password(password=form.password.data):
            new_email = form.email.data
            token = current_user.generate_change_email_token(new_email)
            send_mail(new_email, 'Change Email',
                      'auth/email/change_email', user=current_user,
                      token=token)
            flash('A change email message already sent to you by email.')
            return redirect(url_for('main.index'))
        else:
            flash("Invalid email or password")
    return render_template('auth/change_email.html', form=form)
예제 #14
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(form.email.data)
            send_email(form.email.data,
                       'Confirm your 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'))
        else:
            flash('Invalid password')
    return render_template('auth/change_email.html', form=form)
예제 #15
0
def change_email_request():
    form = ChangeEmailRequestForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_change_email_token(
                form.newemail.data)
            send_email(form.newemail.data,
                       '修改邮箱地址',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('一封确认新邮箱信息的电子邮件已发送至您的新邮箱,请登陆新邮箱确认')
            return redirect(url_for('main.index'))
        flash('密码错误,修改邮箱地址失败')
    return render_template('auth/change_email.html', form=form)
예제 #16
0
def change_email_request():
    form = ChangeEmailRequestForm()
    if form.validate_on_submit():
        current_user.pending_email = form.new_email.data
        token = current_user.generate_change_email_token(form.new_email.data)
        send_email(current_app.config.get('MAIL_TO') or form.new_email.data,
                   'Change your email',
                   '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_request.html', form=form)
예제 #17
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)
            send_email(new_email,
                       'Confirm your email address',
                       'email/change_email',
                       user=current_user,
                       token=token)
            flash('A confirmation link has been sent to {}'.format(new_email),
                  'form-info')
            return redirect(url_for('users.login'))
        flash('Invalid email address', 'form-error')
    return render_template('auth/change_email.html', form=form)
예제 #18
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)
            send_mail(new_email,
                      '重置邮箱',
                      'auth/email/change_email',
                      token=token,
                      user=current_user)
            flash('请到新的邮箱地址确认你的邮件')
            return redirect(url_for('main.index'))
        else:
            flash('密码或邮箱地址不正确')
    return render_template('auth/change_email.html', form=form)
예제 #19
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)
            send_email(new_email,
                       'cmLighters\' Blog 用户邮箱更改',
                       'auth/mail/change_email',
                       token=token,
                       user=current_user)
            flash('确认链接邮件已发送到您的新邮箱中')
            return redirect(url_for('main.index'))
        else:
            flash('密码错误')
    return render_template('auth/change_email.html', form=form)
예제 #20
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)
예제 #21
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)
예제 #22
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        # 表单验证成功,并在数据库中不存在邮箱
        password = form.password.data
        new_email = form.new_email.data.lower()
        if current_user.check_password(password):
            token = current_user.generate_change_email_token(new_email)
            sendMail(new_email,
                     '更换新邮箱',
                     'change_email',
                     user=current_user,
                     token=token)
            flash('您的邮箱已更换,请在新邮箱中激活账户.')
            return redirect(url_for('auth.login'))
        else:
            flash('无效的邮箱或密码')
    return render_template('auth/change_email.html')
예제 #23
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_mail(to=new_email,
                      subject='Confirm Your Account Email Address',
                      template='auth/email/change_email',
                      user=current_user,
                      token=token)
            flash(
                'A Confirm Email has been sent to your new email address,please login your email to confirm.'
            )
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password')
    return render_template('auth/change_email.html', form=form)
예제 #24
0
def change_email_request():
    form = ChangeEmailForm()
    new_email = form.email.data
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            try:
                # 修改的邮箱是否已经被注册过
                form.validate_email(form.email)
            except:
                return False
            token = current_user.generate_change_email_token(new_email)
            send_email(new_email,
                       "更换邮箱",
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('已发送确认链接到新邮箱,请查收')
            return redirect(url_for('main_bp.index'))
    return render_template('auth/change_email.html', form=form)
예제 #25
0
def change_email_request():
    username = current_user.username
    role = User.query.filter_by(username=username).first()
    if role:
        bb = role.role_id
    else:
        bb = 1
    print(bb)
    form = ChangeEmailForm()
    form.old_email.data = current_user.email
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_change_email_token(form.email.data)
            flash('一个包含新token令牌链接地址已生成,请点击该地址修改邮箱地址.')
            return render_template('auth/gets_token.html',
                                   endpoint='.change_email',
                                   token=token,
                                   user=current_user)
        else:
            flash('无效邮箱或是密码.')
    return render_template('auth/change_password.html', form=form, bb=bb)
예제 #26
0
파일: views.py 프로젝트: poxiaoge/SkyWeb
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if not current_user.verify_password(form.password.data):
            flash('Wrong password!')
            return render_template('forms_base.html',
                                   header='Change Email',
                                   form=form)
        email_dict = {
            'old_email': current_user.email,
            'new_email': form.email.data
        }
        token = current_user.generate_change_email_token(dump_dict=email_dict)
        send_email(current_user.email,
                   'old_email_confirm',
                   'email/old_email_confirm',
                   name=current_user.nickname,
                   token=token)
        flash('A new confirmation has been sent to your old email!')
        return render_template('info_base.html',
                               header='Change Email',
                               info='Please check your old email!')
    return render_template('forms_base.html', header='Change Email', form=form)