Beispiel #1
0
def cheage_email():
    form = CheageEmail()
    if form.validate_on_submit():
        token = current_user.generate_email_token()
        # 发送激活邮件
        send_mail(form.new_email.data, "修改邮箱", "email/cheage_email", token=token, username=current_user.username)
        flash("邮件已经发送,请点击链接修改", "ok")
    return render_template("user/cheage_email.html", form=form)
Beispiel #2
0
def resend_confirmation():
    token = current_user.generate_email_token()
    send_email(to=current_user.email,
               subject='Confirm your account',
               template='/auth/email/confirm',
               user=current_user,
               token=token)
    flash('A new email has sent to you...')
    return render_template('unconfirmed.html')
Beispiel #3
0
 def test_users_can_confirm_email(self):
     self.client.post(url_for('login'),
                      data={
                          'email': '*****@*****.**',
                          'password': '******'
                      })
     token = current_user.generate_email_token().decode('ascii')
     user = User.verify_email_token(token)
     self.assertTrue(user)
     response = self.client.get('/confirm/{}'.format(token))
     self.assertRedirects(response, url_for('index'))
Beispiel #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_email_token(new_email)
            send_email(user.email, 'Confirm your email adderss', '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)
Beispiel #5
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_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)
Beispiel #6
0
def change_email_request():
    form = Changeemail()
    if form.validate_on_submit():
        #		current_user.emali = form.new_email.data
        #		current_user.confirmed = False
        token = current_user.generate_email_token(form.new_email.data)
        send_email(form.new_email.data,
                   'Confirmation Your Account',
                   'auth/email/change_email',
                   user=current_user,
                   token=token)
        flash('A confirmation email has been sent to you by email')
        return redirect(url_for('main.index'))
    return render_template('auth/Changeemail.html', form=form)
Beispiel #7
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        token = current_user.generate_email_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 instruction to confirm your new email address has been sent to your new email address'
        )
        return redirect(url_for('main.index'))
    return render_template('auth/change_email.html', form=form)
Beispiel #8
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.generate_password_hash(form.password.data)
        db.session.add(user)
        db.session.commit()
        token = current_user.generate_email_token()
        send_email(to=current_user.email,
                   subject='Confirm your account',
                   template='/auth/email/confirm',
                   user=user,
                   token=token)
        return redirect(url_for("main.index"))
    return render_template('auth/register.html', form=form)
Beispiel #9
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        token = current_user.generate_email_token(
            form.new_email.data.lower())  # method of the User
        send_email(form.new_email.data.lower(),
                   'Confirm Email',
                   'auth/mail/confirm_email',
                   user=current_user,
                   token=token)
        flash("A confirmation request has been sent to your email!")
        return redirect(url_for('.login'))
    return render_template('auth/change_email.html',
                           form=form,
                           user=current_user)
Beispiel #10
0
def login():
    form = LoginForm()
    user = User.query.filter_by(username=form.username.data).first()
    if form.validate_on_submit():
        if user is not None and user.verify_password(form.password.data):
            login_user(user)
            token = current_user.generate_email_token()
            if not current_user.authenticated:
                send_email(to=current_user.email,
                           subject='Confirm your account',
                           template='/auth/email/confirm',
                           user=current_user,
                           token=token)
            return redirect(url_for('main.index'))
        flash('Invalid user or password')
    return render_template('auth/login.html', form=form)
Beispiel #11
0
 def test_users_can_reset_password(self):
     self.client.post(url_for('login'),
                      data={
                          'email': '*****@*****.**',
                          'password': '******'
                      })
     info = {"email": "*****@*****.**"}
     response = self.client.post(
         '/reset',
         data=json.dumps(info),
         content_type='application/json;charset=UTF-8')
     self.assertEquals(response.json['message'], 'success')
     self.assert200(response)
     token = current_user.generate_email_token().decode('ascii')
     response = self.client.get("/reset/{}".format(token))
     self.assertTemplateUsed('change_pass.html')
Beispiel #12
0
def change_email_token(token):
    form = ChangeEmail()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_email_token(email=form.email.data)
            send_email(form.email.data,
                       'confirm your email',
                       'auth/mail/confirm_email',
                       token=token,
                       user=current_user)
            flash('a confirm email has been send to your new email %s' %
                  form.email.data)
            return redirect(url_for('main.index'))
        flash('wrong password')
    if not current_user.confirm(token):
        flash('wrong or expired token')
        return redirect(url_for('main.index'))
    return render_template('auth/change_email.html', form=form)