4 * This file contains code which relates to authentication of users to Citadel.
16 #include <sys/types.h>
18 #include <sys/socket.h>
21 #include <netinet/in.h>
43 * Display the login screen
45 void display_login(char *mesg)
51 if (mesg != NULL) if (strlen(mesg) > 0) {
53 svprintf("mesg", WCS_STRING, "%s", buf);
56 svprintf("hello", WCS_SERVCMD, "MESG hello");
61 wDumpContent(0); /* No menu here; not logged in yet! */
68 * This function needs to get called whenever the session changes from
69 * not-logged-in to logged-in, either by an explicit login by the user or
70 * by a timed-out session automatically re-establishing with a little help
71 * from the browser cookie. Either way, we need to load access controls and
72 * preferences from the server.
74 void become_logged_in(char *user, char *pass, char *serv_response)
77 extract(WC->wc_username, &serv_response[4], 0);
78 strcpy(WC->wc_password, pass);
79 WC->axlevel = extract_int(&serv_response[4], 1);
80 if (WC->axlevel >= 6) {
93 if (!strcasecmp(bstr("action"), "Exit")) {
97 if (!strcasecmp(bstr("action"), "Login")) {
98 serv_printf("USER %s", bstr("name"));
101 serv_printf("PASS %s", bstr("pass"));
104 become_logged_in(bstr("name"),
107 display_login(&buf[4]);
111 display_login(&buf[4]);
115 if (!strcasecmp(bstr("action"), "New User")) {
116 serv_printf("NEWU %s", bstr("name"));
119 become_logged_in(bstr("name"), bstr("pass"), buf);
120 serv_printf("SETP %s", bstr("pass"));
123 display_login(&buf[4]);
131 WC->new_mail = extract_int(&buf[4], 0);
132 need_regi = extract_int(&buf[4], 1);
133 WC->need_vali = extract_int(&buf[4], 2);
141 display_login("Your password was not accepted.");
146 void do_welcome(void)
150 get_preference("startpage", startpage);
151 if (strlen(startpage)==0) {
152 strcpy(startpage, "/dotskip&room=_BASEROOM_");
153 set_preference("startpage", startpage);
156 svprintf("STARTPAGE", WCS_STRING, startpage);
158 do_template("mainframeset");
159 clear_local_substs();
164 * Disconnect from the Citadel server, and end this WebCit session
166 void end_webcit_session(void) {
169 /* close() of citadel socket will be done by do_housekeeping() */
177 strcpy(WC->wc_username, "");
178 strcpy(WC->wc_password, "");
179 strcpy(WC->wc_roomname, "");
181 output_headers(2); /* note "2" causes cookies to be unset */
184 serv_puts("MESG goodbye");
190 wprintf("Goodbye\n");
192 wprintf("<HR><A HREF=\"/\">Log in again</A> "
193 "<A HREF=\"javascript:window.close();\">Close window</A>"
196 end_webcit_session();
213 strcpy(buf, bstr("user"));
215 if (strlen(bstr("WC->axlevel")) > 0) {
216 serv_printf("VALI %s|%s", buf, bstr("WC->axlevel"));
219 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
226 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
230 strcpy(user, &buf[4]);
231 serv_printf("GREG %s", user);
239 wprintf("User #%s<BR><H1>%s</H1>",
242 wprintf("PW: %s<BR>\n", buf);
244 wprintf("%s<BR>\n", buf);
246 wprintf("%s<BR>\n", buf);
248 wprintf("%s, ", buf);
252 wprintf("%s<BR>\n", buf);
254 wprintf("%s<BR>\n", buf);
256 wprintf("Current access level: %d (%s)\n",
257 atoi(buf), axdefs[atoi(buf)]);
258 } while (strcmp(buf, "000"));
260 wprintf("<H1>%s</H1>%s<BR>\n", user, &cmd[4]);
263 wprintf("<CENTER><TABLE border><CAPTION>Select access level:");
264 wprintf("</CAPTION><TR>");
265 for (a = 0; a <= 6; ++a) {
266 wprintf("<TD><A HREF=\"/validate&user=");
268 wprintf("&WC->axlevel=%d\">%s</A></TD>\n",
271 wprintf("</TR></TABLE><CENTER><BR>\n");
281 * Display form for registration.
282 * (Set during_login to 1 if this registration is being performed during
283 * new user login and will require chaining to the proper screen.)
285 void display_reg(int during_login)
292 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
293 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
294 wprintf("<B>Enter registration info</B>\n");
295 wprintf("</FONT></TD></TR></TABLE>\n");
298 serv_puts("MESG register");
303 wprintf("<FORM ACTION=\"/register\" METHOD=\"POST\">\n");
304 wprintf("<INPUT TYPE=\"hidden\" NAME=\"during_login\" VALUE=\"%d\">\n", during_login);
306 serv_puts("GREG _SELF_");
309 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
312 wprintf("<H1>%s</H1><TABLE border>\n", &buf[4]);
314 while (serv_gets(buf), strcmp(buf, "000")) {
319 wprintf("Real Name:</TD><TD><INPUT TYPE=\"text\" NAME=\"realname\" VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n", buf);
322 wprintf("Street Address:</TD><TD><INPUT TYPE=\"text\" NAME=\"address\" VALUE=\"%s\" MAXLENGTH=\"24\"><BR>\n", buf);
325 wprintf("City/town:</TD><TD><INPUT TYPE=\"text\" NAME=\"city\" VALUE=\"%s\" MAXLENGTH=\"14\"><BR>\n", buf);
328 wprintf("State/province:</TD><TD><INPUT TYPE=\"text\" NAME=\"state\" VALUE=\"%s\" MAXLENGTH=\"2\"><BR>\n", buf);
331 wprintf("ZIP/postal code:</TD><TD><INPUT TYPE=\"text\" NAME=\"zip\" VALUE=\"%s\" MAXLENGTH=\"10\"><BR>\n", buf);
334 wprintf("Telephone:</TD><TD><INPUT TYPE=\"text\" NAME=\"phone\" VALUE=\"%s\" MAXLENGTH=\"14\"><BR>\n", buf);
337 wprintf("E-Mail:</TD><TD><INPUT TYPE=\"text\" NAME=\"email\" VALUE=\"%s\" MAXLENGTH=\"31\"><BR>\n", buf);
340 wprintf("Country:</TD><TD><INPUT TYPE=\"text\" NAME=\"country\" VALUE=\"%s\" MAXLENGTH=\"31\"><BR>\n", buf);
343 wprintf("</TD></TR>\n");
345 wprintf("</TABLE><P>");
347 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Register\">\n");
348 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
349 wprintf("</CENTER>\n");
356 void register_user(void)
360 if (strcmp(bstr("action"), "Register")) {
361 display_error("Cancelled. Registration was not saved.");
367 display_error(&buf[4]);
369 serv_puts(bstr("realname"));
370 serv_puts(bstr("address"));
371 serv_puts(bstr("city"));
372 serv_puts(bstr("state"));
373 serv_puts(bstr("zip"));
374 serv_puts(bstr("phone"));
375 serv_puts(bstr("email"));
376 serv_puts(bstr("country"));
379 if (atoi(bstr("during_login"))) {
382 display_success("Registration information has been saved.");
391 * display form for changing your password
393 void display_changepw(void)
399 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
400 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
401 wprintf("<B>Change your password</B>\n");
402 wprintf("</FONT></TD></TR></TABLE>\n");
405 serv_puts("MESG changepw");
410 wprintf("<FORM ACTION=\"changepw\" METHOD=\"POST\">\n");
411 wprintf("<CENTER><TABLE border><TR><TD>Enter new password:</TD>\n");
412 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
413 wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
414 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
415 wprintf("</TABLE>\n");
416 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Change\">\n");
417 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
418 wprintf("</CENTER>\n");
428 char newpass1[32], newpass2[32];
430 if (strcmp(bstr("action"), "Change")) {
431 display_error("Cancelled. Password was not changed.");
434 strcpy(newpass1, bstr("newpass1"));
435 strcpy(newpass2, bstr("newpass2"));
437 if (strcasecmp(newpass1, newpass2)) {
438 display_error("They don't match. Password was not changed.");
441 serv_printf("SETP %s", newpass1);
444 display_success(&buf[4]);
446 display_error(&buf[4]);