Пример #1
0
def bind_email(request):
    redirect_to = request.GET.get('from', reverse('home'))
    if request.method == 'POST':
        form = BindEmailForm(request.POST, request=request, user=request.user)
        if form.is_valid():
            email = form.cleaned_data['email']
            user = User.objects.get(username=request.user.username)
            user.email = email
            user.save()
            del request.session['email_code']  # 防止一个验证码多次使用

            return redirect(redirect_to)

    else:
        form = BindEmailForm()

    context = {
        'page_title': '绑定邮箱',
        'form_title': '绑定邮箱',
        'submit_text': '绑定',
        'form': form,
        'return_back_url': redirect_to,
    }

    return render(request, 'bind_email.html', context=context)
Пример #2
0
def bind_email(request):
    data = {}
    bind_form = BindEmailForm(request.POST, request=request)
    if bind_form.is_valid():
        email = bind_form.cleaned_data['email']
        request.user.email = email
        request.user.save()
        del request.session['bind_email_code']
        del request.session['get_email']
        data['status'] = 'SUCCESS'
    else:
        data['status'] = 'ERROR'
        data['errors'] = bind_form.errors
    return JsonResponse(data)
Пример #3
0
def personal_info(request):
    context = {}
    bind_form = BindEmailForm()
    password_form = ChangePasswordForm()
    context['bind_form'] = bind_form
    context['password_form'] = password_form
    return render(request, 'presonal_info.html', context)
Пример #4
0
def bind_email(request):
    redirect_to = request.GET.get('from', reverse('home'))
    if request.method == 'POST':
        form = BindEmailForm(request.POST, request=request)
        if form.is_valid():
            email = form.cleaned_data['email']
            request.user.email = email
            request.user.save()
            return redirect(redirect_to)
    else:
        form = BindEmailForm()
    return render(request, 'bind_email.html', {
        "form": form,
        "page_title": '绑定邮箱',
        "form_title": '绑定邮箱',
        "submit_text": '绑定',
        "return_back_url": redirect_to,
    })
Пример #5
0
def bind_email(request):
    if request.method == 'POST':
        form = BindEmailForm(request.POST,request=request)
        if form.is_valid():
            email = form.cleaned_data['email']
            request.user.email = email
            request.user.save()
            return redirect(request.GET.get('from', reverse('home')))
    else:
        form = BindEmailForm()

    context = {}
    context['page_title'] = '我的博客|绑定邮箱'
    context['form_title'] = '绑定邮箱'
    context['submit_text'] = '绑定'
    context['form'] = form
    context['return_back_url'] = request.GET.get('from', reverse('home'))
    return render(request,'bind_email.html',context)
Пример #6
0
def bind_email(request):
    if request.method == 'POST':
        form = BindEmailForm(request.POST, user=request.user)
        print(form)
        if form.is_valid():
            nickname_new = form.cleaned_data['nickname_new']
            profile, created = Profile.objects.get_or_create(user=request.user)
            profile.nickname = nickname_new
            profile.save()
            return redirect(request.GET.get('from', reverse('home')))
    else:
        form = BindEmailForm()

    context = {}
    context['page_title'] = '绑定邮箱'
    context['form_title'] = '绑定邮箱'
    context['submit_text'] = '绑定'
    context['form'] = form
    context['return_back_url'] = request.GET.get('from', reverse('home'))
    return render(request, 'user/bind_email.html', context)
Пример #7
0
def bind_Email(request):
    redirect_to = request.GET.get('from', reverse('home'))
    if request.method == 'POST':
        form = BindEmailForm(request.POST,request=request)
        if form.is_valid():
            email = form.cleaned_data['email']
            request.user.email = email
            request.user.save()
            del request.session['bind_email_code']
            return redirect(redirect_to)
    else:
        form = BindEmailForm()

    context = {
        'forms': form,
        'page_title': '绑定邮箱',
        'form_title': '绑定邮箱',
        'submit_text': '绑定',
        'return_back_url': redirect_to
    }
    return render(request, 'user/bind_email.html', context=context)
Пример #8
0
def bind_email(request):
    redirect_to = request.GET.get('from', reverse('user_info'))

    if request.method == 'POST':
        form = BindEmailForm(request.POST, request=request)
        if form.is_valid():
            email = form.cleaned_data['email']
            request.user.email = email
            request.user.save()
            # 清除session
            del request.session['bind_email_code']
            return redirect(redirect_to)
    else:
        form = BindEmailForm()

    context = {}
    context['page_title'] = '绑定邮箱'
    context['form_title'] = '绑定邮箱'
    context['submit_text'] = '绑定'
    context['form'] = form
    context['return_back_url'] = redirect_to
    return render(request, 'bind_email.html', context)