Browse Source

accounts: Fix broken numeric, write more framework for reg

tags/v0.1.0
Daniel Oaks 7 years ago
parent
commit
e7fced804e
3 changed files with 64 additions and 6 deletions
  1. 1
    1
      irc/numerics.go
  2. 61
    3
      irc/registration.go
  3. 2
    2
      irc/server.go

+ 1
- 1
irc/numerics.go View File

@@ -155,6 +155,6 @@ const (
155 155
 	ERR_ACCOUNT_ALREADY_VERIFIED    = "924"
156 156
 	ERR_ACCOUNT_INVALID_VERIFY_CODE = "925"
157 157
 	RPL_REG_VERIFICATION_REQUIRED   = "927"
158
+	ERR_REG_INVALID_CRED_TYPE       = "928"
158 159
 	ERR_REG_INVALID_CALLBACK        = "929"
159
-	ERR_REG_INVALID_CRED_TYPE       = "982"
160 160
 )

+ 61
- 3
irc/registration.go View File

@@ -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")

+ 2
- 2
irc/server.go View File

@@ -159,8 +159,8 @@ func NewServer(config *Config) *Server {
159 159
 	if server.accountRegistration.Enabled {
160 160
 		// 'none' isn't shown in the REGCALLBACKS vars
161 161
 		var enabledCallbackTypes []string
162
-		for _, name := range server.accountRegistration.EnabledRegistrationCallbackTypes {
163
-			if name != "none" {
162
+		for _, name := range server.accountRegistration.EnabledCallbackTypes {
163
+			if name != "*" {
164 164
 				enabledCallbackTypes = append(enabledCallbackTypes, name)
165 165
 			}
166 166
 		}

Loading…
Cancel
Save