mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
accounts: Fix broken numeric, write more framework for reg
This commit is contained in:
parent
e4b6c1852b
commit
e7fced804e
@ -155,6 +155,6 @@ const (
|
|||||||
ERR_ACCOUNT_ALREADY_VERIFIED = "924"
|
ERR_ACCOUNT_ALREADY_VERIFIED = "924"
|
||||||
ERR_ACCOUNT_INVALID_VERIFY_CODE = "925"
|
ERR_ACCOUNT_INVALID_VERIFY_CODE = "925"
|
||||||
RPL_REG_VERIFICATION_REQUIRED = "927"
|
RPL_REG_VERIFICATION_REQUIRED = "927"
|
||||||
|
ERR_REG_INVALID_CRED_TYPE = "928"
|
||||||
ERR_REG_INVALID_CALLBACK = "929"
|
ERR_REG_INVALID_CALLBACK = "929"
|
||||||
ERR_REG_INVALID_CRED_TYPE = "982"
|
|
||||||
)
|
)
|
||||||
|
@ -21,14 +21,20 @@ var (
|
|||||||
// AccountRegistration manages the registration of accounts.
|
// AccountRegistration manages the registration of accounts.
|
||||||
type AccountRegistration struct {
|
type AccountRegistration struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
EnabledRegistrationCallbackTypes []string
|
EnabledCallbackTypes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAccountRegistration returns a new AccountRegistration, configured correctly.
|
// NewAccountRegistration returns a new AccountRegistration, configured correctly.
|
||||||
func NewAccountRegistration(config AccountRegistrationConfig) (accountReg AccountRegistration) {
|
func NewAccountRegistration(config AccountRegistrationConfig) (accountReg AccountRegistration) {
|
||||||
if config.Enabled {
|
if config.Enabled {
|
||||||
accountReg.Enabled = true
|
accountReg.Enabled = true
|
||||||
accountReg.EnabledRegistrationCallbackTypes = config.EnabledCallbacks
|
for _, name := range config.EnabledCallbacks {
|
||||||
|
// we store "none" as "*" internally
|
||||||
|
if name == "none" {
|
||||||
|
name = "*"
|
||||||
|
}
|
||||||
|
accountReg.EnabledCallbackTypes = append(accountReg.EnabledCallbackTypes, name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return accountReg
|
return accountReg
|
||||||
}
|
}
|
||||||
@ -73,6 +79,58 @@ func regHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// account didn't already exist, continue with account creation and dispatching verification (if required)
|
// account didn't already exist, continue with account creation and dispatching verification (if required)
|
||||||
|
callback := strings.ToLower(msg.Params[2])
|
||||||
|
var callbackNamespace, callbackValue string
|
||||||
|
|
||||||
|
if callback == "*" {
|
||||||
|
callbackNamespace = "*"
|
||||||
|
} else if strings.Contains(callback, ":") {
|
||||||
|
callbackValues := strings.SplitN(callback, ":", 2)
|
||||||
|
callbackNamespace, callbackValue = callbackValues[0], callbackValues[1]
|
||||||
|
} else {
|
||||||
|
callbackNamespace = server.accountRegistration.EnabledCallbackTypes[0]
|
||||||
|
callbackValue = callback
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure the callback namespace is valid
|
||||||
|
// need to search callback list, maybe look at using a map later?
|
||||||
|
var callbackValid bool
|
||||||
|
for _, name := range server.accountRegistration.EnabledCallbackTypes {
|
||||||
|
if callbackNamespace == name {
|
||||||
|
callbackValid = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !callbackValid {
|
||||||
|
client.Send(nil, server.nameString, ERR_REG_INVALID_CALLBACK, client.nickString, msg.Params[1], callbackNamespace, "Callback namespace is not supported")
|
||||||
|
//TODO(dan): close out failed account reg (remove values from db)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure the credential type is valid
|
||||||
|
var credentialType, credentialValue string
|
||||||
|
|
||||||
|
if len(msg.Params) > 4 {
|
||||||
|
credentialType = strings.ToLower(msg.Params[3])
|
||||||
|
credentialValue = msg.Params[4]
|
||||||
|
} else if len(msg.Params) == 4 {
|
||||||
|
credentialType = "passphrase" // default from the spec
|
||||||
|
credentialValue = msg.Params[3]
|
||||||
|
} else {
|
||||||
|
client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters")
|
||||||
|
//TODO(dan): close out failed account reg (remove values from db)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// dispatch callback
|
||||||
|
if callbackNamespace != "*" {
|
||||||
|
client.Notice("Account creation was successful!")
|
||||||
|
//TODO(dan): close out failed account reg (remove values from db)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Notice(fmt.Sprintf("We should dispatch an actual callback here to %s:%s", callbackNamespace, callbackValue))
|
||||||
|
client.Notice(fmt.Sprintf("Primary account credential is with %s:%s", credentialType, credentialValue))
|
||||||
|
|
||||||
} else if subcommand == "verify" {
|
} else if subcommand == "verify" {
|
||||||
client.Notice("Parsing VERIFY")
|
client.Notice("Parsing VERIFY")
|
||||||
|
@ -159,8 +159,8 @@ func NewServer(config *Config) *Server {
|
|||||||
if server.accountRegistration.Enabled {
|
if server.accountRegistration.Enabled {
|
||||||
// 'none' isn't shown in the REGCALLBACKS vars
|
// 'none' isn't shown in the REGCALLBACKS vars
|
||||||
var enabledCallbackTypes []string
|
var enabledCallbackTypes []string
|
||||||
for _, name := range server.accountRegistration.EnabledRegistrationCallbackTypes {
|
for _, name := range server.accountRegistration.EnabledCallbackTypes {
|
||||||
if name != "none" {
|
if name != "*" {
|
||||||
enabledCallbackTypes = append(enabledCallbackTypes, name)
|
enabledCallbackTypes = append(enabledCallbackTypes, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user