def form_valid(self, form):
     portal = form.portal
     username = form.cleaned_data.get("username")
     if username:
         return JsonResponse(
             self.get_user_organisation_roles(portal, username))
     else:
         return JsonError('Missing "username" POST parameter.')
    def form_valid(self, form):
        portal = form.portal
        username = form.cleaned_data.get("username")

        if username:
            return self.get_user(portal, username)
        else:
            return JsonError('Missing "username" POST parameter.')
    def form_valid(self, form):
        portal = form.portal
        username = form.cleaned_data.get("username")
        password = form.cleaned_data.get("password")

        if username and password:
            return self.authenticate(portal, username, password)
        else:
            return JsonError(
                'Missing "username" or "password" POST parameters.')
 def authenticate(self, portal, username, password):
     user = django_authenticate(username=username, password=password)
     if user:
         if not user.is_active:
             return JsonError("User account is disabled")
         else:
             try:
                 profile = user.user_profile
             except models.UserProfile.DoesNotExist:
                 return JsonError("No access to this portal")
             if profile.has_access(portal):
                 user_data = construct_user_data(profile=profile)
                 return JsonResponse({"user": user_data})
             else:
                 return JsonError("No access to this portal")
     else:
         logger.warn(
             "Login failed for user %s and ip %s",
             username,
             self.request.META["REMOTE_ADDR"],
         )
         return JsonError("Login failed")
 def get_user(self, portal, username):
     try:
         user = User.objects.get(username=username)
     except User.DoesNotExist:
         user = None
     if user:
         if not user.is_active:
             return JsonError("User account is disabled")
         else:
             try:
                 profile = user.user_profile
             except models.UserProfile.DoesNotExist:
                 return JsonError("No access to this portal")
             if profile.has_access(portal):
                 user_data = construct_user_data(profile=profile)
                 return JsonResponse({"user": user_data})
             else:
                 return JsonError("No access to this portal")
     else:
         return JsonError(
             "No such user. " +
             "Perhaps you need to add user to the SSO server first?")