def generate_access_key(self): """Generates a random key for accessing the request when it is private.""" key = utils.generate_key(24) self.access_key = key self.save() logger.info('New access key generated for %s', self) return key
def save(self): """Save the existing or new portal to the FOIA request""" portal = self.cleaned_data.get('portal') if not portal: portal = Portal.objects.create( url=self.cleaned_data['url'], name=self.cleaned_data['name'], type=self.cleaned_data['type'], ) self.foia.portal = portal if not self.foia.portal_password: self.foia.portal_password = generate_key() self.foia.save()
def miniregister(self, full_name, email, newsletter=False): """Create a new user from their full name and email and login""" password = generate_key(12) full_name = full_name.strip() username = unique_username(full_name) first_name, last_name = split_name(full_name) # create a new User user = User.objects.create_user(username, email, password, first_name=first_name, last_name=last_name) # create a new Profile Profile.objects.create(user=user, acct_type='basic', monthly_requests=settings.MONTHLY_REQUESTS.get( 'basic', 0), date_update=date.today()) # send the new user a welcome email welcome_miniregister.delay(user) user = authenticate( username=user.username, password=password, ) login(self.request, user) if newsletter: mailchimp_subscribe( self.request, user.email, source='Mini-Register: {}'.format(self.minireg_source), url='https://{}{}'.format(settings.MUCKROCK_URL, self.request.path), ) mixpanel_event( self.request, 'Sign Up', { 'Source': 'Mini-Register: {}'.format(self.minireg_source), 'Newsletter': newsletter, }, signup=True, ) return user
def generate_sharing_code(self): """Generate a new sharing code, save it to the request, and then return a URL.""" self.sharing_code = generate_key(12) self.save() return self.sharing_code
def generate_confirmation_key(self): """Generate random key used for validating the email address""" key = generate_key(24) self.confirmation_key = key self.save() return key
def get_new_password(self): """Generate a random password to use with this portal""" chars = string.ascii_letters + string.digits + string.punctuation return generate_key(12, chars=chars)