|
@ -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.
|
|
|