3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

accounts: Very roughly introduce account type

This commit is contained in:
Daniel Oaks 2016-09-05 22:35:13 +10:00
parent 739f8d71d2
commit 5269dc8776
5 changed files with 27 additions and 8 deletions

View File

@ -5,8 +5,14 @@ package irc
import "time"
// Account represents a user account.
type Account struct {
var (
NoAccount = ClientAccount{
Name: "*", // * is used until actual account name is set
}
)
// ClientAccount represents a user account.
type ClientAccount struct {
// Name of the account.
Name string
// RegisteredAt represents the time that the account was registered.

View File

@ -209,7 +209,7 @@ func (channel *Channel) Join(client *Client, key string) {
for member := range channel.members {
if member.capabilities[ExtendedJoin] {
member.Send(nil, client.nickMaskString, "JOIN", channel.nameString, client.accountName, client.realname)
member.Send(nil, client.nickMaskString, "JOIN", channel.nameString, client.account.Name, client.realname)
} else {
member.Send(nil, client.nickMaskString, "JOIN", channel.nameString)
}
@ -224,7 +224,7 @@ func (channel *Channel) Join(client *Client, key string) {
}
if client.capabilities[ExtendedJoin] {
client.Send(nil, client.nickMaskString, "JOIN", channel.nameString, client.accountName, client.realname)
client.Send(nil, client.nickMaskString, "JOIN", channel.nameString, client.account.Name, client.realname)
} else {
client.Send(nil, client.nickMaskString, "JOIN", channel.nameString)
}

View File

@ -45,7 +45,7 @@ type Client struct {
nickMaskString string // cache for nickmask string since it's used with lots of replies
quitTimer *time.Timer
realname string
accountName string
account *ClientAccount
registered bool
server *Server
socket *Socket
@ -67,7 +67,7 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
flags: make(map[UserMode]bool),
server: server,
socket: &socket,
accountName: "*", // * is used until actual account name is set
account: &NoAccount,
nickString: "*", // * is used until actual nick is given
}
if isTLS {

View File

@ -18,6 +18,7 @@ import (
const (
keyAccountExists = "account %s exists"
keyAccountVerified = "account %s verified"
keyAccountRegTime = "account %s registered.time"
keyAccountCredentials = "account %s credentials"
)
@ -221,11 +222,23 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
if err != nil {
client.Send(nil, server.nameString, ERR_UNKNOWNERROR, client.nickString, "REG", "CREATE", "Could not register")
log.Println("Could not save registration creds:", err.Error())
removeFailedRegCreateData(server.store, accountString)
return false
}
// automatically complete registration
if callbackNamespace == "*" {
err = server.store.Update(func(tx *buntdb.Tx) error {
tx.Set(keyAccountVerified, "1", nil)
return nil
})
if err != nil {
client.Send(nil, server.nameString, ERR_UNKNOWNERROR, client.nickString, "REG", "CREATE", "Could not register")
log.Println("Could not save verification confirmation (*):", err.Error())
removeFailedRegCreateData(server.store, accountString)
return false
}
client.Notice("Account creation was successful!")
return false
}

View File

@ -27,7 +27,7 @@ import (
)
type Server struct {
accounts map[string]Account
accounts map[string]ClientAccount
channels ChannelNameMap
clients *ClientLookupSet
commands chan Command
@ -67,7 +67,7 @@ type clientConn struct {
func NewServer(config *Config) *Server {
server := &Server{
accounts: make(map[string]Account),
accounts: make(map[string]ClientAccount),
channels: make(ChannelNameMap),
clients: NewClientLookupSet(),
commands: make(chan Command),