mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
accounts: Very roughly introduce account type
This commit is contained in:
parent
739f8d71d2
commit
5269dc8776
@ -5,8 +5,14 @@ package irc
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// Account represents a user account.
|
var (
|
||||||
type Account struct {
|
NoAccount = ClientAccount{
|
||||||
|
Name: "*", // * is used until actual account name is set
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ClientAccount represents a user account.
|
||||||
|
type ClientAccount struct {
|
||||||
// Name of the account.
|
// Name of the account.
|
||||||
Name string
|
Name string
|
||||||
// RegisteredAt represents the time that the account was registered.
|
// RegisteredAt represents the time that the account was registered.
|
||||||
|
@ -209,7 +209,7 @@ func (channel *Channel) Join(client *Client, key string) {
|
|||||||
|
|
||||||
for member := range channel.members {
|
for member := range channel.members {
|
||||||
if member.capabilities[ExtendedJoin] {
|
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 {
|
} else {
|
||||||
member.Send(nil, client.nickMaskString, "JOIN", channel.nameString)
|
member.Send(nil, client.nickMaskString, "JOIN", channel.nameString)
|
||||||
}
|
}
|
||||||
@ -224,7 +224,7 @@ func (channel *Channel) Join(client *Client, key string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if client.capabilities[ExtendedJoin] {
|
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 {
|
} else {
|
||||||
client.Send(nil, client.nickMaskString, "JOIN", channel.nameString)
|
client.Send(nil, client.nickMaskString, "JOIN", channel.nameString)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ type Client struct {
|
|||||||
nickMaskString string // cache for nickmask string since it's used with lots of replies
|
nickMaskString string // cache for nickmask string since it's used with lots of replies
|
||||||
quitTimer *time.Timer
|
quitTimer *time.Timer
|
||||||
realname string
|
realname string
|
||||||
accountName string
|
account *ClientAccount
|
||||||
registered bool
|
registered bool
|
||||||
server *Server
|
server *Server
|
||||||
socket *Socket
|
socket *Socket
|
||||||
@ -67,7 +67,7 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
|
|||||||
flags: make(map[UserMode]bool),
|
flags: make(map[UserMode]bool),
|
||||||
server: server,
|
server: server,
|
||||||
socket: &socket,
|
socket: &socket,
|
||||||
accountName: "*", // * is used until actual account name is set
|
account: &NoAccount,
|
||||||
nickString: "*", // * is used until actual nick is given
|
nickString: "*", // * is used until actual nick is given
|
||||||
}
|
}
|
||||||
if isTLS {
|
if isTLS {
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
keyAccountExists = "account %s exists"
|
keyAccountExists = "account %s exists"
|
||||||
|
keyAccountVerified = "account %s verified"
|
||||||
keyAccountRegTime = "account %s registered.time"
|
keyAccountRegTime = "account %s registered.time"
|
||||||
keyAccountCredentials = "account %s credentials"
|
keyAccountCredentials = "account %s credentials"
|
||||||
)
|
)
|
||||||
@ -221,11 +222,23 @@ func regCreateHandler(server *Server, client *Client, msg ircmsg.IrcMessage) boo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
client.Send(nil, server.nameString, ERR_UNKNOWNERROR, client.nickString, "REG", "CREATE", "Could not register")
|
client.Send(nil, server.nameString, ERR_UNKNOWNERROR, client.nickString, "REG", "CREATE", "Could not register")
|
||||||
log.Println("Could not save registration creds:", err.Error())
|
log.Println("Could not save registration creds:", err.Error())
|
||||||
|
removeFailedRegCreateData(server.store, accountString)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// automatically complete registration
|
// automatically complete registration
|
||||||
if callbackNamespace == "*" {
|
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!")
|
client.Notice("Account creation was successful!")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
accounts map[string]Account
|
accounts map[string]ClientAccount
|
||||||
channels ChannelNameMap
|
channels ChannelNameMap
|
||||||
clients *ClientLookupSet
|
clients *ClientLookupSet
|
||||||
commands chan Command
|
commands chan Command
|
||||||
@ -67,7 +67,7 @@ type clientConn struct {
|
|||||||
|
|
||||||
func NewServer(config *Config) *Server {
|
func NewServer(config *Config) *Server {
|
||||||
server := &Server{
|
server := &Server{
|
||||||
accounts: make(map[string]Account),
|
accounts: make(map[string]ClientAccount),
|
||||||
channels: make(ChannelNameMap),
|
channels: make(ChannelNameMap),
|
||||||
clients: NewClientLookupSet(),
|
clients: NewClientLookupSet(),
|
||||||
commands: make(chan Command),
|
commands: make(chan Command),
|
||||||
|
Loading…
Reference in New Issue
Block a user