Exemplo n.º 1
0
def register(request):
    form = UserRegisterForm(request.POST or None)
    # next_ = request.GET.get('next')
    # next_post = request.POST.get('next')
    # redirect_path = next_ or next_post or None
    if form.is_valid() and request.recaptcha_is_valid:
        # email  = form.cleaned_data.get('email')
        password = form.cleaned_data.get('password2')
        user = form.save(commit=False)
        user.set_password(password)
        user.active = False
        user.save()
        current_site = get_current_site(request)
        subject = 'Activate Your HomeShop Account'
        message = render_to_string(
            'account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
        user.email_user(subject, message)
        return redirect('account_activation_sent')
        # new_user = authenticate(username=email, password=password)
        # if user:
        #     login(request, new_user)
        #     messages.success(request,f"An account has been created with {email}")
        #     if is_safe_url(redirect_path, request.get_host()):
        #         return redirect(redirect_path)
        #     return redirect('/')
    return render(request, "accounts/register.html", {'form': form})
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST)
        if form.is_valid():

            user = form.save(commit=False)
            user.is_active = False  # Deactivate account till it is confirmed
            user.save()

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

            messages.success(
                request,
                ('Please Confirm your email to complete registration.'))

            return redirect('login')

        return render(request, self.template_name, {'form': form})
Exemplo n.º 3
0
 def post(self, request):
     form = SignUpForm(request.POST)
     if form.is_valid():
         user = form.save()
         current_site = get_current_site(request)
         subject = 'Activate Your Privalytics Account'
         message = render_to_string(
             'emails/account_activation.txt', {
                 'user':
                 user,
                 'domain':
                 current_site.domain,
                 'uid':
                 urlsafe_base64_encode(force_bytes(
                     user.pk)).decode('utf-8'),
                 'token':
                 account_activation_token.make_token(user),
             })
         user.email_user(subject,
                         message,
                         from_email='Privalytics <*****@*****.**>')
         user.profile.account_selected = request.session.get('account_type')
         user.save()
         user.profile.save()
         auth_login(request,
                    user,
                    backend='django.contrib.auth.backends.ModelBackend')
         return redirect('account')
     return render(request, self.template_name, {'form': form})
Exemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False  # Deactivate account till it is confirmed
            user.save()

            current_site = get_current_site(request)
            subject = 'Activate Your RRBN Portal Account'
            from_email = settings.DEFAULT_FROM_EMAIL
            to_email = [form.cleaned_data.get('email')]
            message = render_to_string(
                'accounts/activation_request.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            send_mail(subject,
                      message,
                      from_email,
                      to_email,
                      fail_silently=True)

            messages.success(
                request,
                ('Please Confirm your email to complete registration.'))

            return render(request, self.template_name1)

        return render(request, self.template_name, {'form': form})
Exemplo n.º 5
0
def signup_view(request):
    if request.method == "POST":
        form = UserRegisterForm(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 blog account.'
            message = render_to_string(
                '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, 'confirm_registration.html', {'form': form})
            # Now, You Signed up :)
            # login(request, user)
    else:
        form = UserRegisterForm()
    return render(request, 'signup.html', {'form': form})
Exemplo n.º 6
0
def signup_view(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            user.profile.first_name = form.cleaned_data.get('first_name')
            user.profile.last_name = form.cleaned_data.get('last_name')
            user.profile.email = form.cleaned_data.get('email')
            # user can't login until link confirmed
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = 'Please Activate Your Account'
            # load a template like get_template()
            # and calls its render() method immediately.
            message = render_to_string(
                'accounts/activation_request.html',
                {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    # method will generate a hash value with user related data
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
            return redirect('activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'accounts/signup.html', {'form': form})
Exemplo n.º 7
0
    def post(self, request):
        form = self.form_class(request.POST)

        # Check form validation
        if form.is_valid():
            data = form.cleaned_data

            # Create user
            user = User.objects.create(email=data.get('email'))
            user.set_password(data.get('password2'))
            user.is_active = False
            user.save()

            # Generate and send letter to user email
            current_site = get_current_site(request)
            subject = 'Activate Your Account'

            message = loader.render_to_string(
                'activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'id': user.pk,
                    'token': account_activation_token.make_token(user),
                    'protocol': 'http',
                })

            user.email_user(subject, message)

            return redirect('accounts:activation_sent')

        else:
            return render(request, self.template_name, {'form': form})
Exemplo n.º 8
0
    def form_valid(self, form):

        user = form.save(commit=False)
        user.is_active = False
        user.save()

        ## Send confirmation message
        current_site = get_current_site(self.request)
        message = render_to_string(
            'activate/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),
            })
        # # Sending activation link in terminal
        # user.email_user(subject, message)
        mail_subject = 'Activate your freeLearnAcademy account.'
        to_email = form.cleaned_data.get('email')

        print(f"\n\n {to_email} \n\n")

        email = EmailMessage(mail_subject, message, to=[to_email])
        email.send()

        return render(self.request, 'activate/acc_active_sent.html')
Exemplo n.º 9
0
    def create(self, validatedData):
        username = validatedData['username']
        email = validatedData['email']
        password = validatedData['password']
        userObj = User(username=username, email=email)
        userObj.set_password(password)
        userObj.is_active = False
        userObj.save()
        subject = 'Activate Your Touricted Account'
        message = render_to_string(
            'account_activation_email.html', {
                'user': userObj,
                'domain': 'localhost:8000',
                'uid': urlsafe_base64_encode(force_bytes(userObj.pk)),
                'token': account_activation_token.make_token(userObj),
            })

        to = email
        print(message, 'message')
        # userObj.email_user(subject, message)
        SendEmail.send_email_varification_mail(to, subject, message)

        validatedData['username'] = userObj.username

        return validatedData
Exemplo n.º 10
0
    def form_valid(self, form):

        user = form.save(commit=False)
        user.is_active = False
        user.save()

        request = self.request

        domain = get_current_site(request).domain

        subject = render_to_string(self.subject_template_name, {
            'domain': domain,
            'user': user
        })

        activate_url = reverse('accounts:activate',
                               kwargs={
                                   'uidb64': (urlsafe_base64_encode(
                                       force_bytes(user.pk)).decode("utf-8")),
                                   'token':
                                   account_activation_token.make_token(user)
                               })

        message = render_to_string(
            self.email_template_name, {
                'user': user,
                'domain': domain,
                'activate_url': request.build_absolute_uri(activate_url)
            })

        user.email_user(subject, '', html_message=message)

        messages.success(self.request, self.success_message)

        return redirect(self.success_url)
Exemplo n.º 11
0
def send_activation_email(user, request):
    current_site = get_current_site(request)
    mail_subject = 'Activate your DM Apps account / Activez votre compte Applications GD'
    message = render_to_string(
        'registration/acc_active_email.html', {
            'user': user,
            'domain': current_site.domain,
            'uid': force_text(urlsafe_base64_encode(force_bytes(user.pk))),
            'token': account_activation_token.make_token(user),
        })
    to_email = user.email
    from_email = settings.SITE_FROM_EMAIL
    custom_send_mail(
        html_message=message,
        subject=mail_subject,
        recipient_list=[
            to_email,
        ],
        from_email=from_email,
    )
    messages.success(
        request,
        _('A verification email was just send to {email_address}. In order to complete your registration, please follow the link'
          ' in the message. <br><br>If the email does not appear within 1-2 minutes, please be sure to check your junk mail folder. '
          '<br><br>The activation link will only remain valid for a limited period of time.'
          ).format(email_address=to_email))
Exemplo n.º 12
0
def register(request):
    if request.method == 'POST':
        user_form = RegistrationForm(request.POST, request.FILES)
        profile_form = HomeForm(request.POST, request.FILES or None)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.refresh_from_db()  # This will load the Profile created by the Signal
            profile_form = HomeForm(request.POST, instance=user.userprofile)  # Reload the profile form with the profile instance
            profile_form.full_clean()  # Manually clean the form this time. It is implicitly called by "is_valid()" method
            profile_form.save()  # Gracefully save the form
            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            message = render_to_string('accounts/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(reverse_lazy('account_activation_sent'))

    else:
        user_form = RegistrationForm()
        profile_form = HomeForm()
    return render(request, 'accounts/reg_form.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Exemplo n.º 13
0
    def send_activation_email(self, user, serializer):

        create_token(self.token_model, user, serializer)

        token = account_activation_token.make_token(user)

        params = {
            'uid': urlsafe_base64_encode(force_bytes(user.pk)),
            'token': token
        }

        confirmation_link = settings.FRONTEND_URL + "/#/confirm?" + urllib.parse.urlencode(
            params)

        context = {
            'username': user.username,
            'confirmation_link': confirmation_link,
            'service_name': "DummyService"
        }

        message = Mail(from_email='*****@*****.**',
                       to_emails=user.email,
                       subject='Thank you for registration',
                       html_content=render_to_string(
                           "account/email/confirmation_mail.html", context))
        try:
            sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
            response = sg.send(message)
            print(response.status_code)
            print(response.body)
            print(response.headers)
        except Exception as e:
            print(e)
Exemplo n.º 14
0
def resendemail(request):
    current_site = get_current_site(request)
    request.user.verification_code = '{0:04}'.format(random.randint(1, 9999))
    request.user.save()
    context = {
        'user': request.user,
        'domain': current_site.domain,
        'uid': urlsafe_base64_encode(force_bytes(request.user.pk)).decode(),
        'token': account_activation_token.make_token(request.user),
        'url': '/accounts/activate/',
        'resendemail': True
    }
    message = render_to_string('frontend/core/acc_active_email.html', context)

    mail_subject = 'Activate your account.'
    to_email = request.user.email

    email_message = EmailMultiAlternatives(mail_subject, message,
                                           settings.EMAIL_HOST_USER,
                                           [to_email])
    html_email = render_to_string('frontend/core/acc_active_email.html',
                                  context)
    email_message.attach_alternative(html_email, 'text/html')
    email_message.send()

    messages.add_message(
        request, messages.INFO,
        'Email sent for verification, please activate you account on link sent to your email'
    )

    return HttpResponse('sent')
Exemplo n.º 15
0
def new_signup(request):
    now = datetime.date.today()
    os_object = OperationScheme.objects.latest('id')
    if now < os_object.new_register_start() or now > os_object.new_register_end:
        return render(request, 'accounts/user_register_not_now.html')
    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 = '[Caffe人] 서울대학교 재학생 인증 메일입니다.'
            mail_content = render_to_string('accounts/acc_active_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': user.id,
                'token': account_activation_token.make_token(user),
            })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, mail_content, to=[to_email])
            email.send()
            return HttpResponse('이메일을 확인해주세요.')
    else:
        form = SignUpForm()
    return render(request, 'accounts/user_register.html', {'form': form})
Exemplo n.º 16
0
    def post(self, request, *args, **kwrags):
        signup_form = SignUpForm(request.POST)
        if signup_form.is_valid():
            user = signup_form.save()
            user.refresh_from_db()
            user.user_profile.phone_number = signup_form.cleaned_data.get(
                'phone_number')
            user.user_profile.city = signup_form.cleaned_data.get('city')
            user.save()

            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            message = render_to_string('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),
            })
            user.email_user(subject, message)
            messages.success(
                request, ('Registration Completed.Please Confirm Your Email Address'))
            return redirect('accounts:login')
        else:
            context = {
                'signup_form': signup_form,
                'title': 'Register'
            }
            return render(request, 'accounts/register.html', context)
Exemplo n.º 17
0
def signup(request):
    auth = authenticated(request)
    if auth is not None:
        return auth
    else:
        if request.method == "POST":
            form = SignUpForm(request.POST)
            if form.is_valid():
                user = form.save(commit=False)
                current_site = get_current_site(request)
                mail_subject = '[Rhys Website] Activate your Rhys Website account.'
                message = render_to_string(
                    'accounts/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()
                user.is_active = False
                user.save()
                # auto_login(request, user)

                return render(request, 'accounts/signup_done.html',
                              {'form': form})

        else:
            form = SignUpForm()
        return render(request, 'accounts/signup.html', {'form': form})
def ragister_view(request):
    form = RegistrationForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            if email and User.objects.filter(email=email):
                messages.error(request, "Email addresses must be unique.")
                return render(request, 'accounts/login.html')
            user = form.save()
            username = form.cleaned_data.get('username')
            print(username)
            #login(request, user)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = 'Please Activate Your Account'
            # load a template like get_template()
            # and calls its render() method immediately.
            message = render_to_string(
                'accounts/activation_request.html',
                {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    # method will generate a hash value with user related data
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            send_mail(subject, message, '*****@*****.**',
                      [to_email])
            return redirect('activation_sent')
        else:
            messages.error(request, "username must be unique.")
    return render(request, "accounts/login.html")
Exemplo n.º 19
0
def signup(request):
    form = SignUpForm(request.POST or None)
    if form.is_valid():
        user = form.save()
        user_email = form.cleaned_data['email']
        user.save()

        # send confirmation email
        token = account_activation_token.make_token(user)
        user_id = urlsafe_base64_encode(force_bytes(user.id))
        url = BASE_URL + reverse('accounts:confirm-email',
                                 kwargs={
                                     'user_id': user_id,
                                     'token': token
                                 })
        message = get_template(
            'accounts/account_activation_email.html').render(
                {'confirm_url': url})
        mail = EmailMessage('Fagrimacs Account Confirmation',
                            message,
                            to=[user_email],
                            from_email=settings.EMAIL_HOST_USER)
        mail.content_subtype = 'html'
        mail.send()

        return render(
            request, 'accounts/registration_pending.html', {
                'message': ('A confirmation email has been sent to your email'
                            '. Please confirm to finish registration.')
            })
    return render(request, 'accounts/signup.html', {
        'form': form,
    })
Exemplo n.º 20
0
    def form_valid(self, form):

        try:
            with transaction.atomic():
                # create record for new user to track activation
                user = form.save(commit=False)
                user.is_active = False
                user.save()
                self.object = user

                current_site = get_current_site(self.request)

                # construct the account verification email
                subject = "Activate your HydroLearn.org Account"
                message = render_to_string('/accounts/registration/account_activation_email.html', {
                        'user': user,
                        'domain':current_site.domain,
                        'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                        'token': account_activation_token.make_token(user)
                    })


                # send email to supplied email address
                user.email_user(subject,message)

                return HttpResponseRedirect("{0}?u={1}".format(self.get_success_url(), user.get_username()))
                #return redirect(self.get_success_url(), context={'username':user.username})

        except:
            return render(self.request, '/accounts/registration/account_activation_invalid.html')
Exemplo n.º 21
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.active = False
            user.save()

            current_site = get_current_site(request)
            mail_subject = 'Activate Your Library Account'
            message = render_to_string(
                'account_activation_email.html',
                {
                    'user': user,
                    #'domain': current_site.domain,
                    'domain': 'localhost:8000',
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            #user.email_user(subject, message)
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            #return redirect('account_activation_sent')
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
Exemplo n.º 22
0
def Registration(request):
    if request.method=="POST":
        form=RegistrationForm(request.POST)
        if form.is_valid():
            user=form.save(commit=False)
            user.is_active=False
            user.save()
            #============Emailing======
            current_site=get_current_site(request)
            mail_subject="Activate your blog account."
            message=render_to_string('activation_email.html',{
            'user':user,
            'domain':current_site.domain,
            'uid':urlsafe_base64_encode(force_bytes(user.pk)),
            'token':account_activation_token.make_token(user),
            })
            to_mail=form.cleaned_data.get('email')
            email=EmailMessage(
            mail_subject,message,to=[to_mail]
            )
            email.send()
            return HttpResponse('Please confirm your email address to complete the Registration')

    else:
        form=RegistrationForm()
    context={
    'form':form
    }
    return render(request,'accounts/register.html',context)
Exemplo n.º 23
0
def signup_user(request):
    login_form = AuthenticationForm(request)

    if request.method == 'POST':
        signup_form = SignUpForm(request.POST)
        if signup_form.is_valid():
            user = signup_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(
                'account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
    else:
        signup_form = SignUpForm()

    context = {'form': signup_form}
    return render(request, 'signup.html', context)
Exemplo n.º 24
0
def signup(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect(reverse('profile_user'))
    else:
        if request.method == 'POST':
            form = MyCustomUserCreationForm(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 = 'Активация акаунта.'
                message = render_to_string(
                    '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 HttpResponse(
                    u'Пожалуйста подтвердите свой email. Инструкции отправлены на email'
                )
        else:
            form = MyCustomUserCreationForm()
        return render(request, 'signup.html', {'form': form})
Exemplo n.º 25
0
 def post(self, request, *args, **kwargs):
     """Manage POST method."""
     form = self.form_class(request.POST)
     if form.is_valid():
         user = form.save()
         if user.is_teacher:
             Teacher.objects.create(user=user)
         elif user.is_school:
             School.objects.create(user=user)
         uid = urlsafe_base64_encode(force_bytes(user.pk))
         token = account_activation_token.make_token(user.pk)
         email_context = {
             "token": token,
             "uid": uid,
             "domain": get_current_site(request).domain
         }
         mail = EmailMessage(
             "Melomnia: Confirmation de l'inscription",
             render_to_string(self.email_template, context=email_context),
             '*****@*****.**', [user.email])
         mail.content_subtype = "html"
         mail.send()
         return render(request, "accounts/signup-email.html")
     else:
         context = {"form": form}
         return render(request, self.template_name, context)
Exemplo n.º 26
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST)
        print(form)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            to_email = form.cleaned_data['email']
            form.save()

            subject = 'Activate your account.'
            current_site = get_current_site(request)
            message = render_to_string(
                'registration/activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        form.instance.pk)),
                    'token': account_activation_token.make_token(form.instance)
                })
            email = EmailMessage(subject, message, to=[
                to_email,
            ])
            email.send()
            return redirect(self.success_url)
        else:
            form = self.form_class()
            return form
Exemplo n.º 27
0
def register(request):
    if request.method == 'POST':
        form = UserRegisterForm(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 blog account.'
            message = render_to_string('accounts/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()
            # username = form.cleaned_data.get('username')
            # messages.success(request, f'Your account has been created! You are now can login {username}!')
            return render(request, 'accounts/mail_state.html', {'title': 'Please confirm your email address to complete the registration'})
    else:
        form = UserRegisterForm()

    return render(request, 'accounts/register.html', {'form': form})
Exemplo n.º 28
0
 def test_activate_user_email_invalid(self):
     user = self.initialize_user(is_active=False, email_verified=False)
     uid = urlsafe_base64_encode(force_bytes('grabage'))
     token = account_activation_token.make_token(user)
     self.client.get(reverse('auth:activate', args=[uid, token]))
     user.refresh_from_db()
     self.assertFalse(user.profile.email_verified)
     self.assertFalse(user.is_active)
Exemplo n.º 29
0
 def setUp(self):
     user = UserFactory(is_active=False)
     self.profile = ProfileFactory(user=user)
     uidb64 = urlsafe_base64_encode(force_bytes(self.profile.user.pk))
     token = account_activation_token.make_token(self.profile.user)
     self.url = reverse_lazy('activate',
                             kwargs={
                                 'uidb64': uidb64,
                                 'token': token
                             })
Exemplo n.º 30
0
    def post(self, request, *args, **kwargs):
        signup_form = SignUpForm(request.POST)
        context = {'signup_form': signup_form, 'title': 'Register'}
        if signup_form.is_valid():
            user = signup_form.save()
            user.refresh_from_db()
            user.user_profile.phone_number = signup_form.cleaned_data.get(
                'phone_number')
            user.user_profile.address = signup_form.cleaned_data.get('address')
            user.user_profile.user_type = signup_form.cleaned_data.get(
                'user_type')
            # user.user_profile.bio = signup_form.cleaned_data.get('bio')
            user.save()
            if signup_form.cleaned_data.get('user_type') == '0':
                department_id = request.POST.get('department')
                department_obj = get_object_or_404(Department,
                                                   id=department_id)

                faculty_id = request.POST.get('faculty')
                faculty_obj = get_object_or_404(Faculty, id=faculty_id)

                Teacher.objects.create(teacher=user,
                                       department=department_obj,
                                       faculty=faculty_obj)

            elif signup_form.cleaned_data.get('user_type') == '1':
                department_id = request.POST.get('department')
                department_obj = get_object_or_404(Department,
                                                   id=department_id)

                faculty_id = request.POST.get('faculty')
                faculty_obj = get_object_or_404(Faculty, id=faculty_id)

                Student.objects.create(student=user,
                                       department=department_obj,
                                       faculty=faculty_obj)
            # raw_password = form.cleaned_data.get('password1')
            # user = authenticate(username=user.username, password=raw_password)
            # login(request, user)
            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            message = render_to_string(
                '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),
                })
            user.email_user(subject, message)
            messages.success(
                request,
                ('Registration Completed.Please Confirm Your Email Address'))
            return redirect('accounts:login')
        else:
            return render(request, 'accounts/register.html', context)