|
@@ -7,8 +7,10 @@ import (
|
|
|
"regexp"
|
|
|
"strconv"
|
|
|
|
|
|
+ uuid "github.com/google/uuid"
|
|
|
auth "imuslab.com/arozos/mod/auth"
|
|
|
"imuslab.com/arozos/mod/auth/ldap/ldapreader"
|
|
|
+ "imuslab.com/arozos/mod/auth/oauth2/syncdb"
|
|
|
reg "imuslab.com/arozos/mod/auth/register"
|
|
|
"imuslab.com/arozos/mod/common"
|
|
|
db "imuslab.com/arozos/mod/database"
|
|
@@ -24,6 +26,7 @@ type ldapHandler struct {
|
|
|
permissionHandler *permission.PermissionHandler
|
|
|
userHandler *user.UserHandler
|
|
|
iconSystem string
|
|
|
+ syncdb *syncdb.SyncDB
|
|
|
}
|
|
|
|
|
|
type Config struct {
|
|
@@ -70,6 +73,7 @@ func NewLdapHandler(authAgent *auth.AuthAgent, register *reg.RegisterHandler, co
|
|
|
permissionHandler: permissionHandler,
|
|
|
userHandler: userHandler,
|
|
|
iconSystem: iconSystem,
|
|
|
+ syncdb: syncdb.NewSyncDB(),
|
|
|
}
|
|
|
|
|
|
return &LDAPHandler
|
|
@@ -339,7 +343,6 @@ func (ldap *ldapHandler) HandleLogin(w http.ResponseWriter, r *http.Request) {
|
|
|
//Check the database and see if this user is in the database
|
|
|
passwordCorrect, err := ldap.ldapreader.Authenticate(username, password)
|
|
|
if err != nil {
|
|
|
- //Password not defined
|
|
|
ldap.ag.Logger.LogAuth(r, false)
|
|
|
common.SendErrorResponse(w, "Unable to connect to LDAP server")
|
|
|
log.Println("LDAP Authentication error, " + err.Error())
|
|
@@ -348,12 +351,22 @@ func (ldap *ldapHandler) HandleLogin(w http.ResponseWriter, r *http.Request) {
|
|
|
//The database contain this user information. Check its password if it is correct
|
|
|
if passwordCorrect {
|
|
|
//Password correct
|
|
|
- // Set user as authenticated
|
|
|
- ldap.ag.LoginUserByRequest(w, r, username, rememberme)
|
|
|
- //Print the login message to console
|
|
|
- log.Println(username + " logged in.")
|
|
|
- ldap.ag.Logger.LogAuth(r, true)
|
|
|
- common.SendOK(w)
|
|
|
+ if !ldap.ag.UserExists(username) {
|
|
|
+ authkey, err := uuid.NewUUID()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("UUID generation failed, " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ldap.syncdb.Store(authkey.String())
|
|
|
+ common.SendErrorResponse(w, "Redirection=system/auth/ldap/register.html?username="+username+"&displayname="+username+"&authkey="+authkey.String())
|
|
|
+ } else {
|
|
|
+ // Set user as authenticated
|
|
|
+ ldap.ag.LoginUserByRequest(w, r, username, rememberme)
|
|
|
+ //Print the login message to console
|
|
|
+ log.Println(username + " logged in.")
|
|
|
+ ldap.ag.Logger.LogAuth(r, true)
|
|
|
+ common.SendOK(w)
|
|
|
+ }
|
|
|
} else {
|
|
|
//Password incorrect
|
|
|
log.Println(username + " has entered an invalid username or password")
|