* Completed the code for creating a new account, manually specifying
authorArt Cancro <ajc@citadel.org>
Thu, 5 Jun 2008 02:32:46 +0000 (02:32 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 5 Jun 2008 02:32:46 +0000 (02:32 +0000)
  the account name, when an OpenID was verified but the desired nickname
  either was not supplied or conflicts with an existing user.
* The SETP command can now be passed a special string that tells it the
  client wants the server to auto-generate a random password.

citadel/modules/openid/serv_openid_rp.c
citadel/user_ops.c
webcit/auth.c
webcit/static/openid_manual_create.html

index 0729c62de02722893a3a8e2be2c5d8add4096685..b74a3f88653ae5ed20143430128c9111235667b8 100644 (file)
@@ -181,6 +181,31 @@ void cmd_oidl(char *argbuf) {
 }
 
 
+/*
+ * Create a new user account, manually specifying the name, after successfully
+ * verifying an OpenID (which will of course be attached to the account)
+ */
+void cmd_oidc(char *argbuf) {
+       struct ctdl_openid *oiddata = (struct ctdl_openid *) CC->openid_data;
+
+       if (!oiddata->verified) {
+               cprintf("%d You have not verified an OpenID yet.\n", ERROR);
+               return;
+       }
+
+       /* We can make the semantics of OIDC exactly the same as NEWU, simply
+        * by _calling_ cmd_newu() and letting it run.  Very clever!
+        */
+       cmd_newu(argbuf);
+
+       /* Now, if this logged us in, we have to attach the OpenID */
+       if (CC->logged_in) {
+               attach_openid(&CC->user, oiddata->claimed_id);
+       }
+}
+
+
+
 
 /*
  * Detach an OpenID from the currently logged in account
@@ -778,6 +803,7 @@ CTDL_MODULE_INIT(openid_rp)
                CtdlRegisterProtoHook(cmd_oidf, "OIDF", "Finalize OpenID authentication");
                CtdlRegisterProtoHook(cmd_oidl, "OIDL", "List OpenIDs associated with an account");
                CtdlRegisterProtoHook(cmd_oidd, "OIDD", "Detach an OpenID from an account");
+               CtdlRegisterProtoHook(cmd_oidc, "OIDC", "Create a new user after validating an OpenID");
                CtdlRegisterSessionHook(openid_cleanup_function, EVT_LOGOUT);
                CtdlRegisterUserHook(openid_purge, EVT_PURGEUSER);
        }
@@ -785,7 +811,3 @@ CTDL_MODULE_INIT(openid_rp)
        /* return our Subversion id for the Log */
        return "$Id$";
 }
-
-
-/* FIXME ... we have to add the new openid database to serv_vandelay.c */
-
index 4f4ba6795d57581541be5d51cf308b1fa556e592..6baed0b2ee2607b20cba91b333a19c4d3ecec395 100644 (file)
@@ -1200,6 +1200,8 @@ void CtdlSetPassword(char *new_pw)
  */
 void cmd_setp(char *new_pw)
 {
+       int generate_random_password = 0;
+
        if (CtdlAccessCheck(ac_logged_in)) {
                return;
        }
@@ -1212,14 +1214,23 @@ void cmd_setp(char *new_pw)
                        ERROR + NOT_HERE);
                return;
        }
-       strproc(new_pw);
-       if (IsEmptyStr(new_pw)) {
-               cprintf("%d Password unchanged.\n", CIT_OK);
-               return;
-       }
 
-       CtdlSetPassword(new_pw);
-       cprintf("%d Password changed.\n", CIT_OK);
+       if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
+               char random_password[17];
+               generate_random_password = 1;
+               snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
+               CtdlSetPassword(random_password);
+               cprintf("%d %s\n", CIT_OK, random_password);
+       }
+       else {
+               strproc(new_pw);
+               if (IsEmptyStr(new_pw)) {
+                       cprintf("%d Password unchanged.\n", CIT_OK);
+                       return;
+               }
+               CtdlSetPassword(new_pw);
+               cprintf("%d Password changed.\n", CIT_OK);
+       }
 }
 
 
index 25d1e95c75ea84d30789f55769afc71b197d003c..8b54dc53d348a2fff9795d71ef66c0d470185892 100644 (file)
@@ -161,6 +161,8 @@ void display_openid_name_request(char *claimed_id, char *username) {
        stresc(buf, sizeof buf, claimed_id, 0, 0);
        svprintf(HKEY("VERIFIED"), WCS_STRING, _("Your OpenID <tt>%s</tt> was successfully verified."),
                claimed_id);
+       svput("CLAIMED_ID", WCS_STRING, claimed_id);
+
 
        if (!IsEmptyStr(username)) {
                stresc(buf, sizeof buf, username, 0, 0);
@@ -302,19 +304,17 @@ void openid_manual_create(void)
                return;
        }
 
-#if 0 
-       char buf[SIZ];
+       char buf[1024];
        if (havebstr("newuser_action")) {
                serv_printf("OIDC %s", bstr("name"));
                serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
-                       become_logged_in(bstr("name"), bstr("pass"), buf);              // FIXME
-               } else {
-                       display_openid_name_request(char *claimed_id, char *username);  // FIXME
-                       return;
+                       char gpass[1024] = "";
+                       serv_puts("SETP GENERATE_RANDOM_PASSWORD");
+                       serv_getln(gpass, sizeof gpass);
+                       become_logged_in(bstr("name"), &gpass[4], buf);
                }
        }
-#endif
 
        if (WC->logged_in) {
                if (WC->need_regi) {
@@ -325,7 +325,7 @@ void openid_manual_create(void)
                        do_welcome();
                }
        } else {
-               display_login(_("Your password was not accepted."));
+               display_openid_name_request(bstr("openid_url"), bstr("name"));
        }
 
 }
index 2f4607086a3b0ab5c1ceb1be62992eed0caef6dc..7b4807de0f6c31ca016f320776cb8ef3623d0459 100644 (file)
@@ -6,6 +6,7 @@
        <?ACTION_REQUESTED><br />
 </div>
 <form action="openid_manual_create" method="POST"  class="box" id="login_form">
+       <input type="hidden" NAME="openid_url" VALUE="<?CLAIMED_ID>">
         <label for="uname"><?USERNAME_BOX></label>
         <input type="text" name="name" id="uname" > <br>
         <div class="logbuttons">