Beispiel #1
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(data=request.POST)
        if form.is_valid():
            user = form.create_user()
            django_login(request, user)
            return redirect('member:main')
    else:
        form = SignupForm()
    context = {
        'form': form,
    }
    return render(request, 'member/signup.html', context)
Beispiel #2
0
def signup(request):
    # member/signup.html을 사용
    #   1. username, password1, passwords2를 받아 회원가입.
    #   2. 기존에 존재하는 유저인지 검사
    #   3. password1, 2가 일치하는지 검사
    #   4. 각각의 경우를 검사해서 틀릴 경우 오류메시지 리턴
    #   5. 가입성공시 로그인시키고 post_list로 redirect

    if request.method == "POST":

        ### Form을 사용하지 않는 경우
        # form = SignupForm(data=request.POST)
        # username = request.POST['username']
        # password1 = request.POST['password1']
        # password2 = request.POST['password2']
        # if User.objects.filter(username=username).exists():
        #     return HttpResponse('Username is already exists')
        # elif password1 != password2:
        #     return HttpResponse('패스워드가 다릅니다.'.format(username))
        #
        # user = User.objects.create_user(username=username, password=password1)


        ### Form을 사용한 경우
        form = SignupForm(data=request.POST)
        if form.is_valid():
            user = form.create_user()
            print("유저 누구? ", user)
            # 위에서 생성한 유저를 로그인 시킨 후, post_list뷰로 이동
            django_login(request, user)
            return redirect("posts:post_list")

    else:
        form = SignupForm()
    context = {
        'form': form
    }
    return render(request, 'member/signup.html', context)
Beispiel #3
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.create_user()
            current_site = get_current_site(request)
            message = render_to_string(
                'acc_activate_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            mail_subject = 'Hello! Welcome to WeatherSound. Please activate your account.'
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )
    else:
        form = SignupForm()

    return render(request, 'signup.html', {'form': form})