Browse Source

Made auth use full ID instead, to support different auth methods in the future.

master
Gisle Aune 7 years ago
parent
commit
6a3e70b21b
  1. 9
      controllers/wikiauth.go
  2. 2
      viewmodel/base.go

9
controllers/wikiauth.go

@ -52,6 +52,7 @@ func (wikiAuth *WikiAthenticator) Find(username string) *auth.User {
// Login login // Login login
func (wikiAuth *WikiAthenticator) Login(username, password string) (*auth.User, error) { func (wikiAuth *WikiAthenticator) Login(username, password string) (*auth.User, error) {
db := server.Main.DB db := server.Main.DB
fullID := wikiAuth.ID() + ":" + username
// Connect to the wiki // Connect to the wiki
client, err := mediawiki.New(server.Main.Config.Wiki.URL, server.UserAgent) client, err := mediawiki.New(server.Main.Config.Wiki.URL, server.UserAgent)
@ -66,19 +67,19 @@ func (wikiAuth *WikiAthenticator) Login(username, password string) (*auth.User,
} }
// Look up the user // Look up the user
rows, err := db.Query("SELECT id,role FROM `user` WHERE id=?", username)
rows, err := db.Query("SELECT id,role FROM `user` WHERE id=?", fullID)
if err != nil { if err != nil {
return nil, fmt.Errorf("Login failed %v", err) return nil, fmt.Errorf("Login failed %v", err)
} }
// If none was found, just create a new record with the role of member // If none was found, just create a new record with the role of member
if !rows.Next() { if !rows.Next() {
_, err = db.Exec("INSERT INTO `user` (id, role) VALUES (?, 'member')", username)
_, err = db.Exec("INSERT INTO `user` (id, role) VALUES (?, 'member')", fullID)
if err != nil { if err != nil {
return nil, fmt.Errorf("Login failed %v", err) return nil, fmt.Errorf("Login failed %v", err)
} }
return auth.NewUser(wikiAuth, username, "member", nil), nil
return auth.NewUser(wikiAuth, fullID, "member", nil), nil
} }
// If the user was found, read it in // If the user was found, read it in
@ -90,7 +91,7 @@ func (wikiAuth *WikiAthenticator) Login(username, password string) (*auth.User,
userid = strings.Split(userid, "@")[0] userid = strings.Split(userid, "@")[0]
// Make the user // Make the user
return auth.NewUser(wikiAuth, userid, "member", nil), nil
return auth.NewUser(wikiAuth, strings.Split(userid, ":")[1], "member", nil), nil
} }
// Register just tells the user that they can't. // Register just tells the user that they can't.

2
viewmodel/base.go

@ -11,6 +11,7 @@ import (
// Base is the basic information used to render the page // Base is the basic information used to render the page
type Base struct { type Base struct {
User struct { User struct {
ID string
Name string Name string
Role string Role string
LoggedIn bool LoggedIn bool
@ -23,6 +24,7 @@ func (base *Base) setupBase(user *auth.User, viewTitle string) {
if user != nil { if user != nil {
log.Printf("%+v", user) log.Printf("%+v", user)
base.User.ID = user.FullID()
base.User.Name = user.ID base.User.Name = user.ID
base.User.Role = user.Data["role"] base.User.Role = user.Data["role"]
base.User.LoggedIn = true base.User.LoggedIn = true

Loading…
Cancel
Save