Fix login timeout bug & standardize FCGI_*Control functions
[matches/MCTX3420.git] / server / login.c
index 2aa702d..4ec89dd 100644 (file)
@@ -149,8 +149,9 @@ int Login_LDAP_Bind(const char * uri, const char * dn, const char * pass)
  * @param params - Parameter string, UNUSED
  */
 void Logout_Handler(FCGIContext * context, char * params)
-{              
+{
        FCGI_ReleaseControl(context);
+       FCGI_AcceptJSON(context, "Logged out", "0");
 }
 
 
@@ -161,13 +162,6 @@ void Logout_Handler(FCGIContext * context, char * params)
  */
 void Login_Handler(FCGIContext * context, char * params)
 {
-
-       if (context->control_key[0] != '\0')
-       {
-               FCGI_RejectJSON(context, "Already logged in.");
-               return;
-       }
-
        char * user; // The username supplied through CGI
        char * pass; // The password supplied through CGI
 
@@ -247,14 +241,18 @@ void Login_Handler(FCGIContext * context, char * params)
        
        if (!authenticated)
        {
-               FCGI_RejectJSON(context, "Authentication failure.");
-               return;
+               FCGI_RejectJSONEx(context, STATUS_UNAUTHORIZED, "Authentication failure.");
+       }
+       else
+       {
+               if (FCGI_LockControl(context, false))
+               {
+                       // Give the user a cookie
+                       FCGI_AcceptJSON(context, "Logged in", context->control_key);
+               }
+               else
+               {
+                       FCGI_RejectJSON(context, "Someone else is already logged in");
+               }
        }
-
-       FCGI_LockControl(context, false);
-       
-       // Give the user a cookie
-       FCGI_PrintRaw("Content-type: text\r\n");
-       FCGI_PrintRaw("Set-Cookie: %s\r\n\r\n", context->control_key);
-       FCGI_PrintRaw("Logged in");
 }

UCC git Repository :: git.ucc.asn.au