Beispiel #1
0
 def clean(self):
     from profile.models import ClientApp
     from django.contrib.auth.models import User
     """Register the app"""
     super(RegisterForm, self).clean()
     #in automated tests, the captcha is ignored:
     if settings.IGNORE_CAPTCHA and 'recaptcha' in self._errors:
         #logging.debug(self._errors)
         del self._errors['recaptcha']
         self.cleaned_data['recaptcha'] = 'test'                    
     if any(self.errors):
         return self.cleaned_data
     if ClientApp.objects.filter(url__iexact=self.cleaned_data['url']).count() > 0:
         self._errors['url']=ErrorList([_('There is an app with that name already registered'),])
         del self.cleaned_data['url']
     else:
         key = ""
         try:
             app = ClientApp(url=self.cleaned_data['url'])
             app.save()                
             key = app.get_token()
             
             raw_pass = User.objects.make_random_password()
             u = User.objects.create_user(app.url, self.cleaned_data['mail'], raw_pass)
             u.save()                                           
             #logging.debug('pass for %s: %s' % (app.url, raw_pass))
             app.user = u
             app.save()
             self.cleaned_data['key'] = key
             self.cleaned_data['pass']= raw_pass
         except:
             pass                       
         
         return self.cleaned_data
Beispiel #2
0
 def handle(self, url, email, *args, **options):
     try:
         app = ClientApp(url=url)
         app.save()
         
         raw_pass = User.objects.make_random_password()
         u = User.objects.create_user(app.url, email, raw_pass)
         u.save()                                           
         #logging.debug('pass for %s: %s' % (app.url, raw_pass))
         app.user = u
         app.save()
         
         return app.get_token(), app.user.username, raw_pass
     except Exception, e:
         raise CommandError(e.message)