]> code.citadel.org Git - citadel.git/blobdiff - webcit/auth.c
* start migrating important message to strbuf; have both meanwhile.
[citadel.git] / webcit / auth.c
index e48c4e69ce2d9f606ba9a7d8a6618e76a7341ce8..3f4a4e7833757e6e915c7eb6585d8bfbc03dbafe 100644 (file)
@@ -51,43 +51,10 @@ void display_login(void)
  */
 void display_openid_login(char *mesg)
 {
-       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>Enter your OpenID URL and click &quot;Login&quot;."
-               "<li><a href=\"http://www.citadel.org/doku.php/documentation:openid\">"
-               "Click here to learn what OpenID is and how Citadel is using it.</a>"
-               "<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>")
-       );
-
-       svput("HELLO", WCS_SERVCMD, "MESG hello");
-       
-       svprintf(HKEY("OFFER_CONVENTIONAL_LOGIN"), WCS_STRING,
-               "<div id=\"convlogin\">"
-               "<a href=\"display_login\">"
-               "%s</a>"
-               "</div>"
-               ,
-               "Log in using a user name and password"
-       );
-
-       do_template("openid_login", NULL);
-       wDumpContent(2);
+  begin_burst();
+  output_headers(1, 0, 0, 0, 1, 0);
+  do_template("openid_login", NULL);
+  end_burst();
 }
 
 
@@ -124,7 +91,7 @@ void display_openid_name_request(const StrBuf *claimed_id, const StrBuf *usernam
        svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
 
        svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
-                ChrPtr(serv_info.serv_humannode));
+                ChrPtr(WC->serv_info->serv_humannode));
 
        do_template("openid_manual_create", NULL);
        wDumpContent(2);
@@ -147,10 +114,11 @@ void display_openid_name_request(const StrBuf *claimed_id, const StrBuf *usernam
 void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_response)
 {
        wcsession *WCC = WC;
-       char buf[SIZ];
+       StrBuf *Buf;
        StrBuf *FloorDiv;
+       StrBuf *Language = NULL;
 
-       WC->logged_in = 1;
+       WCC->logged_in = 1;
 
        if (WCC->wc_fullname == NULL)
                WCC->wc_fullname = NewStrBufPlain(NULL, StrLength(serv_response));
@@ -178,17 +146,32 @@ void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_respo
 
        load_preferences();
 
+       Buf = NewStrBuf();
        serv_puts("CHEK");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '2') {
-               WC->new_mail = extract_int(&buf[4], 0);
-               WC->need_regi = extract_int(&buf[4], 1);
-               WC->need_vali = extract_int(&buf[4], 2);
-               extract_token(WC->cs_inet_email, &buf[4], 3, '|', sizeof WC->cs_inet_email);
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 2) {
+               const char *pch;
+
+               pch = ChrPtr(Buf) + 4;
+               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)
+                       WCC->cs_inet_email  = NewStrBuf();
+               StrBufExtract_NextToken(WCC->cs_inet_email, Buf, &pch, '|');
+       }
+       if (havebstr("language"))
+               set_preference("language", NewStrBufDup(SBSTR("language")), 1);
+       else {
+               get_preference("language", &Language);
+               if (Language != NULL) {
+                       set_selected_language(ChrPtr(Language));
+                       go_selected_language();         /* set locale */
+               }
        }
-
        get_preference("floordiv_expanded", &FloorDiv);
-       WC->floordiv_expanded = FloorDiv;
+       WCC->floordiv_expanded = FloorDiv;
+       FreeStrBuf(&Buf);
 }
 
 
@@ -264,7 +247,6 @@ void do_login(void)
                }
        }
        if (WCC->logged_in) {
-               set_preference("language", NewStrBufPlain(bstr("language"), -1), 1);
                if (WCC->need_regi) {
                        display_reg(1);
                } else if (WCC->need_vali) {
@@ -408,9 +390,7 @@ void finalize_openid_login(void)
                                serv_puts("000");
 
                                linecount = 0;
-                               while (StrBuf_ServGetln(Buf), 
-                                      (StrLength(Buf)==3) && 
-                                      !strcmp(ChrPtr(Buf), "000")) 
+                               while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) 
                                {
                                        if (linecount == 0) result = NewStrBufDup(Buf);
                                        if (!strcasecmp(ChrPtr(result), "authenticate")) {
@@ -563,13 +543,18 @@ void end_webcit_session(void) {
  */
 void do_logout(void)
 {
+       wcsession *WCC = WC;
        char buf[SIZ];
 
-       FlushStrBuf(WC->wc_username);
-       FlushStrBuf(WC->wc_password);
-       FlushStrBuf(WC->wc_roomname);
-       FlushStrBuf(WC->wc_fullname);
+       FlushStrBuf(WCC->wc_username);
+       FlushStrBuf(WCC->wc_password);
+       FlushStrBuf(WCC->wc_roomname);
+       FlushStrBuf(WCC->wc_fullname);
 
+       /* 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);
 
@@ -581,7 +566,7 @@ void do_logout(void)
        serv_puts("MESG goodbye");
        serv_getln(buf, sizeof buf);
 
-       if (WC->serv_sock >= 0) {
+       if (WCC->serv_sock >= 0) {
                if (buf[0] == '1') {
                        fmout("CENTER");
                } else {
@@ -755,6 +740,8 @@ void validate(void)
  */
 void display_reg(int during_login)
 {
+       message_summary *VCMsg;
+       wc_mime_attachment *VCAtt;
        long vcard_msgnum;
 
        if (goto_config_room() != 0) {
@@ -763,7 +750,7 @@ void display_reg(int during_login)
                return;
        }
 
-       vcard_msgnum = locate_user_vcard_in_this_room();
+       vcard_msgnum = locate_user_vcard_in_this_room(&VCMsg, &VCAtt);
        if (vcard_msgnum < 0L) {
                if (during_login) do_welcome();
                else display_main_menu();
@@ -771,10 +758,10 @@ void display_reg(int during_login)
        }
 
        if (during_login) {
-               do_edit_vcard(vcard_msgnum, "1", "do_welcome", USERCONFIGROOM);
+               do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, "do_welcome", USERCONFIGROOM);
        }
        else {
-               do_edit_vcard(vcard_msgnum, "1", "display_main_menu", USERCONFIGROOM);
+               do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, "display_main_menu", USERCONFIGROOM);
        }
 
 }