aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnknown <mko0815@googlemail.com>2012-03-27 11:02:27 +0200
committerUnknown <mko0815@googlemail.com>2012-03-27 11:02:27 +0200
commitc051f79c84922cdc215db0715d63939372874a82 (patch)
treec68ddc2c3470ed3a1d4fbdaff4a8f8094e6346ae
parenta3fe6138fb2e9231d3a2d7369ad8e1877f014add (diff)
Added Django command to test user authentification via Crowd.
Just try "python manage.py testcrowd A_USERNAME THE_PASSWORD" providing username and password argument for authentification. Command will call django.contrib.auth.authenticate() with the given credentials and print a message for the result.
-rw-r--r--.hgignore2
-rw-r--r--crowdrest/management/__init__.py0
-rw-r--r--crowdrest/management/commands/__init__.py0
-rw-r--r--crowdrest/management/commands/testcrowd.py30
4 files changed, 32 insertions, 0 deletions
diff --git a/.hgignore b/.hgignore
new file mode 100644
index 0000000..9e32b48
--- /dev/null
+++ b/.hgignore
@@ -0,0 +1,2 @@
+syntax: glob
+*.pyc
diff --git a/crowdrest/management/__init__.py b/crowdrest/management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/crowdrest/management/__init__.py
diff --git a/crowdrest/management/commands/__init__.py b/crowdrest/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/crowdrest/management/commands/__init__.py
diff --git a/crowdrest/management/commands/testcrowd.py b/crowdrest/management/commands/testcrowd.py
new file mode 100644
index 0000000..6f7ee73
--- /dev/null
+++ b/crowdrest/management/commands/testcrowd.py
@@ -0,0 +1,30 @@
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth import authenticate
+
+###########################
+class Command(BaseCommand):
+###########################
+ args = '<username password>'
+ help = 'Try to authenticate a user via Crowd ( testing crowed backend with current settings ).'
+
+ def __init__(self):
+ super(Command,self).__init__()
+
+ def handle(self, *args, **options):
+ """
+ Try authenticate.
+ """
+ if len(args)<2:
+ raise CommandError("Need user and password argument")
+
+ userName = args[0]
+ userPwd = args[1]
+ user = authenticate(username=userName, password=userPwd)
+ if user is not None:
+ if user.is_active:
+ print "You provided a correct username and password for '%s' !"%userName
+ else:
+ print "Account '%s' has been disabled!"%userName
+ else:
+ print "Your username and password were incorrect."