}
+/*
+ * 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);
+ /* populate_vcard_from_sreg(FIXME GET THE SREG DATA IN HERE SOMEHOW); */
+ }
+
+}
+
+
+
/*
* Detach an OpenID from the currently logged in account
+/*
+ * Attempt to register (populate the vCard) the currently-logged-in user
+ * using the data from Simple Registration Extension, if present.
+ */
+void populate_vcard_from_sreg(HashList *sreg_keys) {
+
+ struct vCard *v;
+ int pop = 0; /* number of fields populated */
+ char *data = NULL;
+ char *postcode = NULL;
+ char *country = NULL;
+
+ if (!sreg_keys) return;
+ v = vcard_new();
+ if (!v) return;
+
+ if (GetHash(sreg_keys, "identity", 8, (void *) &data)) {
+ vcard_add_prop(v, "url;type=openid", data);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.email", 10, (void *) &data)) {
+ vcard_add_prop(v, "email;internet", data);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.nickname", 13, (void *) &data)) {
+ vcard_add_prop(v, "nickname", data);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.fullname", 13, (void *) &data)) {
+ char n[256];
+ vcard_add_prop(v, "fn", data);
+ vcard_fn_to_n(n, data, sizeof n);
+ vcard_add_prop(v, "n", n);
+ ++pop;
+ }
+
+ if (!GetHash(sreg_keys, "sreg.postcode", 13, (void *) &postcode)) {
+ postcode = NULL;
+ }
+
+ if (!GetHash(sreg_keys, "sreg.country", 12, (void *) &country)) {
+ country = NULL;
+ }
+
+ if (postcode || country) {
+ char adr[256];
+ snprintf(adr, sizeof adr, ";;;;;%s;%s",
+ (postcode ? postcode : ""),
+ (country ? country : "")
+ );
+ vcard_add_prop(v, "adr", adr);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.dob", 8, (void *) &data)) {
+ vcard_add_prop(v, "bday", data);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.gender", 11, (void *) &data)) {
+ vcard_add_prop(v, "x-funambol-gender", data);
+ ++pop;
+ }
+
+ /* Only save the vCard if there is some useful data in it */
+ if (pop > 0) {
+ char temp[PATH_MAX];
+ FILE *fp;
+ char *ser;
+
+ CtdlMakeTempFileName(temp, sizeof temp);
+ ser = vcard_serialize(v);
+ if (ser) {
+ CtdlLogPrintf(CTDL_DEBUG, "--- BEGIN VCARD ---\n%s\n--- END VCARD ---\n", ser);
+ fp = fopen(temp, "w");
+ if (fp) {
+ fwrite(ser, strlen(ser), 1, fp);
+ fclose(fp);
+ CtdlWriteObject(USERCONFIGROOM, "text/x-vcard", temp, &CC->user, 0, 0, 0);
+ unlink(temp);
+ }
+ free(ser);
+ }
+ }
+ vcard_free(v);
+}
+
+
/*
* Attempt to auto-create a new Citadel account using the nickname from Simple Registration Extension
*/
-int openid_create_user_via_sri(char *claimed_id, HashList *sri_keys)
+int openid_create_user_via_sreg(char *claimed_id, HashList *sreg_keys)
{
char *desired_name = NULL;
char new_password[32];
if (config.c_auth_mode != AUTHMODE_NATIVE) return(1);
if (config.c_disable_newu) return(2);
if (CC->logged_in) return(3);
- if (!GetHash(sri_keys, "sreg.nickname", 13, (void *) &desired_name)) return(4);
+ if (!GetHash(sreg_keys, "sreg.nickname", 13, (void *) &desired_name)) return(4);
CtdlLogPrintf(CTDL_DEBUG, "The desired account name is <%s>\n", desired_name);
snprintf(new_password, sizeof new_password, "%08lx%08lx", random(), random());
CtdlSetPassword(new_password);
attach_openid(&CC->user, claimed_id);
+ populate_vcard_from_sreg(sreg_keys);
return(0);
}
-// FIXME we still have to set up the vCard
-
-// identity = [50] http://uncensored.citadel.org/~ajc/MyID.config.php
-// sreg.nickname = [17] IGnatius T Foobar
-// sreg.email = [26] ajc@uncensored.citadel.org
-// sreg.fullname = [10] Art Cancro
-// sreg.postcode = [5] 10549
-// sreg.country = [2] US
-
-
/*
* If a user account exists which is associated with the Claimed ID, log it in and return zero.
urlesc(escaped_return_to, sizeof escaped_return_to, return_to);
urlesc(escaped_trust_root, sizeof escaped_trust_root, trust_root);
urlesc(escaped_sreg_optional, sizeof escaped_sreg_optional,
- "nickname,email,fullname,postcode,country");
+ "nickname,email,fullname,postcode,country,dob,gender");
snprintf(redirect_string, sizeof redirect_string,
"%s"
/*
* New user whose OpenID is verified and Simple Registration Extension is in use?
*/
- else if (openid_create_user_via_sri(oiddata->claimed_id, keys) == 0) {
+ else if (openid_create_user_via_sreg(oiddata->claimed_id, keys) == 0) {
cprintf("authenticate\n%s\n%s\n", CC->user.fullname, CC->user.password);
logged_in_response();
}
}
cprintf("000\n");
- /*
- * We will eventually do something with the data in the hash list.
- *
- long len;
- void *Value;
- char *Key;
- HashPos *HashPos;
- HashPos = GetNewHashPos();
- while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
- {
- }
- DeleteHashPos(&HashPos);
- */
-
DeleteHash(&keys); /* This will free() all the key data for us */
}
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);
}
/* return our Subversion id for the Log */
return "$Id$";
}
-
-
-/* FIXME ... we have to add the new openid database to serv_vandelay.c */
-