コード例 #1
0
ファイル: views.py プロジェクト: Pedrexus/Vision1500
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)

            message = render_to_string(
                'registration/account_activation_email.html', {
                    'user':
                    user,
                    'domain':
                    current_site.domain,
                    'uid':
                    urlsafe_base64_encode(force_bytes(
                        user.pk)).decode("utf-8"),
                    'token':
                    account_activation_token.make_token(user),
                })

            subject = 'Activate Your MySite Account'
            user.email_user(subject, message)

            return render(request, 'registration/account_activation_sent.html',
                          {'user': user})
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
コード例 #2
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)
            subject = 'Activate Your MySite Account'
            message = render_to_string(
                'registration/account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            from_email = [settings.EMAIL_HOST_USER]
            to_email = [user.email]
            send_mail(subject=subject,
                      from_email=from_email,
                      recipient_list=to_email,
                      message=message,
                      fail_silently=False)

            return redirect('/account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
コード例 #3
0
ファイル: views.py プロジェクト: varuhait/mining_web
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect(to='/board')
    else:
        form = SignUpForm()
    return render(request, 'registration.html', {'form': form})
コード例 #4
0
def signup(request):
    # POST requests are usually used for submissions
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        # call the form’s is_valid() method
        if form.is_valid():
            # If is_valid() is True, we’ll be able to find all the validated form data in its cleaned_data attribute
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            # redirect to the page where the user can see that his signing up was successful
            # in the urls.py has to be specified where to find the template that should be shown under:
            return redirect('/registration/done')
    else:
        form = SignUpForm()
        # folder where the signup.html template can be found
    return render(request, 'registration/signup.html', {'form': form})
コード例 #5
0
 def test_sets_username_to_email(self):
     data = {
         "email": "*****@*****.**",
         "first_name": "Foo",
         "last_name": "Bar",
         "password1": "abcdef456",
         "password2": "abcdef456",
     }
     form = SignUpForm(data=data)
     self.assertTrue(form.is_valid())
     user = form.save()
     self.assertEqual(user, User.objects.first())
     self.assertEqual(user.username, user.email)
     self.assertEqual(user.email, data["email"])
コード例 #6
0
ファイル: views.py プロジェクト: Saptorshi7/daydreams
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            username = form.cleaned_data.get('username')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            auth_login(request, user)
            return redirect('welcome')
    else:
        form = SignUpForm()
    return render(request, 'index.html', {'form': form})
コード例 #7
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()  # load the profile instance created by the signal
            user.profile.phone = form.cleaned_data.get('phone')
            user.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
コード例 #8
0
ファイル: views.py プロジェクト: LECARROU/gom-jabbar
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db(
            )  # load the profile instance created by the signal
            # user.customers.pseudo = form.cleaned_data.get('pseudo')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect('registration:profile')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
コード例 #9
0
def signup(request):
    """Create a new unactivated user in the db for a potential new user."""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            # This is needed to force the user to rely on the email
            # confirmation. Otherwise, the user can log in without the
            # confirmation email.
            user.is_active = False
            # user_name = f"{user.first_name}_{user.last_name}"
            # Creates new user object in the database.
            user.save()

            # Load the profile instance created by the signal
            # Needed to save the profile details of the user.
            user.refresh_from_db()
            # Save again, to save the new changes made to the user's profile
            user.save()

            # Without this the user will not belong to any group.
            # Newly signed up users can only be customers. Otherwise, they have
            # to have an account created to them by the admin/staff manually.
            group = Group.objects.get(name="Inquirers")
            group.user_set.add(user)

            current_site = get_current_site(request)
            subject = 'Activate Your Questions & Answers Account'
            message = render_to_string('account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
                'token': account_activation_token.make_token(user),
            })
            user.email_user(subject, message)

            return redirect("account_activation_sent")
    else:
        form = SignUpForm()

    return render(request, 'signup.html', {'form': form})
コード例 #10
0
    def post(self, request, *args, **kwargs):
        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)
            subject = "Activate Your Skagit BMC Account"
            email_context = {
                "user": user,
                "protocol": request.scheme,
                "domain": current_site.domain,
                "uid": urlsafe_base64_encode(force_bytes(user.pk)),
                "token": account_activation_token.make_token(user),
            }
            text_message = render_to_string(
                "registration/account_activation_email.txt", email_context)
            html_message = render_to_string(
                "registration/account_activation_email.html", email_context)
            user.email_user(subject, text_message, html_message=html_message)
            return redirect("account_activation_sent")

        else:
            return render(request, "registration/signup.html", {"form": form})