Example #1
0
    def singup(self):
        if self.method == 'POST':
            form = UserCreationForm(self.POST)
            if form.is_valid():
                email = form.cleaned_data.get('email')
                username = form.cleaned_data.get('username')

                raw_password = form.cleaned_data.get('password')
                digits = "".join([
                    random.choice(string.digits + string.ascii_letters)
                    for i in range(10)
                ])
                email = EmailMessage(
                    'Hello',
                    'http://*****:*****@gmail.com'])  # fill this param

                email.send()
                form.link = digits
                form.save()
                user = authenticate(username=username, password=raw_password)
                # login(self, user)
                # user.save()
                return HttpResponseRedirect('/accounts/login')
        else:
            form = UserCreationForm()

        return render(self, 'account/signup.html', {'form': form})
Example #2
0
def signup(request):

    # 이미 로그인한 상태 -> redirect
    if request.user.is_anonymous:
        pass
    elif request.user:
        return HttpResponseRedirect('/')

    template = 'account/signup.html'
    signup_form = UserCreationForm()
    message = ""

    # form 작성 후 post 액션 시
    if request.method == "POST":
        signup_form = UserCreationForm(request.POST, request.FILES or None)
        if signup_form.is_valid():
            user = signup_form.save(commit=False)
            user.save()

            # 계정 활성화 과정 필요
            # return HttpResponse('Please confirm your email address to complete the registration')
            # return HttpResponse('회원가입 성공!')
            context = {"message": '회원가입 성공!'}
            return render(request, 'account/signup_success.html', context)
        else:
            message = "비밀번호 미일치"

    elif request.method == "GET":
        pass

    context = {"signupForm": signup_form, "message": message}
    return render(request, template, context)
Example #3
0
def sign_up(request):
    form = UserCreationForm()
    if request.POST:
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect("home")
    return render(request, "account/sign_up.html", {"form": form})
Example #4
0
def sign_up(request):
    form = UserCreationForm(request.POST)
    if form.is_valid():
        user = User.objects.create_user(
            username=form.cleaned_data.get('username'),
            email=form.cleaned_data.get('email'),
            password=form.cleaned_data.get('password2'))
        setup_new_user(user)
        login(request, user)
        return JsonResponse(user.to_user())
    else:
        return JsonResponse(form.errors, status=400)
Example #5
0
def signup(request):

    # 기로그인 -> redirect
    if request.user.is_anonymous:
        pass
    elif request.user:
        # return HttpResponseRedirect('/portfolios/')
        return HttpResponseRedirect('/')

    template = 'registration/signup.html'
    signupForm = UserCreationForm()
    message = ""

    # form 작성 후 post 액션 시
    if request.method == "POST":
        signupForm = UserCreationForm(request.POST, request.FILES or None)
        if signupForm.is_valid():
            user = signupForm.save(commit=False)
            user.save()
            """Create a portfolio for this user"""
            Portfolio.make_portfolio(user)

            # 계정 활성화를 위한 이메일 인증
            current_site = get_current_site(request)

            mail_subject = render_to_string(
                'registration/activation_email_subject.txt')
            mail_message = render_to_string(
                'registration/activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                    'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
                })
            to_email = signupForm.cleaned_data.get('email')

            email = EmailMessage(mail_subject, mail_message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )
        else:
            message = "패스워드 미일치"

    elif request.method == "GET":
        pass

    context = {"signupForm": signupForm, "message": message}
    return render(request, template, context)
Example #6
0
def signup(request):
    template_name = 'system/signup.html'
    form = UserCreationForm(request.POST or None)
    if form.is_valid():
        form.save()
        print("hi from form sis valid")
        return redirect('system:userlogin')
    else:
        print("hi from form is not valid")
    context = {
        'title': 'sign up',
        'forms': form,
    }
    return render(request, template_name, context)
Example #7
0
 def signup(request):
     if request.method == 'POST':
         data = request.POST.copy()
         form = UserCreationForm(data)
         if form.is_valid():
             user = form.save()
             email = form.cleaned_data.get('email')
             raw_password = form.cleaned_data.get('password1')
             user = authenticate(email=email, password=raw_password)
             auth_login(request, user)
             return redirect('/')
     else:
         form = UserCreationForm()
     return render(request, 'account/signup.html', {'form': form})
Example #8
0
def member_register(request):
    _next = request.GET.get('next', reverse('index'))

    if request.user.is_authenticated():
        return redirect(_next)

    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            UserExtra.objects.create(user=user)
            # https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.login
            auth_user = authenticate(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1']
            )
            login(request, auth_user)
            return redirect(_next)
        else:
            return render(request, 'account/register_form.html', {'form': form})

    form = UserCreationForm()
    return render(request, 'account/register_form.html', {'form': form})