nickserv: email confirmation (CONFIRM) on registration

When email is configured and a REGISTER includes an address, the account
starts unverified and a confirmation code is emailed. CONFIRM <code>
verifies it (a federated AccountVerified event); INFO shows an unconfirmed
email until then. Emailed codes now carry a purpose (reset vs confirm).
This commit is contained in:
Jean Chevronnet 2026-07-12 15:36:30 +00:00
parent a2957ffe02
commit fbcf0eaac7
No known key found for this signature in database
6 changed files with 140 additions and 20 deletions

View file

@ -0,0 +1,26 @@
use crate::engine::db::{CodeKind, Db};
use crate::engine::service::{Sender, ServiceCtx};
// CONFIRM <code>: confirm your account's email with the code you were emailed.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut Db) {
let Some(&code) = args.get(1) else {
ctx.notice(me, from.uid, "Syntax: CONFIRM <code>");
return;
};
let Some(account) = from.account.map(str::to_string).or_else(|| db.resolve_account(from.nick).map(str::to_string)) else {
ctx.notice(me, from.uid, "You don't have an account to confirm.");
return;
};
if db.is_verified(&account) {
ctx.notice(me, from.uid, format!("\x02{account}\x02 is already confirmed."));
return;
}
if !db.take_code(&account, CodeKind::Confirm, code) {
ctx.notice(me, from.uid, "Invalid or expired confirmation code.");
return;
}
match db.verify_account(&account) {
Ok(()) => ctx.notice(me, from.uid, format!("\x02{account}\x02 is now confirmed. Thanks!")),
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}

View file

@ -13,7 +13,8 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
ctx.notice(me, from.uid, format!(" Registered : {}", human_time(acct.ts)));
if from.account == Some(acct.name.as_str()) {
match &acct.email {
Some(email) => ctx.notice(me, from.uid, format!(" Email : {email}")),
Some(email) if acct.verified => ctx.notice(me, from.uid, format!(" Email : {email}")),
Some(email) => ctx.notice(me, from.uid, format!(" Email : {email} (unconfirmed)")),
None => ctx.notice(me, from.uid, " Email : (none set)"),
}
}

View file

@ -28,6 +28,8 @@ mod ungroup;
mod ghost;
#[path = "resetpass.rs"]
mod resetpass;
#[path = "confirm.rs"]
mod confirm;
pub struct NickServ {
pub uid: String,
@ -67,7 +69,8 @@ impl Service for NickServ {
Some("UNGROUP") => ungroup::handle(me, from, args, ctx, db),
Some("GHOST") | Some("RECOVER") => ghost::handle(me, &self.guest_nick, &mut self.guest_seq, from, args, ctx, net, db),
Some("RESETPASS") => resetpass::handle(me, from, args, ctx, db),
Some("HELP") => ctx.notice(me, from.uid, "NickServ looks after your nickname. Commands: \x02REGISTER\x02 <password> [email], \x02IDENTIFY\x02 [account] <password>, \x02INFO\x02 [account], \x02ALIST\x02, \x02GROUP\x02/\x02GLIST\x02/\x02UNGROUP\x02, \x02GHOST\x02 <nick> [password], \x02SET\x02 PASSWORD|EMAIL, \x02RESETPASS\x02 <account>, \x02DROP\x02 <password>, \x02LOGOUT\x02, \x02CERT\x02 ADD|DEL|LIST <password> [fingerprint]."),
Some("CONFIRM") => confirm::handle(me, from, args, ctx, db),
Some("HELP") => ctx.notice(me, from.uid, "NickServ looks after your nickname. Commands: \x02REGISTER\x02 <password> [email], \x02IDENTIFY\x02 [account] <password>, \x02INFO\x02 [account], \x02ALIST\x02, \x02GROUP\x02/\x02GLIST\x02/\x02UNGROUP\x02, \x02GHOST\x02 <nick> [password], \x02SET\x02 PASSWORD|EMAIL, \x02RESETPASS\x02 <account>, \x02CONFIRM\x02 <code>, \x02DROP\x02 <password>, \x02LOGOUT\x02, \x02CERT\x02 ADD|DEL|LIST <password> [fingerprint]."),
Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")),
None => {}
}

View file

@ -1,4 +1,4 @@
use crate::engine::db::Db;
use crate::engine::db::{CodeKind, Db};
use crate::engine::service::{Sender, ServiceCtx};
// RESETPASS <account>: email a reset code to the address on file.
@ -18,7 +18,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
ctx.notice(me, from.uid, "That account has no email on file, so it can't be reset.");
return;
};
let code = db.issue_reset_code(&canonical);
let code = db.issue_code(&canonical, CodeKind::Reset);
ctx.send_email(
email,
format!("Password reset for {canonical}"),
@ -31,7 +31,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
ctx.notice(me, from.uid, format!("\x02{name}\x02 isn't registered."));
return;
};
if !db.take_reset_code(&canonical, code) {
if !db.take_code(&canonical, CodeKind::Reset, code) {
ctx.notice(me, from.uid, "Invalid or expired reset code.");
return;
}