| 1 |
/* |
| 2 |
* Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net> |
| 3 |
* Copyright (c) 2007 Jilles Tjoelker |
| 4 |
* Rights to this code are as documented in doc/LICENSE. |
| 5 |
* |
| 6 |
* Changes your e-mail address. |
| 7 |
* |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "atheme.h" |
| 11 |
#include "uplink.h" |
| 12 |
|
| 13 |
DECLARE_MODULE_V1 |
| 14 |
( |
| 15 |
"nickserv/set_email", false, _modinit, _moddeinit, |
| 16 |
PACKAGE_STRING, |
| 17 |
VENDOR_STRING |
| 18 |
); |
| 19 |
|
| 20 |
mowgli_patricia_t **ns_set_cmdtree; |
| 21 |
|
| 22 |
static void ns_cmd_set_email(sourceinfo_t *si, int parc, char *parv[]); |
| 23 |
|
| 24 |
command_t ns_set_email = { "EMAIL", N_("Changes your e-mail address."), AC_NONE, 1, ns_cmd_set_email, { .path = "nickserv/set_email" } }; |
| 25 |
|
| 26 |
void _modinit(module_t *m) |
| 27 |
{ |
| 28 |
MODULE_TRY_REQUEST_SYMBOL(m, ns_set_cmdtree, "nickserv/set_core", "ns_set_cmdtree"); |
| 29 |
|
| 30 |
command_add(&ns_set_email, *ns_set_cmdtree); |
| 31 |
} |
| 32 |
|
| 33 |
void _moddeinit(module_unload_intent_t intent) |
| 34 |
{ |
| 35 |
command_delete(&ns_set_email, *ns_set_cmdtree); |
| 36 |
} |
| 37 |
|
| 38 |
/* SET EMAIL <new address> */ |
| 39 |
static void ns_cmd_set_email(sourceinfo_t *si, int parc, char *parv[]) |
| 40 |
{ |
| 41 |
char *email = parv[0]; |
| 42 |
metadata_t *md; |
| 43 |
|
| 44 |
if (!email) |
| 45 |
{ |
| 46 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "EMAIL"); |
| 47 |
command_fail(si, fault_needmoreparams, _("Syntax: SET EMAIL <new e-mail>")); |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
if (!strcasecmp(si->smu->email, email)) |
| 52 |
{ |
| 53 |
md = metadata_find(si->smu, "private:verify:emailchg:newemail"); |
| 54 |
if (md != NULL) |
| 55 |
{ |
| 56 |
command_success_nodata(si, _("The email address change to \2%s\2 has been cancelled."), md->value); |
| 57 |
metadata_delete(si->smu, "private:verify:emailchg:key"); |
| 58 |
metadata_delete(si->smu, "private:verify:emailchg:newemail"); |
| 59 |
metadata_delete(si->smu, "private:verify:emailchg:timestamp"); |
| 60 |
} |
| 61 |
else |
| 62 |
command_fail(si, fault_nochange, _("The email address for account \2%s\2 is already set to \2%s\2."), entity(si->smu)->name, si->smu->email); |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
if (!validemail(email)) |
| 67 |
{ |
| 68 |
command_fail(si, fault_badparams, _("\2%s\2 is not a valid email address."), email); |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
if (!email_within_limits(email)) |
| 73 |
{ |
| 74 |
command_fail(si, fault_toomany, _("\2%s\2 has too many accounts registered."), email); |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
if (me.auth == AUTH_EMAIL) |
| 79 |
{ |
| 80 |
unsigned long key = makekey(); |
| 81 |
|
| 82 |
metadata_add(si->smu, "private:verify:emailchg:key", number_to_string(key)); |
| 83 |
metadata_add(si->smu, "private:verify:emailchg:newemail", email); |
| 84 |
metadata_add(si->smu, "private:verify:emailchg:timestamp", number_to_string(CURRTIME)); |
| 85 |
|
| 86 |
if (!sendemail(si->su != NULL ? si->su : si->service->me, si->smu, EMAIL_SETEMAIL, email, number_to_string(key))) |
| 87 |
{ |
| 88 |
command_fail(si, fault_emailfail, _("Sending email failed, sorry! Your email address is unchanged.")); |
| 89 |
metadata_delete(si->smu, "private:verify:emailchg:key"); |
| 90 |
metadata_delete(si->smu, "private:verify:emailchg:newemail"); |
| 91 |
metadata_delete(si->smu, "private:verify:emailchg:timestamp"); |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
logcommand(si, CMDLOG_SET, "SET:EMAIL: \2%s\2 (\2%s\2 -> \2%s\2) (awaiting verification)", entity(si->smu)->name, si->smu->email, email); |
| 96 |
command_success_nodata(si, _("An email containing email changing instructions has been sent to \2%s\2."), email); |
| 97 |
command_success_nodata(si, _("Your email address will not be changed until you follow these instructions.")); |
| 98 |
|
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
logcommand(si, CMDLOG_SET, "SET:EMAIL: \2%s\2 (\2%s\2 -> \2%s\2)", entity(si->smu)->name, si->smu->email, email); |
| 103 |
myuser_set_email(si->smu, email); |
| 104 |
command_success_nodata(si, _("The email address for account \2%s\2 has been changed to \2%s\2."), entity(si->smu)->name, si->smu->email); |
| 105 |
} |
| 106 |
|
| 107 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 108 |
* vim:ts=8 |
| 109 |
* vim:sw=8 |
| 110 |
* vim:noexpandtab |
| 111 |
*/ |