3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

replace ACC UNREGISTER with nickserv unregister

This commit is contained in:
Shivaram Lingamneni 2018-02-12 01:09:30 -05:00
parent af256fccd3
commit 73391f11a6
4 changed files with 44 additions and 30 deletions

View File

@ -368,6 +368,9 @@ func (am *AccountManager) Unregister(account string) error {
client.LogoutOfAccount()
}
if err != nil {
return errAccountDoesNotExist
}
return nil
}

View File

@ -70,7 +70,7 @@ func init() {
Commands = map[string]Command{
"ACC": {
handler: accHandler,
minParams: 2,
minParams: 3,
},
"AMBIANCE": {
handler: sceneHandler,

View File

@ -41,8 +41,6 @@ func accHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo
return accRegisterHandler(server, client, msg, rb)
} else if subcommand == "verify" {
rb.Notice(client.t("VERIFY is not yet implemented"))
} else if subcommand == "unregister" {
return accUnregisterHandler(server, client, msg, rb)
} else {
rb.Add(nil, server.name, ERR_UNKNOWNERROR, client.nick, "ACC", msg.Params[0], client.t("Unknown subcommand"))
}
@ -50,33 +48,6 @@ func accHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo
return false
}
// ACC UNREGISTER <accountname>
func accUnregisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
// get and sanitise account name
account := strings.TrimSpace(msg.Params[1])
casefoldedAccount, err := CasefoldName(account)
// probably don't need explicit check for "*" here... but let's do it anyway just to make sure
if err != nil || msg.Params[1] == "*" {
rb.Add(nil, server.name, ERR_REG_UNSPECIFIED_ERROR, client.nick, account, client.t("Account name is not valid"))
return false
}
if !(account == client.Account() || client.HasRoleCapabs("unregister")) {
rb.Add(nil, server.name, ERR_NOPRIVS, client.Nick(), account, client.t("Insufficient oper privs"))
return false
}
err = server.accounts.Unregister(account)
// TODO better responses all around here
if err != nil {
errorMsg := fmt.Sprintf("Unknown error while unregistering account %s", casefoldedAccount)
rb.Add(nil, server.name, ERR_UNKNOWNERROR, client.Nick(), msg.Command, errorMsg)
return false
}
rb.Notice(fmt.Sprintf("Successfully unregistered account %s", casefoldedAccount))
return false
}
// ACC REGISTER <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
func accRegisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
// make sure reg is enabled

View File

@ -17,6 +17,10 @@ To register an account:
/NS REGISTER username [password]
Leave out [password] if you're registering using your client certificate fingerprint.
To unregister an account:
/NS UNREGISTER [username]
Leave out [username] if you're unregistering the user you're currently logged in as.
To login to an account:
/NS IDENTIFY [username password]
Leave out [username password] to use your client certificate fingerprint. Otherwise,
@ -63,11 +67,47 @@ func (server *Server) nickservPrivmsgHandler(client *Client, message string, rb
username, passphrase := extractParam(params)
server.nickservIdentifyHandler(client, username, passphrase, rb)
} else if command == "unregister" {
username, _ := extractParam(params)
server.nickservUnregisterHandler(client, username, rb)
} else {
rb.Notice(client.t("Command not recognised. To see the available commands, run /NS HELP"))
}
}
func (server *Server) nickservUnregisterHandler(client *Client, username string, rb *ResponseBuffer) {
if !server.AccountConfig().Registration.Enabled {
rb.Notice(client.t("Account registration has been disabled"))
return
}
if username == "" {
username = client.Account()
}
if username == "" {
rb.Notice(client.t("You're not logged into an account"))
return
}
cfname, err := CasefoldName(username)
if err != nil {
rb.Notice(client.t("Invalid username"))
return
}
if !(cfname == client.Account() || client.HasRoleCapabs("unregister")) {
rb.Notice(client.t("Insufficient oper privs"))
return
}
err = server.accounts.Unregister(cfname)
if err == errAccountDoesNotExist {
rb.Notice(client.t(err.Error()))
} else if err != nil {
rb.Notice(client.t("Error while unregistering account"))
} else {
rb.Notice(fmt.Sprintf(client.t("Successfully unregistered account %s"), cfname))
}
}
func (server *Server) nickservRegisterHandler(client *Client, username, passphrase string, rb *ResponseBuffer) {
certfp := client.certfp
if passphrase == "" && certfp == "" {