1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-mock.git synced 2024-10-18 05:24:30 +00:00
cchat-mock/internal/service/authenticator.go

72 lines
1.6 KiB
Go
Raw Permalink Normal View History

2020-10-04 20:47:41 +00:00
package service
import (
"github.com/diamondburned/cchat"
"github.com/diamondburned/cchat-mock/internal/internet"
"github.com/diamondburned/cchat-mock/internal/session"
2020-10-27 20:42:48 +00:00
"github.com/diamondburned/cchat/text"
2020-10-04 20:47:41 +00:00
"github.com/pkg/errors"
)
type Authenticator struct{}
var _ cchat.Authenticator = (*Authenticator)(nil)
2020-10-27 20:42:48 +00:00
func (Authenticator) Name() text.Rich {
return text.Plain("Slow Authentication")
}
func (Authenticator) Description() text.Rich {
return text.Plain("")
}
2020-10-04 20:47:41 +00:00
func (Authenticator) AuthenticateForm() []cchat.AuthenticateEntry {
return []cchat.AuthenticateEntry{
{
Name: "Username",
},
{
Name: "Password (ignored)",
Secret: true,
},
{
Name: "Paragraph (ignored)",
Multiline: true,
},
}
}
2020-10-27 20:42:48 +00:00
func (Authenticator) Authenticate(form []string) (cchat.Session, cchat.AuthenticateError) {
2020-10-04 20:47:41 +00:00
// SLOW IO TIME.
2020-10-27 20:42:48 +00:00
err := internet.SimulateAustralian()
if err == nil {
return session.New(form[0], ""), nil
2020-10-04 20:47:41 +00:00
}
2020-10-27 20:42:48 +00:00
return nil, cchat.WrapAuthenticateError(errors.Wrap(err, "Authentication failed"))
2020-10-04 20:47:41 +00:00
}
2020-10-27 04:55:49 +00:00
type FastAuthenticator struct{}
var _ cchat.Authenticator = (*FastAuthenticator)(nil)
2020-10-27 20:42:48 +00:00
func (FastAuthenticator) Name() text.Rich {
return text.Plain("Fast Authenticator")
}
func (FastAuthenticator) Description() text.Rich {
return text.Plain("Internet fails and slow-downs disabled.")
}
2020-10-27 04:55:49 +00:00
func (FastAuthenticator) AuthenticateForm() []cchat.AuthenticateEntry {
return []cchat.AuthenticateEntry{
{
Name: "Username (fast)",
},
}
}
2020-10-27 20:42:48 +00:00
func (FastAuthenticator) Authenticate(form []string) (cchat.Session, cchat.AuthenticateError) {
2020-10-27 04:55:49 +00:00
return session.New(form[0], ""), nil
}