Made auth use full ID instead, to support different auth methods in the future.
This commit is contained in:
@@ -52,6 +52,7 @@ func (wikiAuth *WikiAthenticator) Find(username string) *auth.User {
|
||||
// Login login
|
||||
func (wikiAuth *WikiAthenticator) Login(username, password string) (*auth.User, error) {
|
||||
db := server.Main.DB
|
||||
fullID := wikiAuth.ID() + ":" + username
|
||||
|
||||
// Connect to the wiki
|
||||
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
|
||||
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 {
|
||||
return nil, fmt.Errorf("Login failed %v", err)
|
||||
}
|
||||
|
||||
// If none was found, just create a new record with the role of member
|
||||
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 {
|
||||
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
|
||||
@@ -90,7 +91,7 @@ func (wikiAuth *WikiAthenticator) Login(username, password string) (*auth.User,
|
||||
userid = strings.Split(userid, "@")[0]
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
// Base is the basic information used to render the page
|
||||
type Base struct {
|
||||
User struct {
|
||||
ID string
|
||||
Name string
|
||||
Role string
|
||||
LoggedIn bool
|
||||
@@ -23,6 +24,7 @@ func (base *Base) setupBase(user *auth.User, viewTitle string) {
|
||||
if user != nil {
|
||||
log.Printf("%+v", user)
|
||||
|
||||
base.User.ID = user.FullID()
|
||||
base.User.Name = user.ID
|
||||
base.User.Role = user.Data["role"]
|
||||
base.User.LoggedIn = true
|
||||
|
||||
Reference in New Issue
Block a user