Browse Source

registration: Hook up reg to actual accounts

tags/v0.1.0
Daniel Oaks 7 years ago
parent
commit
e3fbdebc48
4 changed files with 29 additions and 4 deletions
  1. 1
    1
      irc/accounts.go
  2. 9
    0
      irc/numerics.go
  3. 17
    1
      irc/registration.go
  4. 2
    2
      irc/server.go

+ 1
- 1
irc/accounts.go View File

@@ -18,5 +18,5 @@ type ClientAccount struct {
18 18
 	// RegisteredAt represents the time that the account was registered.
19 19
 	RegisteredAt time.Time
20 20
 	// Clients that are currently logged into this account (useful for notifications).
21
-	Clients []Client
21
+	Clients []*Client
22 22
 }

+ 9
- 0
irc/numerics.go View File

@@ -149,6 +149,15 @@ const (
149 149
 	ERR_NOOPERHOST                  = "491"
150 150
 	ERR_UMODEUNKNOWNFLAG            = "501"
151 151
 	ERR_USERSDONTMATCH              = "502"
152
+	RPL_LOGGEDIN                    = "900"
153
+	RPL_LOGGEDOUT                   = "901"
154
+	ERR_NICKLOCKED                  = "902"
155
+	RPL_SASLSUCCESS                 = "903"
156
+	ERR_SASLFAIL                    = "904"
157
+	ERR_SASLTOOLONG                 = "905"
158
+	ERR_SASLABORTED                 = "906"
159
+	ERR_SASLALREADY                 = "907"
160
+	RPL_SASLMECHS                   = "908"
152 161
 	RPL_REGISTRATION_SUCCESS        = "920"
153 162
 	ERR_ACCOUNT_ALREADY_EXISTS      = "921"
154 163
 	ERR_REG_UNSPECIFIED_ERROR       = "922"

+ 17
- 1
irc/registration.go View File

@@ -19,6 +19,7 @@ import (
19 19
 const (
20 20
 	keyAccountExists      = "account %s exists"
21 21
 	keyAccountVerified    = "account %s verified"
22
+	keyAccountName        = "account %s name" // stores the 'preferred name' of the account, casemapped appropriately
22 23
 	keyAccountRegTime     = "account %s registered.time"
23 24
 	keyAccountCredentials = "account %s credentials"
24 25
 )
@@ -94,6 +95,7 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
94 95
 
95 96
 	// get and sanitise account name
96 97
 	account := NewName(msg.Params[1])
98
+	//TODO(dan): probably don't need explicit check for "*" here... until we actually casemap properly as per rfc7700
97 99
 	if !account.IsNickname() || msg.Params[1] == "*" {
98 100
 		client.Send(nil, server.nameString, ERR_REG_UNSPECIFIED_ERROR, client.nickString, msg.Params[1], "Account name is not valid")
99 101
 		return false
@@ -115,6 +117,7 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
115 117
 		registeredTimeKey := fmt.Sprintf(keyAccountRegTime, accountString)
116 118
 
117 119
 		tx.Set(accountKey, "1", nil)
120
+		tx.Set(fmt.Sprintf(keyAccountName, accountString), strings.TrimSpace(msg.Params[1]), nil)
118 121
 		tx.Set(registeredTimeKey, strconv.FormatInt(time.Now().Unix(), 10), nil)
119 122
 		return nil
120 123
 	})
@@ -230,6 +233,20 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
230 233
 	if callbackNamespace == "*" {
231 234
 		err = server.store.Update(func(tx *buntdb.Tx) error {
232 235
 			tx.Set(keyAccountVerified, "1", nil)
236
+
237
+			// load acct info inside store tx
238
+			account := ClientAccount{
239
+				Name:         strings.TrimSpace(msg.Params[1]),
240
+				RegisteredAt: time.Now(),
241
+				Clients:      []*Client{client},
242
+			}
243
+			//TODO(dan): Consider creating ircd-wide account adding/removing/affecting lock for protecting access to these sorts of variables
244
+			server.accounts[accountString] = &account
245
+			client.account = &account
246
+
247
+			client.Send(nil, server.nameString, RPL_REGISTRATION_SUCCESS, client.nickString, accountString, "Account created")
248
+			client.Send(nil, server.nameString, RPL_LOGGEDIN, client.nickString, client.nickMaskString, accountString, fmt.Sprintf("You are now logged in as %s", accountString))
249
+			client.Send(nil, server.nameString, RPL_SASLSUCCESS, client.nickString, "Authentication successful")
233 250
 			return nil
234 251
 		})
235 252
 		if err != nil {
@@ -239,7 +256,6 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
239 256
 			return false
240 257
 		}
241 258
 
242
-		client.Notice("Account creation was successful!")
243 259
 		return false
244 260
 	}
245 261
 

+ 2
- 2
irc/server.go View File

@@ -27,7 +27,7 @@ import (
27 27
 )
28 28
 
29 29
 type Server struct {
30
-	accounts            map[string]ClientAccount
30
+	accounts            map[string]*ClientAccount
31 31
 	channels            ChannelNameMap
32 32
 	clients             *ClientLookupSet
33 33
 	commands            chan Command
@@ -67,7 +67,7 @@ type clientConn struct {
67 67
 
68 68
 func NewServer(config *Config) *Server {
69 69
 	server := &Server{
70
-		accounts:         make(map[string]ClientAccount),
70
+		accounts:         make(map[string]*ClientAccount),
71 71
 		channels:         make(ChannelNameMap),
72 72
 		clients:          NewClientLookupSet(),
73 73
 		commands:         make(chan Command),

Loading…
Cancel
Save