|
@@ -20,15 +20,21 @@ var (
|
20
|
20
|
|
21
|
21
|
// AccountRegistration manages the registration of accounts.
|
22
|
22
|
type AccountRegistration struct {
|
23
|
|
- Enabled bool
|
24
|
|
- EnabledRegistrationCallbackTypes []string
|
|
23
|
+ Enabled bool
|
|
24
|
+ EnabledCallbackTypes []string
|
25
|
25
|
}
|
26
|
26
|
|
27
|
27
|
// NewAccountRegistration returns a new AccountRegistration, configured correctly.
|
28
|
28
|
func NewAccountRegistration(config AccountRegistrationConfig) (accountReg AccountRegistration) {
|
29
|
29
|
if config.Enabled {
|
30
|
30
|
accountReg.Enabled = true
|
31
|
|
- accountReg.EnabledRegistrationCallbackTypes = config.EnabledCallbacks
|
|
31
|
+ for _, name := range config.EnabledCallbacks {
|
|
32
|
+ // we store "none" as "*" internally
|
|
33
|
+ if name == "none" {
|
|
34
|
+ name = "*"
|
|
35
|
+ }
|
|
36
|
+ accountReg.EnabledCallbackTypes = append(accountReg.EnabledCallbackTypes, name)
|
|
37
|
+ }
|
32
|
38
|
}
|
33
|
39
|
return accountReg
|
34
|
40
|
}
|
|
@@ -73,6 +79,58 @@ func regHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
73
|
79
|
}
|
74
|
80
|
|
75
|
81
|
// account didn't already exist, continue with account creation and dispatching verification (if required)
|
|
82
|
+ callback := strings.ToLower(msg.Params[2])
|
|
83
|
+ var callbackNamespace, callbackValue string
|
|
84
|
+
|
|
85
|
+ if callback == "*" {
|
|
86
|
+ callbackNamespace = "*"
|
|
87
|
+ } else if strings.Contains(callback, ":") {
|
|
88
|
+ callbackValues := strings.SplitN(callback, ":", 2)
|
|
89
|
+ callbackNamespace, callbackValue = callbackValues[0], callbackValues[1]
|
|
90
|
+ } else {
|
|
91
|
+ callbackNamespace = server.accountRegistration.EnabledCallbackTypes[0]
|
|
92
|
+ callbackValue = callback
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ // ensure the callback namespace is valid
|
|
96
|
+ // need to search callback list, maybe look at using a map later?
|
|
97
|
+ var callbackValid bool
|
|
98
|
+ for _, name := range server.accountRegistration.EnabledCallbackTypes {
|
|
99
|
+ if callbackNamespace == name {
|
|
100
|
+ callbackValid = true
|
|
101
|
+ }
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ if !callbackValid {
|
|
105
|
+ client.Send(nil, server.nameString, ERR_REG_INVALID_CALLBACK, client.nickString, msg.Params[1], callbackNamespace, "Callback namespace is not supported")
|
|
106
|
+ //TODO(dan): close out failed account reg (remove values from db)
|
|
107
|
+ return false
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ // ensure the credential type is valid
|
|
111
|
+ var credentialType, credentialValue string
|
|
112
|
+
|
|
113
|
+ if len(msg.Params) > 4 {
|
|
114
|
+ credentialType = strings.ToLower(msg.Params[3])
|
|
115
|
+ credentialValue = msg.Params[4]
|
|
116
|
+ } else if len(msg.Params) == 4 {
|
|
117
|
+ credentialType = "passphrase" // default from the spec
|
|
118
|
+ credentialValue = msg.Params[3]
|
|
119
|
+ } else {
|
|
120
|
+ client.Send(nil, server.nameString, ERR_NEEDMOREPARAMS, client.nickString, msg.Command, "Not enough parameters")
|
|
121
|
+ //TODO(dan): close out failed account reg (remove values from db)
|
|
122
|
+ return false
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ // dispatch callback
|
|
126
|
+ if callbackNamespace != "*" {
|
|
127
|
+ client.Notice("Account creation was successful!")
|
|
128
|
+ //TODO(dan): close out failed account reg (remove values from db)
|
|
129
|
+ return false
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ client.Notice(fmt.Sprintf("We should dispatch an actual callback here to %s:%s", callbackNamespace, callbackValue))
|
|
133
|
+ client.Notice(fmt.Sprintf("Primary account credential is with %s:%s", credentialType, credentialValue))
|
76
|
134
|
|
77
|
135
|
} else if subcommand == "verify" {
|
78
|
136
|
client.Notice("Parsing VERIFY")
|