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
def handle_noargs(self, **options): print "Creating application" app = ClientApp(url='fixtureapp.tmp') app.save() usr = User.objects.create_user(app.url, '*****@*****.**', 'testapp') app.user = usr app.save() print "Creating test users for application" client1 = ClientUser(app=app, clientId='testUser1') client1.save() client2 = ClientUser(app=app, clientId='testUser2') client2.save() json_serializer = serializers.get_serializer('json')() fixture = open(os.path.join(settings.ROOT_PATH, 'profile', 'fixtures', 'testApp.json'), 'w') print "Creating fixture" try: json_serializer.serialize([app,usr,client1,client2], stream = fixture) except: print "couldn't serialize" pass print "Deleting from db" app.delete() usr.delete() client1.delete() client2.delete()
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)