Browse Source

Añadir y elminar grupos

webdeploy
meskio 3 years ago
parent
commit
613c11d34a
Signed by: meskio
GPG Key ID: 52B8F5AC97A2DA86
  1. 36
      server/admin.go
  2. 2
      server/server.go
  3. 18
      tmpl/group.html
  4. 20
      tmpl/groups.html

36
server/admin.go

@ -61,6 +61,42 @@ func (s *server) userHandler(w http.ResponseWriter, r *http.Request) {
response.execute(data)
}
func (s *server) addGroupHandler(w http.ResponseWriter, r *http.Request) {
response := s.newResponse("", w, r)
if !response.IsAdmin {
log.Println("Non admin attemp to add group")
s.forbiddenHandler(w, r)
return
}
groupName := r.FormValue("group")
err := s.ldap.AddGroup(groupName)
if err != nil {
log.Println("An error ocurred adding group '", groupName, "': ", err)
s.errorHandler(w, r)
return
}
http.Redirect(w, r, "/groups/"+groupName, http.StatusFound)
}
func (s *server) delGroupHandler(w http.ResponseWriter, r *http.Request) {
response := s.newResponse("", w, r)
if !response.IsAdmin {
log.Println("Non admin attemp to del group")
s.forbiddenHandler(w, r)
return
}
groupName := r.FormValue("group")
err := s.ldap.DelGroup(groupName)
if err != nil {
log.Println("An error ocurred deleting group '", groupName, "': ", err)
s.errorHandler(w, r)
return
}
http.Redirect(w, r, "/groups/", http.StatusFound)
}
func (s *server) groupsHandler(w http.ResponseWriter, r *http.Request) {
response := s.newResponse("groups", w, r)
if !response.IsAdmin {

2
server/server.go

@ -52,6 +52,8 @@ func Serve(addr string, l *ldap.Ldap, m *mail.Mail, ldb *db.DB, g *gitea.Gitea)
r.HandleFunc("/adduser/", s.createInviteHandler)
r.HandleFunc("/adduser/{invite}", s.addUserHandler)
r.HandleFunc("/groups/", s.groupsHandler)
r.HandleFunc("/groups/add/", s.addGroupHandler).Methods("POST")
r.HandleFunc("/groups/del/", s.delGroupHandler).Methods("POST")
r.HandleFunc("/groups/{name}", s.groupHandler)
r.HandleFunc("/groups/{name}/add/", s.addUserGroupHandler).Methods("POST")
r.HandleFunc("/groups/{name}/del/", s.delUserGroupHandler).Methods("POST")

18
tmpl/group.html

@ -4,6 +4,7 @@
{{$isAdmin := .IsAdmin}}
{{with .Data}}
<br />
<div class="row justify-content-center">
<dl>
<dt>Nombre</dt><dd>{{.Name}}</dd>
@ -22,10 +23,10 @@
<form action="/groups/{{.Name}}/add/" method="post">
<div class="row">
<div class="col">
<label for="password">Añade usuaria:</label>
<label for="user">Añade cuenta:</label>
</div>
<div class="col">
<input type="text" class="form-control" id="user" name="user" placeholder="Usuaria">
<input type="text" class="form-control" id="user" name="user" placeholder="Cuenta">
</div>
<div class="col">
<button type="submit" class="btn btn-primary">Enviar</button>
@ -37,10 +38,10 @@
<form action="/groups/{{.Name}}/del/" method="post">
<div class="row">
<div class="col">
<label for="password">Elimina usuaria:</label>
<label for="user">Elimina cuenta:</label>
</div>
<div class="col">
<input type="text" class="form-control" id="user" name="user" placeholder="Usuaria">
<input type="text" class="form-control" id="user" name="user" placeholder="Cuenta">
</div>
<div class="col">
<button type="submit" class="btn btn-primary">Enviar</button>
@ -48,6 +49,15 @@
</div>
</form>
</div>
<br />
<div class="row justify-content-center">
<form action="/groups/del/" method="post" onsubmit="return confirm('Do you really want to submit the form?');">
<input type="hidden" class="form-control" id="group" name="group" value="{{.Name}}">
<div class="row">
<button type="submit" class="btn btn-lg btn-block btn-danger">Elimina el grupo {{.Name}}</button>
</div>
</form>
</div>
{{end}}
{{end}}

20
tmpl/groups.html

@ -2,6 +2,26 @@
{{template "header_close.html"}}
{{template "navbar.html" .}}
{{if .IsAdmin}}
<br />
<div class="row justify-content-end">
<form action="/groups/add/" method="post">
<div class="row">
<div class="col">
<label for="group">Añade grupo:</label>
</div>
<div class="col">
<input type="text" class="form-control" id="group" name="group" placeholder="Grupo">
</div>
<div class="col">
<button type="submit" class="btn btn-primary">Enviar</button>
</div>
</div>
</form>
</div>
{{end}}
<br />
<table class="table">
<thead>
<tr>

Loading…
Cancel
Save