|
@@ -7,7 +7,6 @@ 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"
|
|
@@ -312,6 +311,41 @@ func (ldap *ldapHandler) HandleLoginPage(w http.ResponseWriter, r *http.Request)
|
|
|
w.Write([]byte(parsedPage))
|
|
|
}
|
|
|
|
|
|
+func (ldap *ldapHandler) HandleNewPasswordPage(w http.ResponseWriter, r *http.Request) {
|
|
|
+ acc, err := common.Mv(r, "username", false)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ displayname, err := common.Mv(r, "displayname", false)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ key, err := common.Mv(r, "authkey", false)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ imgsrc := "./web/" + ldap.iconSystem
|
|
|
+ if !common.FileExists(imgsrc) {
|
|
|
+ imgsrc = "./web/img/public/auth_icon.png"
|
|
|
+ }
|
|
|
+ imageBase64, _ := common.LoadImageAsBase64(imgsrc)
|
|
|
+ template, err := common.Templateload("system/ldap/newPasswordTemplate.html", map[string]interface{}{
|
|
|
+ "vendor_logo": imageBase64,
|
|
|
+ "username": acc,
|
|
|
+ "display_name": displayname,
|
|
|
+ "key": key,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+ w.Header().Set("Content-Type", "text/html; charset=UTF-8")
|
|
|
+ w.Write([]byte(template))
|
|
|
+}
|
|
|
+
|
|
|
func (ldap *ldapHandler) HandleLogin(w http.ResponseWriter, r *http.Request) {
|
|
|
//Get username from request using POST mode
|
|
|
username, err := common.Mv(r, "username", true)
|
|
@@ -352,13 +386,8 @@ func (ldap *ldapHandler) HandleLogin(w http.ResponseWriter, r *http.Request) {
|
|
|
if passwordCorrect {
|
|
|
//Password correct
|
|
|
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())
|
|
|
+ authkey := ldap.syncdb.Store(username)
|
|
|
+ common.SendErrorResponse(w, "Redirection=system/auth/ldap/newPassword?username="+username+"&displayname="+username+"&authkey="+authkey.String())
|
|
|
} else {
|
|
|
// Set user as authenticated
|
|
|
ldap.ag.LoginUserByRequest(w, r, username, rememberme)
|
|
@@ -375,3 +404,27 @@ func (ldap *ldapHandler) HandleLogin(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func (ldap *ldapHandler) HandleSetPassword(w http.ResponseWriter, r *http.Request) {
|
|
|
+ username, err := common.Mv(r, "username", false)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ password, err := common.Mv(r, "password", false)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ authkey, err := common.Mv(r, "authkey", false)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //check if the input key matches the database's username
|
|
|
+ isValid := ldap.syncdb.Read(authkey) == username
|
|
|
+ if isValid {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|