You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
757 B
37 lines
757 B
package wikiauth
|
|
|
|
import (
|
|
"github.com/sadbox/mediawiki"
|
|
)
|
|
|
|
// WikiAuth is the structure responsible for wiki authentication. It's immuitable
|
|
// and thread safe. The only time it connects is to log in.
|
|
type WikiAuth struct {
|
|
url string
|
|
}
|
|
|
|
// New creates a new wiki authenticator instance.
|
|
func New(url string) *WikiAuth {
|
|
return &WikiAuth{url}
|
|
}
|
|
|
|
// Login connects to the wiki and logs in. It will not reuse clients between
|
|
// logins, so it's thus threadsafe.
|
|
func (wikiAuth *WikiAuth) Login(username, password string) error {
|
|
client, err := mediawiki.New(wikiAuth.url, "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
client.Username = username
|
|
client.Password = password
|
|
|
|
err = client.Login()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
client.Logout()
|
|
|
|
return nil
|
|
}
|