Пример #1
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_email(form.old_email.data):
            current_user.email = form.email.data
            db.session.add(current_user)
            flash('您的邮箱已经修改!')
            return redirect(url_for('main.index'))
        else:
            flash('原邮箱错误,操作无效!')
    return render_template('user/change_email.html', form=form)
Пример #2
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        user = User.query.filter(User.username == current_user.username).first()
        if user.verify_password(form.password.data):
            current_user.email = form.email.data
            db.session.add(current_user)
            flash("修改成功")
            return redirect(url_for("users.information"))
        else:
            flash('用户名或密码输入错误')
    return render_template('user/change_email.html', form=form)
Пример #3
0
def profile():
    form = ChangeEmailForm()
    form.email.data = current_user.email
    context = {
        'form': form
    }
    if form.validate_on_submit():  # need hidden field
        current_user.email = request.form.get('email')
        db.session.commit()
        flash('Email has been updated!', 'success')
        return redirect(url_for('profile'))

    return render_template('profile.html', **context)
Пример #4
0
def change_email():
    form = ChangeEmailForm()
    if form.validate():
        if form.oldemail.data == current_user.email:
            current_user.email = form.newemail.data
            current_user.confirmed = 0
            db.session.add(current_user)
            db.session.commit()
            token = current_user.generate_active_token()
            send_mail(current_user.email, '账户激活', 'email/activate', username=current_user.username, token=token)
            flash('邮箱已经修改,请点击邮件中的链接完成激活')
            return redirect(url_for('main.index'))
        else:
            flash('修改失败')
    return render_template('users/change_email.html',form=form)
Пример #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_change_token(new_email)
            send_email(new_email,
                       u'确认您的邮箱',
                       'change_email',
                       user=current_user,
                       token=token)
            flash(u'一封带有确认链接的邮件已经发往您的新邮箱,请查阅确认.')
            return redirect(url_for('index'))
        else:
            flash(u'无效的邮箱或密码')
    return render_template("change_email0.html", form=form)
Пример #6
0
def profile(request):
    """Renders the profile page."""
    assert isinstance(request, HttpRequest)
    student = None
    if (request.user.is_authenticated()):
        try:
            student = Students.objects.get(email=request.user)
        except Exception as e:
            student = None

    if request.method == 'POST':
        return post_handler(request)

    else:
        return render(request,
                      'userprofile/profile.html',
                      context_instance=RequestContext(
                          request, {
                              'title': 'Profile',
                              'student': student,
                              'date': datetime.now(),
                              'year': datetime.now().year,
                              'change_email_form': ChangeEmailForm(),
                              'change_password_form': ChangePasswordForm()
                          }))
Пример #7
0
def change_email(request):
    form = ChangeEmailForm(request.POST)
    if form.is_valid():
        student = Students.objects.get(email=request.user)
        user = AuthUser.objects.get(username=request.user)

        if request.user.check_password(
                form.cleaned_data['password_confirmation']):
            student.email = form.cleaned_data['new_email']
            user.username = form.cleaned_data[
                'new_email']  #email used as username
            user.email = form.cleaned_data['new_email']
            request.user.username = form.cleaned_data['new_email']

            request.user.save()
            student.save()
            user.save()
            return True

    return False
Пример #8
0
def post_handler(request):

    form = ChangeEmailForm(request.POST)
    pwd_change_success = False
    email_change_success = False
    student = None

    if form.is_valid():
        email_change_success = change_email(request)
    else:
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            pwd_change_success = change_password(request)

    if (request.user.is_authenticated()):
        student = Students.objects.get(email=request.user)

    return render(request,
                  'userprofile/profile.html',
                  context_instance=RequestContext(
                      request, {
                          'title': 'Profile',
                          'student': student,
                          'date': datetime.now(),
                          'year': datetime.now().year,
                          'change_email_form': ChangeEmailForm(),
                          'change_password_form': ChangePasswordForm(),
                          'pwd_change_success': pwd_change_success,
                          'email_change_success': email_change_success
                      }))