Exemplo n.º 1
0
def user(request):
    if request.method == "POST":
        user_form = RegistrationForm(request.POST)
        userinfo_form = UserInfoForm(request.POST)
        if user_form.is_valid() * userinfo_form.is_valid():
            new_user = user_form.save(commit=False)
            new_user.set_password(user_form.cleaned_data['password'])
            new_user.save()
            new_profile = userinfo_form.save(commit=False)
            new_profile.user = new_user
            new_profile.save()
            UserInfo.objects.create(user=new_user)
            return HttpResponse("successfully")
        else:
            return HttpResponse("抱歉,注册失败")
    else:
        role_list = Role.objects.all()
        user_list = UserInfo.objects.all()
        user_form = RegistrationForm()
        userinfo_form = UserInfoForm()
        return render(
            request, "system/user.html", {
                "user_list": user_list,
                "form": user_form,
                "userinfo": userinfo_form,
                "role_list": role_list
            })
Exemplo n.º 2
0
def register(request):

    REGISTERED = False

    if request.method == 'POST':

        user_info = UserInfoForm(request.POST)

        if user_info.is_valid():

            user = user_info.save(commit=False)
            user.set_password(user.password)
            user.is_active = False
            user.save()

            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string(
                'login/acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            to_email = user_info.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()

            REGISTERED = True
            return render(request, 'login/registration_done.html')
        else:
            print(user_info.errors)
    else:

        user_info = UserInfoForm()

    return render(request, 'login/register.html', {
        'user_info': user_info,
        'registered': REGISTERED
    })
Exemplo n.º 3
0
def uc_data(request):
    """
    用户中心-个人资料
    """
    menu = 'data'
    unread = get_unread_list(request.user)
    if request.method == 'POST':
        form = UserInfoForm(request.POST, instance=request.user)
        if form.is_valid():
            # form.save(update_fields=['nick_name','email','gender','bio','signature'])
            f = form.save(commit=False)
            f.save(update_fields=[
                'nick_name', 'email', 'gender', 'bio', 'signature'
            ])
    else:
        form = UserInfoForm(instance=request.user)

    return render_to_response('account/data.html', {
        'config': config,
        'menu': menu,
        'unread': unread,
        'form': form
    },
                              context_instance=RequestContext(request))