* rework login screen to utilize more modern templating
authorWilfried Göesgens <willi@citadel.org>
Thu, 27 Nov 2008 00:01:20 +0000 (00:01 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 27 Nov 2008 00:01:20 +0000 (00:01 +0000)
* add MESG() template hook
* (still somewhat unfinished, errormessages won't show up yet...)

webcit/auth.c
webcit/gettext.c
webcit/serv_func.c
webcit/static/t/login.html
webcit/static/t/view_message_replyquote.html
webcit/webcit.h

index be6b00ef32114feb333c71af0e8e6106595d0a22..618956d615a3e02c61f5446f212b8ead5b8e3688 100644 (file)
@@ -34,72 +34,12 @@ void initialize_axdefs(void) {
  * Display the login screen
  * mesg = the error message if last attempt failed.
  */
-void display_login(char *mesg)
+void display_login(void)
 {
-       char buf[SIZ];
-
-       output_headers(1, 1, 2, 0, 0, 0);
-       wprintf("<div id=\"login_screen\">\n");
-
-       if ((mesg != NULL) && (!IsEmptyStr(mesg))) {
-               stresc(buf, SIZ,  mesg, 0, 0);
-               svprintf(HKEY("MESG"), WCS_STRING, "%s", buf);
-       }
-
-       svprintf(HKEY("LOGIN_INSTRUCTIONS"), WCS_STRING,
-               _("<ul>"
-               "<li><b>If you already have an account on %s</b>, "
-               "enter your user name and password and click &quot;Login.&quot; "
-               "<li><b>If you are a new user</b>, enter the name and password "
-               "you wish to use, "
-               "and click &quot;New User.&quot; "
-               "<li>Please log off properly when finished. "
-               "<li>You must use a browser that supports <i>frames</i> and "
-               "<i>cookies</i>. "
-               "<li>Also keep in mind that if your browser is "
-               "configured to block pop-up windows, you will not be able "
-               "to receive any instant messages.<br />"
-               "</ul>"),
-               serv_info.serv_humannode
-       );
-
-       svput("USERNAME_BOX", WCS_STRING, _("User name:"));
-       svput("PASSWORD_BOX", WCS_STRING, _("Password:"));
-       svput("LANGUAGE_BOX", WCS_STRING, _("Language:"));
-       svput("LOGIN_BUTTON", WCS_STRING, _("Login"));
-       svput("NEWUSER_BUTTON", WCS_STRING, _("New User"));
-       svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
-       svput("HELLO", WCS_SERVCMD, "MESG hello");
-       svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
-               serv_info.serv_humannode);
-       svcallback("DO_LANGUAGE_BOX", offer_languages);
-       if (serv_info.serv_newuser_disabled) {
-               svput("NEWUSER_BUTTON_PRE", WCS_STRING, "<div style=\"display:none;\">");
-               svput("NEWUSER_BUTTON_POST", WCS_STRING, "</div>");
-       }
-       else {
-               svput("NEWUSER_BUTTON_PRE", WCS_STRING, "");
-               svput("NEWUSER_BUTTON_POST", WCS_STRING, "");
-       }
-
-       if (serv_info.serv_supports_openid) {
-               svprintf(HKEY("OFFER_OPENID_LOGIN"), WCS_STRING,
-                       "<div align=center>"
-                       "<a href=\"display_openid_login\">"
-                       "<img src=\"static/openid-small.gif\" border=0 valign=middle>"
-                       "%s</a>"
-                       "</div>"
-                       ,
-                       "Log in using OpenID"
-               );
-       }
-       else {
-               svput("OFFER_OPENID_LOGIN", WCS_STRING, "");
-       }
-
+       begin_burst();
+       output_headers(1, 0, 0, 0, 1, 0);
        do_template("login", NULL);
-
-       wDumpContent(2);
+       end_burst();
 }
 
 
@@ -135,15 +75,8 @@ void display_openid_login(char *mesg)
                "</ul>")
        );
 
-       svput("OPENID_BOX", WCS_STRING, _("OpenID URL:"));
-       svput("LANGUAGE_BOX", WCS_STRING, _("Language:"));
-       svput("LOGIN_BUTTON", WCS_STRING, _("Login"));
-       svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
        svput("HELLO", WCS_SERVCMD, "MESG hello");
-       svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
-               serv_info.serv_humannode);
-       svcallback("DO_LANGUAGE_BOX", offer_languages);
-
+       
        svprintf(HKEY("OFFER_CONVENTIONAL_LOGIN"), WCS_STRING,
                "<div align=center>"
                "<a href=\"display_login\">"
@@ -243,6 +176,7 @@ void become_logged_in(char *user, char *pass, char *serv_response)
  */
 void do_login(void)
 {
+       struct wcsession *WCC = WC;
        char buf[SIZ];
 
        if (havebstr("language")) {
@@ -263,17 +197,29 @@ void do_login(void)
                        if (buf[0] == '2') {
                                become_logged_in(bstr("name"), bstr("pass"), buf);
                        } else {
-                               display_login(&buf[4]);
+                               snprintf(WCC->ImportantMessage, 
+                                        sizeof (WCC->ImportantMessage), 
+                                        "%s", 
+                                        &buf[4]);
+                               display_login();
                                return;
                        }
                } else {
-                       display_login(&buf[4]);
+                       snprintf(WCC->ImportantMessage, 
+                                sizeof (WCC->ImportantMessage), 
+                                "%s", 
+                                &buf[4]);
+                       display_login();
                        return;
                }
        }
        if (havebstr("newuser_action")) {
                if (!havebstr("pass")) {
-                       display_login(_("Blank passwords are not allowed."));
+                       snprintf(WCC->ImportantMessage, 
+                                sizeof (WCC->ImportantMessage), 
+                                "%s", 
+                                _("Blank passwords are not allowed."));
+                       display_login();
                        return;
                }
                serv_printf("NEWU %s", bstr("name"));
@@ -283,21 +229,29 @@ void do_login(void)
                        serv_printf("SETP %s", bstr("pass"));
                        serv_getln(buf, sizeof buf);
                } else {
-                       display_login(&buf[4]);
+                       snprintf(WCC->ImportantMessage, 
+                                sizeof (WCC->ImportantMessage), 
+                                "%s", 
+                                &buf[4]);
+                       display_login();
                        return;
                }
        }
-       if (WC->logged_in) {
+       if (WCC->logged_in) {
                set_preference("language", NewStrBufPlain(bstr("language"), -1), 1);
-               if (WC->need_regi) {
+               if (WCC->need_regi) {
                        display_reg(1);
-               } else if (WC->need_vali) {
+               } else if (WCC->need_vali) {
                        validate();
                } else {
                        do_welcome();
                }
        } else {
-               display_login(_("Your password was not accepted."));
+               snprintf(WCC->ImportantMessage, 
+                        sizeof (WCC->ImportantMessage), 
+                        "%s", 
+                        _("Your password was not accepted."));
+               display_login();
        }
 
 }
index 1402983c01865e0e15c9b80eec1cf7403df65de6..d504a6eaf2895acc904ddc2084f15333993c3846 100644 (file)
@@ -205,7 +205,7 @@ void httplang_to_locale(StrBuf *LocaleString)
  * depending on the browser locale change the sequence of the 
  * language chooser.
  */
-void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void tmplput_offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
        int i;
 #ifndef HAVE_USELOCALE
        char *Lang = getenv("LANG");
@@ -344,7 +344,7 @@ void ShutdownLocale(void)
 
 #else  /* ENABLE_NLS */
 /** \brief dummy for non NLS enabled systems */
-void offer_languages(void) {
+void tmplput_offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
        wprintf("English (US)");
 }
 
@@ -388,4 +388,9 @@ const char *get_selected_language(void) {
 #endif
 }
 
-
+void 
+InitModule_GETTEXT
+(void)
+{
+       RegisterNamespace("LANG:SELECT", 0, 0, tmplput_offer_languages, CTX_NONE);
+}
index a01184f35b88907007f55059495a00f7e73a8225..24d64589695b36b6c91c9aae4bde057d04b3052e 100644 (file)
@@ -168,7 +168,7 @@ void FmOut(StrBuf *Target, char *align, StrBuf *Source)
        long len;
        int intext = 0;
 
-       StrBufAppendPrintf(Target, "<div align=%s>\n", align);
+       StrBufAppendPrintf(Target, "<div align=\"%s\">\n", align);
        while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
        {
                done = n == 0;
@@ -523,7 +523,7 @@ void tmplput_serv_fqdn(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
        StrEscAppend(Target, NULL, serv_info.serv_fqdn, 0, 0);
 }
 
-void tmmplput_serv_software(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_software(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        StrEscAppend(Target, NULL, serv_info.serv_software, 0, 0);
 }
@@ -534,8 +534,16 @@ void tmplput_serv_rev_level(StrBuf *Target, int nArgs, WCTemplateToken *Tokens,
                            serv_info.serv_rev_level / 100,
                            serv_info.serv_rev_level % 100);
 }
+int conditional_serv_newuser_disabled(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       return serv_info.serv_newuser_disabled != 0;
+}
+int conditional_serv_supports_openid(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       return serv_info.serv_supports_openid != 0;
+}
 
-void tmmplput_serv_bbs_city(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_bbs_city(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        StrEscAppend(Target, NULL, serv_info.serv_bbs_city, 0, 0);
 }
@@ -551,23 +559,54 @@ void tmplput_current_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
 }
 
 
+void tmplput_mesg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       int n = 0;
+       int Done = 0;
+       StrBuf *Line;
+       StrBuf *Buf;
 
-
+       Buf = NewStrBuf();
+       Line = NewStrBuf();
+       serv_printf("MESG %s", Tokens->Params[0]->Start);
+       StrBuf_ServGetln(Line);
+       while (!Done &&  (StrBuf_ServGetln(Line)>=0)) {
+               if ( (StrLength(Line)==3) && 
+                   !strcmp(ChrPtr(Line), "000")) 
+                       Done = 1;
+               else
+               {
+                       if (n > 0)
+                               StrBufAppendBufPlain(Buf, "\n", 1, 0);
+                       StrBufAppendBuf(Buf, Line, 0);
+               }
+               n++;
+       }
+       FlushStrBuf(Line);
+       FmOut(Line, "center", Buf);
+       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Line, 1);
+       FreeStrBuf(&Buf);
+       FreeStrBuf(&Line);
+}
 
 void 
 InitModule_SERVFUNC
 (void)
 {
+
+       RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
+       RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
        RegisterNamespace("CURRENT_USER", 0, 0, tmplput_current_user, CTX_NONE);
        RegisterNamespace("CURRENT_ROOM", 0, 0, tmplput_current_room, CTX_NONE);
        RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
        RegisterNamespace("SERV:NODENAME", 0, 0, tmplput_serv_nodename, CTX_NONE);
        RegisterNamespace("SERV:HUMANNODE", 0, 0, tmplput_serv_humannode, CTX_NONE);
        RegisterNamespace("SERV:FQDN", 0, 0, tmplput_serv_fqdn, CTX_NONE);
-       RegisterNamespace("SERV:SOFTWARE", 0, 0, tmmplput_serv_software, CTX_NONE);
+       RegisterNamespace("SERV:SOFTWARE", 0, 0, tmplput_serv_software, CTX_NONE);
        RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE);
-       RegisterNamespace("SERV:BBS_CITY", 0, 0, tmmplput_serv_bbs_city, CTX_NONE);
-///    RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmmplput_serv_ldap_enabled, 0);
+       RegisterNamespace("SERV:BBS_CITY", 0, 0, tmplput_serv_bbs_city, CTX_NONE);
+       RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, CTX_NONE);
+///    RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmplput_serv_ldap_enabled, 0);
 }
 
 /*@}*/
index 495e4919eb435383ff5e8639d05a3f0c2555b926..7afc0edc0fede8c2366bbc9dd5480bbfdaf7a576 100644 (file)
@@ -1,23 +1,46 @@
-<?=("beginbox")>
-<?HELLO>
-<div class="login_message"><?MESG></div>
+<?=("head")>
+<div id="login_screen">
+<div class="box">
+<div class="boxlabel"><?SERV:HUMANNODE> - <?_("powered by")> <a href="http://www.citadel.org">Citadel</a></div>
+<div class="boxcontent">
+<?SERV:MESG("hello")>
+
+<?!("COND:IMPMSG", 1)>
+<?IMPORTANTMESSAGE>
+<?!("X", 1)>
+
+<div class="login_message"></div>
 <form action="login" method="POST"  class="box" id="login_form">
-        <label for="uname"><?USERNAME_BOX></label>
+        <label for="uname"><?_("User name:")></label>
         <input type="text" name="name" id="uname" > <br>
-        <label for="pname"><?PASSWORD_BOX></label>
+        <label for="pname"><?_("Password:")></label>
         <input type="password" name="pass" id="pname" > <br>
-        <label for="lname"><?LANGUAGE_BOX></label>
-        <?DO_LANGUAGE_BOX> <br>
+        <label for="lname"><?_("Language:")></label>
+        <?LANG:SELECT> <br>
         <div class="logbuttons">
-        <input type="submit" name="login_action" value="<?LOGIN_BUTTON>" class="logbutton">
-        <?NEWUSER_BUTTON_PRE>
-        <input type="submit" name="newuser_action" value="<?NEWUSER_BUTTON>" class="logbutton" >
-        <?NEWUSER_BUTTON_POST>
-        <input type="submit" name="exit_action" value="<?EXIT_BUTTON>"  class="logbutton">
+        <input type="submit" name="login_action" value="<?_("Login")>" class="logbutton">
+       <??("COND:SERV:NEWU", 1)>
+        <div style="display:none;">
+        <input type="submit" name="newuser_action" value="<?_("New User")>" class="logbutton" >
+        </div>
+       <??("X", 1)>
+        <input type="submit" name="exit_action" value="<?_("Exit")>"  class="logbutton">
         <br>
         </div>
 </form>
-<?OFFER_OPENID_LOGIN>
+<??("COND:SERV:OPENID", 3)>
+  <div align=center>
+  <a href="display_openid_login">
+  <img src="static/openid-small.gif" border="0" valign="middle">
+  <?_("Log in using OpenID")></a>
+  </div>
+<??("X", 3)>
 <div class="login_image"><img src="image&name=hello"></div>
-<div class="login_infos"><?LOGIN_INSTRUCTIONS></div>
+<div class="login_infos">
+<ul><li><b><?_("If you already have an account on")> <?SERV:HUMANNODE></b>,
+<?_("enter your user name and password and click &quot;Login.&quot;<li><b>If you are a new user</b>, enter the name and password you wish to use, and click &quot;New User.&quot; <li>Please log off properly when finished. <li>You must use a browser that supports <i>frames</i> and <i>cookies</i>. <li>Also keep in mind that if your browser is configured to block pop-up windows, you will not be able to receive any instant messages.")>
+<br /> </ul>
+</div>
 <?=("endbox")>
+<?=("trailing")>
index 2bbb285700394371c4f4a603393690785540d776..4de24c17e492d0ab854dc79db3bf20616839db50 100644 (file)
@@ -2,7 +2,7 @@
   <div class="message_header">
     <span><?MAIL:SUMM:DATESTR></span>
     <span><?_("from ")>
-      <??("COND:MAIL:ANON",1)><?MAIL:SUMM:FROM("X")>&lt;<?MAIL:SUMM:RFCA("X")>&gt;<??("X", 1)>
+      <??("COND:MAIL:ANON",1)><?MAIL:SUMM:FROM("X")> &lt;<?MAIL:SUMM:RFCA("X")>&gt;<??("X", 1)>
       <?!("COND:MAIL:ANON",2)>***<??("X", 2)>
     </span>
     <p class="message_subject"><?MAIL:SUMM:SUBJECT></p>
index 1250676ec1ff42d1b0752f7af92b62f074e14ea0..f431ac9e7f752e23c4f1bbe68707a9195b893807 100644 (file)
@@ -707,7 +707,7 @@ void cookie_to_stuff(StrBuf *cookie, int *session,
 void locate_host(char *, int);
 void become_logged_in(char *, char *, char *);
 void openid_manual_create(void);
-void display_login(char *mesg);
+void display_login();
 void display_openids(void);
 void do_welcome(void);
 void do_logout(void);