Merge branch 'master' into users
[matches/MCTX3420.git] / server / login.c
index c1d981f..8ca2cab 100644 (file)
@@ -110,7 +110,12 @@ UserType Login_MySQL(const char * user, const char * pass,
                Log(LOGERR, "No user matching %s", user);
        }
 
-
+       //TODO: Handle administrator users somehow better than this
+       // UserCake stores the permission level in a seperate table to the username/password, which is annoying
+       if (user_type != USER_UNAUTH && strcmp(user, "admin") == 0)
+       {
+               user_type = USER_ADMIN;
+       }
        mysql_free_result(result);
        mysql_close(con);
        return user_type;
@@ -273,7 +278,8 @@ int Login_LDAP_Bind(const char * uri, const char * dn, const char * pass)
 void Logout_Handler(FCGIContext * context, char * params)
 {
        FCGI_ReleaseControl(context);
-       FCGI_AcceptJSON(context, "Logged out", "0");
+       FCGI_SendControlCookie(context, false); //Unset the cookie
+       FCGI_AcceptJSON(context, "Logged out");
 }
 
 
@@ -367,7 +373,7 @@ void Login_Handler(FCGIContext * context, char * params)
                {
                        //WARNING: C string manipulation code approaching!
                        // Non reentrent; uses strsep and modifies g_options.auth_options
-                       // If problems happen, try strdup ...
+                       // If problems happen, try strdup first ...
                        static char * db_opts[] = {"root", "", "users", "uc_users"};
                        static bool db_init_opts = false;
                        if (!db_init_opts)
@@ -386,7 +392,7 @@ void Login_Handler(FCGIContext * context, char * params)
                                                break;
                                        }
                                }                       
-                               Log(LOGDEBUG, "MySQL: user %s pass %s name %s table %s", db_opts[0], db_opts[1], db_opts[2], db_opts[3]);       
+                               //Log(LOGDEBUG, "MySQL: user %s pass %s name %s table %s", db_opts[0], db_opts[1], db_opts[2], db_opts[3]);     
                        }
 
                        user_type = Login_MySQL(user, pass, g_options.auth_uri, db_opts[0],db_opts[1], db_opts[2], db_opts[3]);
@@ -414,7 +420,8 @@ void Login_Handler(FCGIContext * context, char * params)
                {
                        FCGI_EscapeText(context->user_name); //Don't break javascript pls
                        // Give the user a cookie
-                       FCGI_AcceptJSON(context, "Logged in", context->control_key);
+                       FCGI_SendControlCookie(context, true); //Send the control key
+                       FCGI_AcceptJSON(context, "Logged in");
                        Log(LOGDEBUG, "Successful authentication for %s", user);
                }
                else

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