Password change.

merge-requests/1/head
meskio 5 years ago
parent a9573a8c0f
commit ea7a9a096d
  1. 94
      img/sd_nb.svg
  2. 7
      ldap/user.go
  3. 39
      server/server.go
  4. 3
      tmpl/footer.html
  5. 11
      tmpl/header.html
  6. 22
      tmpl/index.html
  7. 17
      tmpl/login.html
  8. 19
      tmpl/navbar.html
  9. 34
      tmpl/password.html

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="70"
height="69.999992"
id="svg5147"
version="1.1"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
sodipodi:docname="sd_nb.svg">
<defs
id="defs5149">
<filter
inkscape:collect="always"
id="filter3833">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="0.19200001"
id="feGaussianBlur3835" />
</filter>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="6.7276164"
inkscape:cx="1.1104519"
inkscape:cy="18.998912"
inkscape:document-units="px"
inkscape:current-layer="g4998"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1916"
inkscape:window-height="1060"
inkscape:window-x="1368"
inkscape:window-y="18"
inkscape:window-maximized="0" />
<metadata
id="metadata5152">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Capa 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-446.02346,-444.33872)">
<g
id="g4998"
transform="matrix(0.54687496,0,0,0.54687496,-13.896714,491.89408)"
style="fill:#000000;filter:url(#filter3833)">
<path
sodipodi:nodetypes="cccccscccccccccccscccccccccccccccsccsscccccccccccccccccsc"
inkscape:connector-curvature="0"
id="rect4782-5-0-1"
d="m 877.08376,-57.957241 c -0.51757,0.008 -1.0338,0.008 -1.53125,0.0625 -3.55246,0.38805 -5.96563,1.15151 -9.25,2.1875 -3.21199,1.30091 -4.39867,2.21921 -6.82408,3.82058 -2.10562,1.81182 -5.25321,4.50213 -7.42032,8.92942 -1.4133,2.62273 -1.59366,3.53782 -1.84935,6.59375 -0.19709,2.35554 0.43202,5.35376 0.8125,7.625 0.42008,1.95613 0.72335,3.30319 1.84375,5.53125 1.40352,2.18475 2.87342,3.38668 4.5,4.9375 1.60591,1.30197 2.68667,2.13853 4.25,2.75 2.30247,1.03417 3.91549,1.62015 5.71875,1.90625 1.76609,0.28026 4.41892,-0.0561 6.34375,0.0312 3.65531,0.005 6.7363,0.18624 8.59375,0.15625 2.13277,0.28828 3.41024,0.466 4.625,0.78125 1.81072,0.37242 2.8111,0.0409 4.375,1.21875 0.25727,0.17752 0.51136,0.30515 0.75,0.4375 0.0309,0.0172 0.0632,0.0456 0.0937,0.0625 0.73876,0.54581 1.39467,1.1805205 1.90625,2.0625005 0.20042,0.34553 0.26775,1.06357 0.41856,1.49432 0.71613,2.49287 -0.90214,3.48793 -2.44981,5.03693 -0.80597,0.66004 -2.57294,2.20704 -7,3.375 -2.38964,0.26082 -5.90949,1.13222 -7.57429,0.875 -3.49988,-0.39288 -5.72629,-0.53711 -8.46875,-3.09375 -0.9416,-0.95654 -2.15054,-3.0638 -2.96875,-4.1875 l -13.25,7.25 c 0.041,-0.0283 3.63656,4.94047 4.28125,5.59375 1.46634,1.67485 3.52592,3.5473995 6.25,4.9062495 2.57105,1.24346 5.41258,1.80518 8.75,2.59375 2.13251,0.45628 5.86775,0.92841 9.85554,0.4375 6.79777,-1.39281 8.36933,-2.19007 11.875,-3.75 3.62168,-2.1348095 3.42804,-2.0360295 7.375,-4.8124995 4.04126,-3.77769 5.15721,-4.90138 7.5,-10.40625 0.86619,-3.12499 0.87218,-5.46377 -0.21875,-10.3750005 -0.55183,-1.37604 -0.94534,-2.66157 -1.46875,-3.6875 -0.52341,-1.02593 -1.18194,-2.67554 -1.71875,-3.46875 -0.0202,-0.0299 -0.0418,-0.0638 -0.0625,-0.0937 -0.19981,-0.40216 -0.41296,-0.76411 -0.59375,-1.03125 -0.89851,-1.32769 -2.25896,-2.7893 -2.9375,-3.40625 -0.67854,-0.61696 -1.4504,-1.19191 -2.3125,-1.75 -3.50087,-2.49295 -6.28099,-2.61449 -8,-2.90625 -3.72003,0.0192 -4.17768,0.007 -8.4375,-0.0937 -2.18407,-0.26265 -6.07104,0.29964 -7.90625,0.0312 -1.76096,-0.29417 -3.95748,-0.39956 -5.21875,-0.90625 -1.94095,-0.95067 -2.1382,-1.41498 -2.8131,-2.1875 -1.02106,-1.22166 -1.35283,-2.94594 -1.0271,-4.75385 -0.0902,-0.89895 0.61055,-2.74962 2.7777,-3.7149 1.86784,-1.10352 1.46655,-0.73484 3.53304,-1.62679 1.95887,-0.56747 4.53805,-0.88872 5.65446,-1.0018 2.82912,10e-4 4.33852,0.79842 6.53125,1.62859 2.80595,1.33097 5.06084,2.66264 6.59375,4.78125 l 11.41051,-8.86342 c -0.81764,-1.88094 -1.43617,-1.46938 -3.5058,-3.52545 -2.3988,-1.83718 -3.02731,-2.44147 -5.44754,-3.90625 -2.35586,-1.09087 -3.05053,-1.22425 -5.48842,-2.17858 -1.8305,-0.75069 -3.66697,-1.0535 -6.4375,-1.2763 -1.30733,0.009 -2.88479,-0.11819 -4.4375,-0.0937 z"
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.30000001;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<path
id="path4059-6-8-3-7-5"
d="m 930.49613,-64.868031 c -18.50386,-1.15955 -32.93912,12.43649 -34.8311,30.47558 l 10.52897,-15.83708 c 3.44663,-4.19361 6.72388,-6.7576 9.41149,-8.08062 4.54837,-2.74579 7.38398,-3.43487 11.59363,-3.45532 4.20965,-0.12978 7.47035,0.76334 11.38969,1.99283 3.91934,1.22962 7.95897,3.37555 12.00827,6.6948 3.95932,3.24562 6.89521,6.77569 8.97274,10.38974 2.05498,3.59571 3.25846,7.20641 3.65669,10.85018 0.39818,3.64385 0.0537,7.28453 -1.13897,10.85018 -1.17505,3.54416 -1.7956,6.30971 -4.2155,10.01094 l -6.99457,10.7949105 c 9.46988,-5.83491 15.32008,-16.5054605 15.46622,-28.7786405 0.25885,-21.73776 -16.0283,-34.66553 -35.84756,-35.9075 z m -2.52281,17.90406 c -0.5953,-0.008 -2.16196,-0.0764 -2.7421,-0.0656 -1.74101,0.14718 -2.22145,-0.007 -4.82297,0.83352 -1.83554,0.88288 -2.61302,1.4597 -4.42838,2.89054 -1.98132,2.11713 -3.72345,4.95183 -5.41774,7.45167 l 34.89457,21.39718 2.7638,-4.16298 c 1.30725,-2.09973 1.41417,-2.80398 2.04273,-4.9932 0.1605,-2.93924 -0.008,-3.55258 -0.46186,-5.48592 -0.68185,-2.22269 -1.08651,-2.94713 -2.26179,-4.9161 -1.48144,-2.3682 -3.5348,-4.09417 -6.23436,-6.30712 -2.76702,-2.26816 -5.37789,-3.9352 -8.09546,-5.15313 -2.27694,-1.00227 -2.94562,-1.06501 -5.23644,-1.48886 z m -30.49229,18.72706 c -1.01153,-0.29395 -2.01373,-0.72069 -3.02087,-0.78232 0,19.8192805 16.21672,35.9662105 36.03597,35.9662105 4.29837,0 11.22933,-0.56671 16.88622,-4.58057 z"
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.91900003;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
inkscape:connector-curvature="0"
sodipodi:nodetypes="scccccccccccsscccccccccccccccscc">
<title
id="title4130-5-4">O-logo</title>
</path>
<path
inkscape:connector-curvature="0"
id="path4912-6-2-9"
d="m 905.02694,-86.958371 c -35.3506,0 -64.02999,28.61943 -64.02999,63.97002 0,35.3506 28.67939,64.02998 64.02999,64.02998 35.35059,0 63.97002,-28.67938 63.97002,-64.02998 0,-35.35059 -28.61943,-63.97002 -63.97002,-63.97002 z m 0,4.37658 c 32.93268,0 59.59344,26.66076 59.59344,59.59344 0,32.9327005 -26.66076,59.65341 -59.59344,59.65341 -32.9327,0 -59.65341,-26.7207095 -59.65341,-59.65341 0,-32.93268 26.72071,-59.59344 59.65341,-59.59344 z"
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.91900003;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 7.6 KiB

@ -17,6 +17,13 @@ func (s *Session) LogIn(user string, pass string) error {
return s.conn.Bind(userdn, pass)
}
// ChangePass changes logged in user's password
func (s *Session) ChangePass(oldpass string, newpass string) error {
passwordModifyRequest := ldap.NewPasswordModifyRequest("", oldpass, newpass)
_, err := s.conn.PasswordModify(passwordModifyRequest)
return err
}
func (s *Session) searchUser(user string) (entry *ldap.Entry, err error) {
searchRequest := ldap.NewSearchRequest(
"ou=people,"+s.dc,

@ -8,7 +8,14 @@ import (
"github.com/gorilla/mux"
)
var tmpl = template.Must(template.ParseFiles("tmpl/login.html", "tmpl/index.html"))
var tmpl = template.Must(template.ParseFiles(
"tmpl/header.html",
"tmpl/footer.html",
"tmpl/navbar.html",
"tmpl/login.html",
"tmpl/index.html",
"tmpl/password.html",
))
type server struct {
ldap *ldap.Session
@ -22,6 +29,8 @@ func Serve(addr string, session *ldap.Session) error {
r.HandleFunc("/", s.homeHandler)
r.HandleFunc("/login/", s.loginHandler)
r.HandleFunc("/logout/", s.logoutHandler).Methods("POST")
r.HandleFunc("/password/", s.passwordHandler)
r.HandleFunc("/bundle.js", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "dist/bundle.js") })
r.HandleFunc("/style.css", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "dist/style.css") })
r.Handle("/img/{img}", http.StripPrefix("/img/", http.FileServer(http.Dir("img"))))
@ -56,3 +65,31 @@ func (s *server) logoutHandler(w http.ResponseWriter, r *http.Request) {
setUser("", w, r)
http.Redirect(w, r, "/", http.StatusFound)
}
func (s *server) passwordHandler(w http.ResponseWriter, r *http.Request) {
user := getUser(w, r)
if user == "" {
http.Redirect(w, r, "/", http.StatusFound)
return
}
if r.Method != "POST" {
tmpl.ExecuteTemplate(w, "password.html", "")
return
}
oldpass := r.FormValue("oldpass")
pass := r.FormValue("password")
pass2 := r.FormValue("password2")
if pass != pass2 {
tmpl.ExecuteTemplate(w, "password.html", "WrongPass")
return
}
err := s.ldap.ChangePass(oldpass, pass)
if err != nil {
tmpl.ExecuteTemplate(w, "password.html", "WrongOldpass")
} else {
tmpl.ExecuteTemplate(w, "password.html", "PassChanged")
}
}

@ -0,0 +1,3 @@
<script src="/bundle.js"></script>
</body>
</html>

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/png" href="/img/favicon_sd.png"/>
<link rel="stylesheet" href="/style.css">
<title>lowry</title>
</head>
<body>

@ -1,25 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/png" href="/img/favicon_sd.png"/>
<link rel="stylesheet" href="/style.css">
{{template "header.html"}}
{{template "navbar.html" "index"}}
<title>SD lowry</title>
</head>
<body>
<div class="container">
<br />
<div class="row justify-content-center">
<h1 class="col-4">Hola {{.}}!!</h1>
</div>
<div class="row justify-content-center">
<form class="col-4" action="/logout/" method="post">
<button type="submit" class="btn btn-primary">Salir</button>
</form>
</div>
<script src="/bundle.js"></script>
</body>
</html>
{{template "footer.html"}}

@ -1,14 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/png" href="/img/favicon_sd.png"/>
<link rel="stylesheet" href="/style.css">
{{template "header.html"}}
<title>SD lowry</title>
</head>
<body>
<div class="container">
<br />
<div class="row justify-content-center">
@ -23,7 +14,7 @@
</div>
<div class="form-group">
<label for="password">Contraseña:</label>
<input type="password" class="form-control {{if .}}is-invalid{{end}}" id="password" name="password" aria-describe="passErr" placeholder="Contraseña">
<input type="password" class="form-control {{if .}}is-invalid{{end}}" id="password" name="password" placeholder="Contraseña">
<div class="invalid-feedback">Contraseña o nombre de usuaria incorrecto.</div>
</div>
<button type="submit" class="btn btn-primary">Entrar</button>
@ -31,6 +22,4 @@
</div>
</div>
<script src="/bundle.js"></script>
</body>
</html>
{{template "footer.html"}}

@ -0,0 +1,19 @@
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<a class="navbar-brand" href="/"><img src="/img/sd_nb.svg" width="30" height="30" /> lowry</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item {{if eq . "password"}}active{{end}}">
<a class="nav-link" href="/password/">Contraseña</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0" action="/logout/" method="post">
<button type="submit" class="btn btn-outline-success my-2 my-sm-0">Salir</button>
</form>
</div>
</nav>

@ -0,0 +1,34 @@
{{template "header.html"}}
{{template "navbar.html" "password"}}
<div class="container">
<br />
{{if eq . "PassChanged"}}
<h1 class="row justify-content-center">La contraseña ha sido actualizada</h1>
{{else}}
<h1 class="row justify-content-center">Cambia tu contraseña</h1>
{{end}}
<br />
<div class="row justify-content-center">
<form class="col-4" id="needs-validation" action="/password/" method="post" novalidate>
<div class="form-group">
<label for="oldpass">Antigua contraseña:</label>
<input type="password" class="form-control {{if eq . "WrongOldpass"}}is-invalid{{end}}" id="oldpass" name="oldpass" placeholder="Contraseña">
<div class="invalid-feedback">Contraseña incorrecta.</div>
</div>
<div class="form-group">
<label for="password">Nueva contraseña:</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Contraseña">
</div>
<div class="form-group">
<label for="password2">Repite la contraseña:</label>
<input type="password" class="form-control {{if eq . "WrongPass"}}is-invalid{{end}}" id="password2" name="password2" placeholder="Contraseña">
<div class="invalid-feedback">No son la misma contraseña.</div>
</div>
<button type="submit" class="btn btn-primary">Entrar</button>
</form>
</div>
</div>
{{template "footer.html"}}
Loading…
Cancel
Save