Checks username and password against the wiki.
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

6 years ago
6 years ago
  1. package wikiauth
  2. import (
  3. "github.com/sadbox/mediawiki"
  4. )
  5. // WikiAuth is the structure responsible for wiki authentication. It's immuitable
  6. // and thread safe. The only time it connects is to log in.
  7. type WikiAuth struct {
  8. url string
  9. }
  10. // New creates a new wiki authenticator instance.
  11. func New(url string) *WikiAuth {
  12. return &WikiAuth{url}
  13. }
  14. // Login connects to the wiki and logs in. It will not reuse clients between
  15. // logins, so it's thus threadsafe.
  16. func (wikiAuth *WikiAuth) Login(username, password string) error {
  17. client, err := mediawiki.New(wikiAuth.url, "")
  18. if err != nil {
  19. return err
  20. }
  21. client.Username = username
  22. client.Password = password
  23. err = client.Login()
  24. if err != nil {
  25. return err
  26. }
  27. client.Logout()
  28. return nil
  29. }