示例#1
0
文件: views.py 项目: vesellov/zenaida
 def get_redirect_url(self, *args, **kwargs):
     activation_obj = Activation.objects.filter(
         code=kwargs.get('code')).first()
     if not activation_obj:
         messages.error(self.request, 'Activation code is not correct')
         return super().get_redirect_url()
     # Remove activation code if it's created more than 24 hours ago.
     activation_code_time_passed = datetime.now(
         timezone.utc) - activation_obj.created_at
     if activation_code_time_passed.total_seconds() > 60 * 60 * 24:
         activation_obj.delete()
         messages.error(self.request,
                        'Activation code is not valid anymore')
         return super().get_redirect_url()
     # Activate user's profile if it's not already activated.
     user = activation_obj.account
     if user.is_active:
         messages.warning(self.request, 'Your account is already activated')
         return super().get_redirect_url()
     user.is_active = True
     user.save()
     messages.success(self.request,
                      'You have successfully activated your account')
     login(self.request, user)
     # If user do not have a profile yet need to create it for him.
     try:
         user.profile
     except ObjectDoesNotExist:
         create_profile(user, contact_email=user.email)
     return super().get_redirect_url()
示例#2
0
    def form_valid(self, form):
        if self.request.recaptcha_is_valid or not settings.GOOGLE_RECAPTCHA_SITE_KEY:
            if settings.ENABLE_USER_ACTIVATION:
                user = form.save(commit=False)
                user.is_active = False
                user.save()

                form.send_activation_email(self.request, user)

                messages.add_message(
                    self.request, messages.SUCCESS,
                    'You are registered. To activate the account, follow the link sent to the mail.'
                )
            else:
                form.save()

                email = form.cleaned_data.get('email')
                raw_password = form.cleaned_data.get('password1')

                user = authenticate(username=email, password=raw_password)
                login(self.request, user)
                create_profile(user, contact_email=email)

                messages.add_message(self.request, messages.SUCCESS,
                                     'You are successfully registered!')
            return super().form_valid(form)
        else:
            return self.render_to_response(self.get_context_data(form=form))
示例#3
0
 def dispatch_wrapper(self, request, *args, **kwargs):
     if self.request.user.is_authenticated:
         if not hasattr(request.user, 'profile'):
             zusers.create_profile(request.user, contact_email=request.user.email)
         if not request.user.profile.is_complete() or not request.user.registrants.count():
             messages.info(request, 'Please provide your contact information to be able to register new domains')
             return shortcuts.redirect('account_profile')
     return dispatch_func(self, request, *args, **kwargs)
示例#4
0
    def get_redirect_url(self, *args, **kwargs):
        # TODO: change assert to raise
        assert 'code' in kwargs

        # TODO: display nice 404 page
        act = get_object_or_404(Activation, code=kwargs['code'])

        # Activate user's profile
        user = act.account
        user.is_active = True
        user.save()

        # Remove activation record, it is unneeded
        act.delete()

        messages.add_message(self.request, messages.SUCCESS,
                             'You have successfully activated your account!')
        login(self.request, user)

        # If user do not have a profile yet need to create it for him.
        try:
            user_profile = user.profile
        except ObjectDoesNotExist:
            user_profile = create_profile(user, contact_email=user.email)

        return super().get_redirect_url()
示例#5
0
 def doDBCheckCreateUserAccount(self, *args, **kwargs):
     """
     Action method.
     """
     if self.known_registrant:
         logger.info(
             'registrant already known so skip creating user account')
         return
     known_owner = zusers.find_account(
         self.current_registrant_info['email'])
     if not known_owner:
         known_owner = zusers.create_account(
             email=self.current_registrant_info['email'],
             account_password=zusers.generate_password(length=10),
             also_profile=True,
             is_active=True,
             person_name=self.current_registrant_address_info.get(
                 'name', 'unknown'),
             organization_name=self.current_registrant_address_info.get(
                 'org', 'unknown'),
             address_street=self.current_registrant_address_info.get(
                 'street', 'unknown'),
             address_city=self.current_registrant_address_info.get(
                 'city', 'unknown'),
             address_province=self.current_registrant_address_info.get(
                 'sp', 'unknown'),
             address_postal_code=self.current_registrant_address_info.get(
                 'pc', 'unknown'),
             address_country=self.current_registrant_address_info.get(
                 'cc', 'AF'),
             contact_voice=zcontacts.extract_phone_number(
                 self.current_registrant_info.get('voice', '')),
             contact_fax=zcontacts.extract_phone_number(
                 self.current_registrant_info.get('fax', '')),
             contact_email=self.current_registrant_info['email'],
         )
     if not hasattr(known_owner, 'profile'):
         zusers.create_profile(
             known_owner,
             person_name=self.current_registrant_address_info.get(
                 'name', 'unknown'),
             organization_name=self.current_registrant_address_info.get(
                 'org', 'unknown'),
             address_street=self.current_registrant_address_info.get(
                 'street', 'unknown'),
             address_city=self.current_registrant_address_info.get(
                 'city', 'unknown'),
             address_province=self.current_registrant_address_info.get(
                 'sp', 'unknown'),
             address_postal_code=self.current_registrant_address_info.get(
                 'pc', 'unknown'),
             address_country=self.current_registrant_address_info.get(
                 'cc', 'AF'),
             contact_voice=zcontacts.extract_phone_number(
                 self.current_registrant_info.get('voice', '')),
             contact_fax=zcontacts.extract_phone_number(
                 self.current_registrant_info.get('fax', '')),
             contact_email=self.current_registrant_info['email'],
         )
     self.received_registrant_epp_id = self.new_registrant_epp_id
     self.known_registrant = zcontacts.registrant_find(
         epp_id=self.received_registrant_epp_id)
     if not self.known_registrant:
         logger.info('new registrant will be created for %r', known_owner)
         self.known_registrant = zcontacts.registrant_create_from_profile(
             owner=known_owner,
             profile_object=known_owner.profile,
             epp_id=self.received_registrant_epp_id,
         )
         if self.target_domain:
             zdomains.domain_detach_contact(self.target_domain, 'admin')
             zdomains.domain_detach_contact(self.target_domain, 'billing')
             zdomains.domain_detach_contact(self.target_domain, 'tech')
         self.new_domain_contacts.pop('admin', None)
         self.new_domain_contacts.pop('billing', None)
         self.new_domain_contacts.pop('tech', None)
     if self.target_domain:
         self.target_domain.refresh_from_db()