Merge branch 'master' of https://github.com/szmoore/MCTX3420.git
[matches/MCTX3420.git] / server / login.c
index ddacdd9..5e2128f 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, "Someone is already logged in.");
-               return;
-       }
-
        char * user; // The username supplied through CGI
        char * pass; // The password supplied through CGI
 
@@ -226,6 +220,7 @@ void Login_Handler(FCGIContext * context, char * params)
                        if (len >= BUFSIZ)
                        {
                                FCGI_RejectJSON(context, "DN too long! Recompile with increased BUFSIZ");
+                               return;
                        }
                
                        authenticated = (Login_LDAP_Bind(g_options.auth_uri, dn, pass) == LDAP_SUCCESS);
@@ -251,8 +246,18 @@ void Login_Handler(FCGIContext * context, char * params)
        }
        else
        {
-               FCGI_LockControl(context, false);
-               // Give the user a cookie
-               FCGI_AcceptJSON(context, "Logged in", context->control_key);
+               if (FCGI_LockControl(context, false))
+               {
+                       //Todo: change this to something better than the username if using LDAP.
+                       snprintf(context->friendly_name, 31, "%s", user);
+                       FCGI_EscapeText(context->friendly_name); //Don't break javascript pls
+
+                       // Give the user a cookie
+                       FCGI_AcceptJSON(context, "Logged in", context->control_key);
+               }
+               else
+               {
+                       FCGI_RejectJSON(context, "Someone else is already logged in");
+               }
        }
 }

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