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

This commit is contained in:
2017-10-07 12:34:29 +02:00
parent def7189c35
commit 6a3e70b21b
2 changed files with 7 additions and 4 deletions
+5 -4
View File
@@ -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.