2019-10-29 09:58:54 +00:00
|
|
|
|
|
|
|
from django.contrib.auth.forms import AuthenticationForm
|
|
|
|
|
|
|
|
from . import api
|
|
|
|
|
|
|
|
class LoginForm(AuthenticationForm):
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
username = self.cleaned_data.get('username')
|
|
|
|
password = self.cleaned_data.get('password')
|
|
|
|
|
|
|
|
if username is not None and password:
|
2019-10-30 12:05:46 +00:00
|
|
|
orchestra = api.Orchestra(username=username, password=password)
|
|
|
|
|
|
|
|
if orchestra.auth_token is None:
|
2019-10-29 09:58:54 +00:00
|
|
|
raise self.get_invalid_login_error()
|
|
|
|
else:
|
2019-10-30 12:05:46 +00:00
|
|
|
self.username = username
|
|
|
|
self.token = orchestra.auth_token
|
2020-01-23 16:37:08 +00:00
|
|
|
self.user = orchestra.retrieve_profile()
|
2019-10-29 09:58:54 +00:00
|
|
|
|
|
|
|
return self.cleaned_data
|