change password for admin user when in LDAP mode

This commit is contained in:
xiahaoshawn 2016-05-09 20:57:41 +08:00
parent ccaad63730
commit cb9b8a7f55
3 changed files with 18 additions and 2 deletions

View File

@ -187,7 +187,9 @@ func (ua *UserAPI) Delete() {
// ChangePassword handles PUT to /api/users/{}/password // ChangePassword handles PUT to /api/users/{}/password
func (ua *UserAPI) ChangePassword() { func (ua *UserAPI) ChangePassword() {
if !(ua.AuthMode == "db_auth") { ldapAdminUser := (ua.AuthMode == "ldap_auth" && ua.userID == 1 && ua.userID == ua.currentUserID)
if !(ua.AuthMode == "db_auth" || ldapAdminUser) {
ua.CustomAbort(http.StatusForbidden, "") ua.CustomAbort(http.StatusForbidden, "")
} }

View File

@ -41,6 +41,7 @@ type BaseController struct {
beego.Controller beego.Controller
i18n.Locale i18n.Locale
SelfRegistration bool SelfRegistration bool
IsLdapAdminUser bool
IsAdmin bool IsAdmin bool
AuthMode string AuthMode string
} }
@ -116,16 +117,23 @@ func (b *BaseController) Prepare() {
b.Data["Username"] = b.GetSession("username") b.Data["Username"] = b.GetSession("username")
b.Data["UserId"] = sessionUserID.(int) b.Data["UserId"] = sessionUserID.(int)
if (sessionUserID == 1 && b.AuthMode == "ldap_auth") {
b.IsLdapAdminUser = true
}
var err error var err error
b.IsAdmin, err = dao.IsAdminRole(sessionUserID.(int)) b.IsAdmin, err = dao.IsAdminRole(sessionUserID.(int))
if err != nil { if err != nil {
log.Errorf("Error occurred in IsAdminRole:%v", err) log.Errorf("Error occurred in IsAdminRole:%v", err)
b.CustomAbort(http.StatusInternalServerError, "Internal error.") b.CustomAbort(http.StatusInternalServerError, "Internal error.")
} }
}else {
b.IsLdapAdminUser = false
} }
b.Data["IsAdmin"] = b.IsAdmin b.Data["IsAdmin"] = b.IsAdmin
b.Data["SelfRegistration"] = b.SelfRegistration b.Data["SelfRegistration"] = b.SelfRegistration
b.Data["IsLdapAdminUser"] = b.IsLdapAdminUser
} }

View File

@ -56,6 +56,12 @@
{{ if eq .AuthMode "db_auth" }} {{ if eq .AuthMode "db_auth" }}
<li><a id="aChangePassword" href="/changePassword" target="_blank"><span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;{{i18n .Lang "change_password"}}</a></li> <li><a id="aChangePassword" href="/changePassword" target="_blank"><span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;{{i18n .Lang "change_password"}}</a></li>
<li role="separator" class="divider"></li> <li role="separator" class="divider"></li>
{{ end }}
{{ if eq .AuthMode "ldap_auth" }}
{{ if eq .IsLdapAdminUser true }}
<li><a id="aChangePassword" href="/changePassword" target="_blank"><span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;{{i18n .Lang "change_password"}}</a></li>
<li role="separator" class="divider"></li>
{{ end }}
{{ end }} {{ end }}
{{ if eq .AuthMode "db_auth" }} {{ if eq .AuthMode "db_auth" }}
{{ if eq .IsAdmin true }} {{ if eq .IsAdmin true }}