Repository: deis/deis

Issue:
User fails to login after `deis register`
I'm seeing this all the time now after provisioning a new EC2 controller:

``` console
(deis)flopsy:example-go matt$ deis register http://deis.mattboersma.com/
username: matt
password: 
password (confirm): 
email: matt@opdemand.com
Registered matt
Login failed
Login failed
(deis)flopsy:example-go matt$ deis login http://deis.mattboersma.com/
username: matt
password: 
Login failed
```

Then I SSH in to the controller as deis, run `./manage.py createsuperuser`, log in to the Django admin, and see that the "mboersma" user has been created but is not marked as "active". Setting to "active" fixes everyting.

Something changed in Django 1.5.4 or djangorestframework?



Discussion:
I had to do some interesting stuff in: https://github.com/opdemand/deis/blob/master/api/views.py#L76

``` python
    def pre_save(self, obj):
        """Replicate UserManager.create_user functionality."""
        now = timezone.now()
        obj.last_login = now
        obj.date_joined = now
        obj.email = User.objects.normalize_email(obj.email)
        obj.set_password(obj.password)
```

Still, I'm wondering why this assertion in `test_auth` is returning True:
https://github.com/opdemand/deis/blob/master/api/tests/auth.py#L53


Resolving patch:
diff --git a/api/views.py b/api/views.py
--- a/api/views.py
+++ b/api/views.py
@@ -78,6 +78,7 @@ def pre_save(self, obj):
         now = timezone.now()
         obj.last_login = now
         obj.date_joined = now
+        obj.is_active = True
         obj.email = User.objects.normalize_email(obj.email)
         obj.set_password(obj.password)
 
diff --git a/client/deis.py b/client/deis.py
--- a/client/deis.py
+++ b/client/deis.py
@@ -576,14 +576,16 @@ def auth_register(self, args):
             password = getpass('password: ')
             confirm = getpass('password (confirm): ')
             if password != confirm:
-                print('Password mispatch, aborting registration.')
+                print('Password mismatch, aborting registration.')
                 return False
         email = args.get('--email')
         if not email:
             email = raw_input('email: ')
         url = urlparse.urljoin(controller, '/api/auth/register')
         payload = {'username': username, 'password': password, 'email': email}
-        response = self._session.post(url, data=payload, allow_redirects=False)
+        response = self._session.post(url, data=payload,
+                                      headers={'content-type': 'application/json'},
+                                      allow_redirects=False)
         if response.status_code == requests.codes.created:  # @UndefinedVariable
             self._settings['controller'] = controller
             self._settings.save()


Test patch:
diff --git a/api/tests/auth.py b/api/tests/auth.py
--- a/api/tests/auth.py
+++ b/api/tests/auth.py
@@ -48,6 +48,7 @@ def test_auth(self):
         self.assertEqual(response.data['email'], email)
         self.assertEqual(response.data['first_name'], first_name)
         self.assertEqual(response.data['last_name'], last_name)
+        self.assertTrue(response.data['is_active'])
         self.assertFalse(response.data['is_superuser'])
         self.assertFalse(response.data['is_staff'])
         self.assertTrue(