reg: Rename commands to match

This commit is contained in:
Daniel Oaks 2017-03-08 21:36:13 +10:00
parent fd793d6adb
commit ff82872934
3 changed files with 31 additions and 31 deletions

View File

@ -55,23 +55,23 @@ func NewAccountRegistration(config AccountRegistrationConfig) (accountReg Accoun
return accountReg return accountReg
} }
// regHandler parses the REG command. // accHandler parses the ACC command.
func regHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { func accHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
subcommand := strings.ToLower(msg.Params[0]) subcommand := strings.ToLower(msg.Params[0])
if subcommand == "create" { if subcommand == "register" {
return regCreateHandler(server, client, msg) return accRegisterHandler(server, client, msg)
} else if subcommand == "verify" { } else if subcommand == "verify" {
client.Notice("Parsing VERIFY") client.Notice("VERIFY is not yet implemented")
} else { } else {
client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "REG", msg.Params[0], "Unknown subcommand") client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "ACC", msg.Params[0], "Unknown subcommand")
} }
return false return false
} }
// removeFailedRegCreateData removes the data created by REG CREATE if the account creation fails early. // removeFailedAccRegisterData removes the data created by ACC REGISTER if the account creation fails early.
func removeFailedRegCreateData(store *buntdb.DB, account string) { func removeFailedAccRegisterData(store *buntdb.DB, account string) {
// error is ignored here, we can't do much about it anyways // error is ignored here, we can't do much about it anyways
store.Update(func(tx *buntdb.Tx) error { store.Update(func(tx *buntdb.Tx) error {
tx.Delete(fmt.Sprintf(keyAccountExists, account)) tx.Delete(fmt.Sprintf(keyAccountExists, account))
@ -82,8 +82,8 @@ func removeFailedRegCreateData(store *buntdb.DB, account string) {
}) })
} }
// regCreateHandler parses the REG CREATE command. // accRegisterHandler parses the ACC REGISTER command.
func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { func accRegisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// make sure reg is enabled // make sure reg is enabled
if !server.accountRegistration.Enabled { if !server.accountRegistration.Enabled {
client.Send(nil, server.name, ERR_REG_UNSPECIFIED_ERROR, client.nick, "*", "Account registration is disabled") client.Send(nil, server.name, ERR_REG_UNSPECIFIED_ERROR, client.nick, "*", "Account registration is disabled")
@ -122,7 +122,7 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
// account could not be created and relevant numerics have been dispatched, abort // account could not be created and relevant numerics have been dispatched, abort
if err != nil { if err != nil {
if err != errAccountCreation { if err != errAccountCreation {
client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "REG", "CREATE", "Could not register") client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "ACC", "REGISTER", "Could not register")
log.Println("Could not save registration initial data:", err.Error()) log.Println("Could not save registration initial data:", err.Error())
} }
return false return false
@ -153,7 +153,7 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
if !callbackValid { if !callbackValid {
client.Send(nil, server.name, ERR_REG_INVALID_CALLBACK, client.nick, account, callbackNamespace, "Callback namespace is not supported") client.Send(nil, server.name, ERR_REG_INVALID_CALLBACK, client.nick, account, callbackNamespace, "Callback namespace is not supported")
removeFailedRegCreateData(server.store, casefoldedAccount) removeFailedAccRegisterData(server.store, casefoldedAccount)
return false return false
} }
@ -168,7 +168,7 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
credentialValue = msg.Params[3] credentialValue = msg.Params[3]
} else { } else {
client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, msg.Command, "Not enough parameters") client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, msg.Command, "Not enough parameters")
removeFailedRegCreateData(server.store, casefoldedAccount) removeFailedAccRegisterData(server.store, casefoldedAccount)
return false return false
} }
@ -180,14 +180,14 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
} }
} }
if credentialType == "certfp" && client.certfp == "" { if credentialType == "certfp" && client.certfp == "" {
client.Send(nil, server.name, ERR_REG_INVALID_CRED_TYPE, client.nick, credentialType, callbackNamespace, "You are not using a certificate") client.Send(nil, server.name, ERR_REG_INVALID_CRED_TYPE, client.nick, credentialType, callbackNamespace, "You are not using a certificiate")
removeFailedRegCreateData(server.store, casefoldedAccount) removeFailedAccRegisterData(server.store, casefoldedAccount)
return false return false
} }
if !credentialValid { if !credentialValid {
client.Send(nil, server.name, ERR_REG_INVALID_CRED_TYPE, client.nick, credentialType, callbackNamespace, "Credential type is not supported") client.Send(nil, server.name, ERR_REG_INVALID_CRED_TYPE, client.nick, credentialType, callbackNamespace, "Credential type is not supported")
removeFailedRegCreateData(server.store, casefoldedAccount) removeFailedAccRegisterData(server.store, casefoldedAccount)
return false return false
} }
@ -238,9 +238,9 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
if err == errCertfpAlreadyExists { if err == errCertfpAlreadyExists {
errMsg = "An account already exists for your certificate fingerprint" errMsg = "An account already exists for your certificate fingerprint"
} }
client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "REG", "CREATE", errMsg) client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "ACC", "REGISTER", errMsg)
log.Println("Could not save registration creds:", err.Error()) log.Println("Could not save registration creds:", err.Error())
removeFailedRegCreateData(server.store, casefoldedAccount) removeFailedAccRegisterData(server.store, casefoldedAccount)
return false return false
} }
@ -265,9 +265,9 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
return nil return nil
}) })
if err != nil { if err != nil {
client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "REG", "CREATE", "Could not register") client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "ACC", "REGISTER", "Could not register")
log.Println("Could not save verification confirmation (*):", err.Error()) log.Println("Could not save verification confirmation (*):", err.Error())
removeFailedRegCreateData(server.store, casefoldedAccount) removeFailedAccRegisterData(server.store, casefoldedAccount)
return false return false
} }

View File

@ -56,6 +56,10 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b
// Commands holds all commands executable by a client connected to us. // Commands holds all commands executable by a client connected to us.
var Commands = map[string]Command{ var Commands = map[string]Command{
"ACC": {
handler: accHandler,
minParams: 3,
},
"AMBIANCE": { "AMBIANCE": {
handler: sceneHandler, handler: sceneHandler,
minParams: 2, minParams: 2,
@ -227,10 +231,6 @@ var Commands = map[string]Command{
usablePreReg: true, usablePreReg: true,
minParams: 0, minParams: 0,
}, },
"REG": {
handler: regHandler,
minParams: 3,
},
"REHASH": { "REHASH": {
handler: rehashHandler, handler: rehashHandler,
minParams: 0, minParams: 0,

View File

@ -67,6 +67,13 @@ Oragono supports the following user modes:
// Help contains the help strings distributed with the IRCd. // Help contains the help strings distributed with the IRCd.
var Help = map[string]HelpEntry{ var Help = map[string]HelpEntry{
// Commands // Commands
"acc": {
text: `ACC REGISTER <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
ACC VERIFY <accountname> <auth_code>
Used in account registration. See the relevant specs for more info:
http://oragono.io/specs.html`,
},
"ambiance": { "ambiance": {
text: `AMBIANCE <target> <text to be sent> text: `AMBIANCE <target> <text to be sent>
@ -350,13 +357,6 @@ specs for more info: http://ircv3.net/specs/core/message-tags-3.3.html`,
text: `QUIT [reason] text: `QUIT [reason]
Indicates that you're leaving the server, and shows everyone the given reason.`, Indicates that you're leaving the server, and shows everyone the given reason.`,
},
"reg": {
text: `REG CREATE <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
REG VERIFY <accountname> <auth_code>
Used in account registration. See the relevant specs for more info:
http://oragono.io/specs.html`,
}, },
"rehash": { "rehash": {
oper: true, oper: true,