Removed the "fix_scrollbarbug" div and all references to it.
[citadel.git] / webcit / auth.c
index 7d369b2cb1f89d3b23e97a7364fc4745add2d2e8..80f7ddbb0a8e63d3920d8e1b72625e79804d15ad 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * WebcitAuth; Handles authentication of users to a Citadel server.
  *
  * Copyright (c) 1996-2010 by the citadel.org team
@@ -35,13 +33,27 @@ void display_reg(int during_login);
 char *axdefs[7]; 
 
 void initialize_axdefs(void) {
-       axdefs[0] = _("Deleted");       /* an erased user */
-       axdefs[1] = _("New User");      /* a new user */
-       axdefs[2] = _("Problem User");  /* a trouble maker */
-       axdefs[3] = _("Local User");    /* user with normal privileges */
-       axdefs[4] = _("Network User");  /* a user that may access network resources */
-       axdefs[5] = _("Preferred User");/* a moderator */
-       axdefs[6] = _("Aide");          /* chief */
+
+       /* an erased user */
+       axdefs[0] = _("Deleted");       
+
+       /* a new user */
+       axdefs[1] = _("New User");      
+
+       /* a trouble maker */
+       axdefs[2] = _("Problem User");  
+
+       /* user with normal privileges */
+       axdefs[3] = _("Local User");    
+
+       /* a user that may access network resources */
+       axdefs[4] = _("Network User");  
+
+       /* a moderator */
+       axdefs[5] = _("Preferred User");
+
+       /* chief */
+       axdefs[6] = _("Aide");          
 }
 
 
@@ -74,45 +86,6 @@ void display_openid_login(char *mesg)
 }
 
 
-void display_openid_name_request(const StrBuf *claimed_id, const StrBuf *username) 
-{
-       StrBuf *Buf = NULL;
-
-       output_headers(1, 1, 2, 0, 0, 0);
-       wc_printf("<div id=\"login_screen\">\n");
-
-       Buf = NewStrBufPlain(NULL, StrLength(claimed_id));
-       StrEscAppend(Buf, claimed_id, NULL, 0, 0);
-       svprintf(HKEY("VERIFIED"), WCS_STRING, _("Your OpenID <tt>%s</tt> was successfully verified."),
-                ChrPtr(Buf));
-       SVPutBuf("CLAIMED_ID", Buf, 0);
-
-
-       if (StrLength(username) > 0) {
-                       Buf = NewStrBufPlain(NULL, StrLength(username));
-                       StrEscAppend(Buf, username, NULL, 0, 0);
-                       svprintf(HKEY("REASON"), WCS_STRING,
-                                _("However, the user name '%s' conflicts with an existing user."), 
-                                ChrPtr(Buf));
-                       FreeStrBuf(&Buf);
-       }
-       else {
-               svput("REASON", WCS_STRING, "");
-       }
-
-       svput("ACTION_REQUESTED", WCS_STRING, _("Please specify the user name you would like to use."));
-
-       svput("USERNAME_BOX", WCS_STRING, _("User name:"));
-       svput("NEWUSER_BUTTON", WCS_STRING, _("New User"));
-       svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
-
-       svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
-                ChrPtr(WC->serv_info->serv_humannode));
-
-       do_template("openid_manual_create", NULL);
-       wDumpContent(2);
-}
-
 
 
 /* Initialize the session
@@ -168,7 +141,7 @@ void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_respo
                const char *pch;
 
                pch = ChrPtr(Buf) + 4;
-               WCC->new_mail  = StrBufExtractNext_long(Buf, &pch, '|');
+               /*WCC->new_mail  =*/ StrBufExtractNext_long(Buf, &pch, '|');
                WCC->need_regi = StrBufExtractNext_long(Buf, &pch, '|');
                WCC->need_vali = StrBufExtractNext_long(Buf, &pch, '|');
                if (WCC->cs_inet_email == NULL)
@@ -188,6 +161,7 @@ void do_login(void)
 {
        wcsession *WCC = WC;
        StrBuf *Buf;
+       long ret, rc;
 
        if (havebstr("language")) {
                set_selected_language(bstr("language"));
@@ -202,25 +176,31 @@ void do_login(void)
        if (havebstr("login_action")) {
                serv_printf("USER %s", bstr("name"));
                StrBuf_ServGetln(Buf);
-               if (GetServerStatus(Buf, NULL) == 3) {
+               rc = GetServerStatus(Buf, &ret);
+               StrBufCutLeft(Buf, 4);
+               switch (rc) {
+               case 3:
                        serv_printf("PASS %s", bstr("pass"));
                        StrBuf_ServGetln(Buf);
                        if (GetServerStatus(Buf, NULL) == 2) {
                                become_logged_in(sbstr("name"), sbstr("pass"), Buf);
                        } else {
-                               snprintf(WCC->ImportantMessage, 
-                                        sizeof (WCC->ImportantMessage), 
-                                        "%s", 
-                                        &(ChrPtr(Buf))[4]);
+                               StrBufCutLeft(Buf, 4);
+                               AppendImportantMessage(SKEY(Buf));
                                display_login();
                                FreeStrBuf(&Buf);
                                return;
                        }
-               } else {
-                       snprintf(WCC->ImportantMessage, 
-                                sizeof (WCC->ImportantMessage), 
-                                "%s", 
-                                &(ChrPtr(Buf))[4]);
+                       break;
+               case 5:
+                       if (ret == 541)
+                       {
+                               AppendImportantMessage(SKEY(Buf));
+                               display_main_menu();
+                               return;
+                       }
+               default:
+                       AppendImportantMessage(SKEY(Buf));
                        display_login();
                        FreeStrBuf(&Buf);
                        return;
@@ -228,10 +208,7 @@ void do_login(void)
        }
        if (havebstr("newuser_action")) {
                if (!havebstr("pass")) {
-                       snprintf(WCC->ImportantMessage, 
-                                sizeof (WCC->ImportantMessage), 
-                                "%s", 
-                                _("Blank passwords are not allowed."));
+                       AppendImportantMessage(_("Blank passwords are not allowed."), -1);
                        display_login();
                        FreeStrBuf(&Buf);
                        return;
@@ -243,10 +220,8 @@ void do_login(void)
                        serv_printf("SETP %s", bstr("pass"));
                        StrBuf_ServGetln(Buf); /* Don't care? */
                } else {
-                       snprintf(WCC->ImportantMessage, 
-                                sizeof (WCC->ImportantMessage), 
-                                "%s", 
-                                &(ChrPtr(Buf))[4]);
+                       StrBufCutLeft(Buf, 4);
+                       AppendImportantMessage(SKEY(Buf));
                        display_login();
                        FreeStrBuf(&Buf);
                        return;
@@ -261,10 +236,7 @@ void do_login(void)
                        do_welcome();
                }
        } else {
-               snprintf(WCC->ImportantMessage, 
-                        sizeof (WCC->ImportantMessage), 
-                        "%s", 
-                        _("Your password was not accepted."));
+               AppendImportantMessage(_("Your password was not accepted."), -1);
                display_login();
        }
        FreeStrBuf(&Buf);
@@ -308,7 +280,15 @@ void openid_manual_create(void)
                        do_welcome();
                }
        } else {
-               display_openid_name_request(sbstr("openid_url"), sbstr("name"));
+               const StrBuf *Buf;
+
+               putbstr("__claimed_id", NewStrBufDup(sbstr("openid_url")));
+               Buf = sbstr("name");
+               if (StrLength(Buf) > 0)
+                       putbstr("__username", NewStrBufDup(Buf));
+               begin_burst();
+               do_template("openid_manual_create", NULL);
+               end_burst();
        }
 
 }
@@ -320,7 +300,6 @@ void openid_manual_create(void)
  */
 void do_openid_login(void)
 {
-       wcsession *WCC = WC;
        char buf[4096];
 
        if (havebstr("language")) {
@@ -334,10 +313,10 @@ void do_openid_login(void)
        }
        if (havebstr("login_action")) {
                snprintf(buf, sizeof buf,
-                       "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
+                       "OIDS %s|%s/finalize_openid_login|%s",
                        bstr("openid_url"),
-                        (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host),
-                        (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host)
+                       ChrPtr(site_prefix),
+                       ChrPtr(site_prefix)
                );
 
                serv_puts(buf);
@@ -448,11 +427,19 @@ void finalize_openid_login(void)
         */
 
        else if (!strcasecmp(ChrPtr(result), "verify_only")) {
-               display_openid_name_request(claimed_id, username);
+               putbstr("__claimed_id", claimed_id);
+               claimed_id = NULL;
+               if (StrLength(username) > 0) {
+                       putbstr("__username", username);
+                       username = NULL;
+               }
+               begin_burst();
+               do_template("openid_manual_create", NULL);
+               end_burst();
        }
 
        /* Did we manage to log in?  If so, continue with the normal flow... */
-       if (WC->logged_in) {
+       else if (WC->logged_in) {
                if (WC->need_regi) {
                        display_reg(1);
                } else {
@@ -562,7 +549,7 @@ void do_logout(void)
        /* FIXME: this is to suppress the iconbar displaying, because we aren't
           actually logged out yet */
        WCC->logged_in = 0;
-       
+
        /** Calling output_headers() this way causes the cookies to be un-set */
        output_headers(1, 1, 0, 1, 0, 0);
 
@@ -570,13 +557,13 @@ void do_logout(void)
         wc_printf("<div class=\"box\">");
         wc_printf("<div class=\"boxlabel\">");
        wc_printf(_("Log off"));
-        wc_printf("</div><div class=\"boxcontent\">"); 
+        wc_printf("</div><div class=\"boxcontent\">");
        serv_puts("MESG goodbye");
        serv_getln(buf, sizeof buf);
 
        if (WCC->serv_sock >= 0) {
                if (buf[0] == '1') {
-                       fmout("CENTER");
+                       fmout("'CENTER'");
                } else {
                        wc_printf("Goodbye\n");
                }
@@ -587,7 +574,7 @@ void do_logout(void)
                        "this problem to your system administrator.")
                );
                wc_printf("<a href=\"http://www.citadel.org/doku.php/"
-                       "faq:mastering_your_os:net#netstat\">%s</a>", 
+                       "faq:mastering_your_os:net#netstat\">%s</a>",
                        _("Read More..."));
        }
 
@@ -605,7 +592,7 @@ void do_logout(void)
        wc_printf("</a></span>");
         */
 
-       wc_printf("</div></div></div></div>\n");
+       wc_printf("</div></div></div>\n");
        wDumpContent(2);
        end_webcit_session();
 }
@@ -658,8 +645,7 @@ void validate(void)
                return;
        }
 
-       wc_printf("<div class=\"fix_scrollbar_bug\">"
-               "<table class=\"auth_validate\"><tr><td>\n");
+       wc_printf("<table class=\"auth_validate\"><tr><td>\n");
        wc_printf("<div id=\"validate\">");
 
        safestrncpy(user, &buf[4], sizeof user);
@@ -742,7 +728,7 @@ void validate(void)
        wc_printf("<br />\n");
 
        wc_printf("</div>\n");
-       wc_printf("</td></tr></table></div>\n");
+       wc_printf("</td></tr></table>\n");
        wDumpContent(1);
 }
 
@@ -915,6 +901,24 @@ void changepw(void)
        }
 }
 
+int ConditionalHaveAccessCreateRoom(StrBuf *Target, WCTemplputParams *TP)
+{
+       StrBuf *Buf;    
+
+       Buf = NewStrBuf();
+       serv_puts("CRE8 0");
+       StrBuf_ServGetln(Buf);
+
+       if (GetServerStatus(Buf, NULL) == 2) {
+               StrBufCutLeft(Buf, 4);
+               AppendImportantMessage(SKEY(Buf));
+               FreeStrBuf(&Buf);
+               return 0;
+       }
+       FreeStrBuf(&Buf);
+       return 1;
+}
+
 int ConditionalAide(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
@@ -1059,7 +1063,7 @@ InitModule_AUTH
 
        RegisterConditional(HKEY("COND:AIDE"), 2, ConditionalAide, CTX_NONE);
        RegisterConditional(HKEY("COND:LOGGEDIN"), 2, ConditionalIsLoggedIn, CTX_NONE);
-
+       RegisterConditional(HKEY("COND:MAY_CREATE_ROOM"), 2,  ConditionalHaveAccessCreateRoom, CTX_NONE);
        return ;
 }