Browse Source

Edit locked status on user page

locked
meskio 3 years ago
parent
commit
50db31cf91
Signed by: meskio
GPG Key ID: 52B8F5AC97A2DA86
  1. 2
      ldap/locked.go
  2. 27
      server/admin.go
  3. 1
      server/server.go
  4. 30
      tmpl/user.html

2
ldap/locked.go

@ -18,6 +18,8 @@ func LockedFromString(s string) Locked {
switch strings.ToLower(s) {
case "":
return Unlocked
case "unlocked":
return Unlocked
case "blocked":
return Blocked
case "deleted":

27
server/admin.go

@ -124,6 +124,33 @@ func (s *server) roleHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/users/"+userName, http.StatusFound)
}
func (s *server) lockHandler(w http.ResponseWriter, r *http.Request) {
response := s.newResponse("", w, r)
if !response.IsAdmin {
log.Println("Non admin attemp to change user locked")
s.forbiddenHandler(w, r)
return
}
vars := mux.Vars(r)
userName := vars["name"]
lockedStr := r.FormValue("locked")
locked := ldap.LockedFromString(lockedStr)
if locked == ldap.Unknown {
log.Println("Not valid locked status '", lockedStr, "' for ", userName)
s.errorHandler(w, r)
return
}
err := s.ldap.ChangeLocked(userName, locked)
if err != nil {
log.Println("An error ocurred changing locked of '", userName, "' to", lockedStr, ": ", err)
s.errorHandler(w, r)
return
}
http.Redirect(w, r, "/users/"+userName, http.StatusFound)
}
func (s *server) passwdadmHandler(w http.ResponseWriter, r *http.Request) {
response := s.newResponse("", w, r)
if !response.IsAdmin {

1
server/server.go

@ -42,6 +42,7 @@ func Serve(addr string, l *ldap.Ldap, m *mail.Mail, ldb *db.DB) error {
r.HandleFunc("/users/{name}/role/", s.roleHandler).Methods("POST")
r.HandleFunc("/users/{name}/password/", s.passwdadmHandler).Methods("POST")
r.HandleFunc("/users/{name}/shell/", s.shellHandler).Methods("POST")
r.HandleFunc("/users/{name}/lock/", s.lockHandler).Methods("POST")
r.HandleFunc("/unlock/", s.unlockHandler)
r.HandleFunc("/invites/", s.listInvitesHandler)
r.HandleFunc("/invites/{invite}/del/", s.deleteInviteHandler)

30
tmpl/user.html

@ -55,6 +55,36 @@
</form>
</div>
<br />
<div class="row justify-content-center">
<form action="/users/{{.User.Name}}/lock/" method="post">
<div class="row">
<div class="col-md-5">
<label>Bloquea la cuenta:</label>
</div>
<div class="col-md-5">
<div class="form-check from-check-inline">
<input class="form-check-input" type="radio" name="locked" id="unlocked" value="unlocked"
{{if eq (printf "%v" .User.Locked) ""}}checked{{end}}>
<label class="form-check-label" for="unlocked">activa</label>
</div>
<div class="form-check from-check-inline">
<input class="form-check-input" type="radio" name="locked" id="blocked" value="blocked"
{{if eq (printf "%v" .User.Locked) "blocked"}}checked{{end}}>
<label class="form-check-label" for="bocked">bloqueada</label>
</div>
<div class="form-check from-check-inline">
<input class="form-check-input" type="radio" name="locked" id="deleted" value="deleted"
{{if eq (printf "%v" .User.Locked) "deleted"}}checked{{end}}>
<label class="form-check-label" for="deleted">eliminada</label>
</div>
</div>
<div class="col-sm-2">
<button type="submit" class="btn btn-primary">Enviar</button>
</div>
</div>
</form>
</div>
<br />
<div class="row justify-content-center">
<form action="/users/{{.User.Name}}/password/" method="post">
<div class="row">

Loading…
Cancel
Save