3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-15 00:19:29 +01:00

Merge pull request #1952 from slingamn/saverify.1

add SAVERIFY command
This commit is contained in:
Shivaram Lingamneni 2022-05-05 22:40:07 -04:00 committed by GitHub
commit 4948b48b8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 18 deletions

View File

@ -821,7 +821,7 @@ func (am *AccountManager) dispatchMailtoCallback(client *Client, account string,
return return
} }
func (am *AccountManager) Verify(client *Client, account string, code string) error { func (am *AccountManager) Verify(client *Client, account string, code string, admin bool) error {
casefoldedAccount, err := CasefoldName(account) casefoldedAccount, err := CasefoldName(account)
var skeleton string var skeleton string
if err != nil || account == "" || account == "*" { if err != nil || account == "" || account == "*" {
@ -884,18 +884,20 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
return errAccountAlreadyVerified return errAccountAlreadyVerified
} }
// actually verify the code if !admin {
// a stored code of "" means a none callback / no code required // actually verify the code
success := false // a stored code of "" means a none callback / no code required
storedCode, err := tx.Get(verificationCodeKey) success := false
if err == nil { storedCode, err := tx.Get(verificationCodeKey)
// this is probably unnecessary if err == nil {
if storedCode == "" || utils.SecretTokensMatch(storedCode, code) { // this is probably unnecessary
success = true if storedCode == "" || utils.SecretTokensMatch(storedCode, code) {
success = true
}
}
if !success {
return errAccountVerificationInvalidCode
} }
}
if !success {
return errAccountVerificationInvalidCode
} }
// verify the account // verify the account
@ -964,7 +966,7 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
func (am *AccountManager) SARegister(account, passphrase string) (err error) { func (am *AccountManager) SARegister(account, passphrase string) (err error) {
err = am.Register(nil, account, "admin", "", passphrase, "") err = am.Register(nil, account, "admin", "", passphrase, "")
if err == nil { if err == nil {
err = am.Verify(nil, account, "") err = am.Verify(nil, account, "", true)
} }
return return
} }

View File

@ -2632,7 +2632,7 @@ func registerHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
switch err { switch err {
case nil: case nil:
if callbackNamespace == "*" { if callbackNamespace == "*" {
err := server.accounts.Verify(client, accountName, "") err := server.accounts.Verify(client, accountName, "", true)
if err == nil { if err == nil {
if client.registered { if client.registered {
if !fixupNickEqualsAccount(client, rb, config, "") { if !fixupNickEqualsAccount(client, rb, config, "") {
@ -2684,7 +2684,7 @@ func verifyHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respo
} }
accountName, verificationCode := msg.Params[0], msg.Params[1] accountName, verificationCode := msg.Params[0], msg.Params[1]
err := server.accounts.Verify(client, accountName, verificationCode) err := server.accounts.Verify(client, accountName, verificationCode, false)
if err == nil && client.registered { if err == nil && client.registered {
if !fixupNickEqualsAccount(client, rb, config, "") { if !fixupNickEqualsAccount(client, rb, config, "") {
err = errNickAccountMismatch err = errNickAccountMismatch

View File

@ -164,7 +164,17 @@ SAREGISTER registers an account on someone else's behalf.
This is for use in configurations that require SASL for all connections; This is for use in configurations that require SASL for all connections;
an administrator can set use this command to set up user accounts.`, an administrator can set use this command to set up user accounts.`,
helpShort: `$bSAREGISTER$b registers an account on someone else's behalf.`, helpShort: `$bSAREGISTER$b registers an account on someone else's behalf.`,
enabled: servCmdRequiresAuthEnabled, enabled: servCmdRequiresAuthEnabled, // deliberate
capabs: []string{"accreg"},
minParams: 1,
},
"saverify": {
handler: nsSaverifyHandler,
help: `Syntax: $bSAVERIFY <username>$b
SAVERIFY manually verifies an account that is pending verification.`,
helpShort: `$bSAREGISTER$b registers an account on someone else's behalf.`,
enabled: servCmdRequiresAuthEnabled, // deliberate
capabs: []string{"accreg"}, capabs: []string{"accreg"},
minParams: 1, minParams: 1,
}, },
@ -996,7 +1006,7 @@ func nsRegisterHandler(service *ircService, server *Server, client *Client, comm
err := server.accounts.Register(client, account, callbackNamespace, callbackValue, passphrase, rb.session.certfp) err := server.accounts.Register(client, account, callbackNamespace, callbackValue, passphrase, rb.session.certfp)
if err == nil { if err == nil {
if callbackNamespace == "*" { if callbackNamespace == "*" {
err = server.accounts.Verify(client, account, "") err = server.accounts.Verify(client, account, "", true)
if err == nil && fixupNickEqualsAccount(client, rb, config, service.prefix) { if err == nil && fixupNickEqualsAccount(client, rb, config, service.prefix) {
sendSuccessfulRegResponse(service, client, rb) sendSuccessfulRegResponse(service, client, rb)
} }
@ -1038,6 +1048,16 @@ func nsSaregisterHandler(service *ircService, server *Server, client *Client, co
} }
} }
func nsSaverifyHandler(service *ircService, server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
account := params[0]
err := server.accounts.Verify(nil, account, "", true)
if err == nil {
service.Notice(rb, fmt.Sprintf(client.t("Successfully verified account %s"), account))
} else {
service.Notice(rb, fmt.Sprintf(client.t("Failed to verify account %s: %v"), account, err.Error()))
}
}
func nsUnregisterHandler(service *ircService, server *Server, client *Client, command string, params []string, rb *ResponseBuffer) { func nsUnregisterHandler(service *ircService, server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
erase := command == "erase" erase := command == "erase"
@ -1106,7 +1126,7 @@ func nsUnregisterHandler(service *ircService, server *Server, client *Client, co
func nsVerifyHandler(service *ircService, server *Server, client *Client, command string, params []string, rb *ResponseBuffer) { func nsVerifyHandler(service *ircService, server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
username, code := params[0], params[1] username, code := params[0], params[1]
err := server.accounts.Verify(client, username, code) err := server.accounts.Verify(client, username, code, false)
var errorMessage string var errorMessage string
if err != nil { if err != nil {