Exemplo n.º 1
0
def signup(request):
    if request.method == 'POST':
        # (기본)
        # username = request.POST.get('username')
        # password = request.POST.get('password')
        # (기본)
        form = SignupForm(request.POST, request.FILES)
        # (기본)
        # if username and password:
        # (기본)
        if form.is_valid():
            # 주어진 username의 User가 존재하는지 검사
            # if User.objects.filter(username=username).exists():
            #     return HttpResponse(f'Username {username} is already exist')
            # 없으면 User 생성
            user = form.save()
            # user = form.signup()
            dj_login(request, user)
            return redirect('main')
    else:
        form = SignupForm()
    context = {
        'form': form,
    }
    return render(request, 'member/signup.html', context)

# def user_post(request):
#     post = Post.objects.filter(author=request.user)
Exemplo n.º 2
0
def signup_view(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('posts:post-list')
    else:
        form = SignupForm()

    context = {
        'form': form,
    }
    return render(request, 'members/signup.html', context)
Exemplo n.º 3
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST, request.FILES)
        if form.is_valid():
            user = form.save()
            login(request,
                  user,
                  backend='django.contrib.auth.backends.ModelBackend')
            return redirect('post:post_list')
    else:
        form = SignupForm
    context = {
        'form': form,
    }
    return render(request, 'member/signup.html', context)
Exemplo n.º 4
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string('registration/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 = form.cleaned_data.get('email')
            email = EmailMessage(
                mail_subject, message, to=[to_email]
            )
            email.send()
            return render(request, 'registration/notice-page.html')
    else:
        form = SignupForm()
    return render(request, 'registration/signup.html', {'form': form})