Back the login to html if no javascript
This commit is contained in:
parent
7410ae7942
commit
7f1b99364c
5 changed files with 47 additions and 17 deletions
|
@ -44,6 +44,7 @@ var templates = template.Must(template.ParseFiles(TEMPLATE_PATH+"header.html",
|
||||||
TEMPLATE_PATH+"book.html",
|
TEMPLATE_PATH+"book.html",
|
||||||
TEMPLATE_PATH+"search.html",
|
TEMPLATE_PATH+"search.html",
|
||||||
TEMPLATE_PATH+"upload.html",
|
TEMPLATE_PATH+"upload.html",
|
||||||
|
TEMPLATE_PATH+"login.html",
|
||||||
TEMPLATE_PATH+"new.html",
|
TEMPLATE_PATH+"new.html",
|
||||||
TEMPLATE_PATH+"read.html",
|
TEMPLATE_PATH+"read.html",
|
||||||
TEMPLATE_PATH+"edit.html",
|
TEMPLATE_PATH+"edit.html",
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{{else}}
|
{{else}}
|
||||||
<li><a data-toggle="modal" href="#login"><i class="icon-user icon-white"></i></a></li>
|
<li><a data-toggle="modal" href="/login/#login"><i class="icon-user icon-white"></i></a></li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
</div><!--/.nav-collapse -->
|
</div><!--/.nav-collapse -->
|
||||||
|
|
16
templates/login.html
Normal file
16
templates/login.html
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{{template "header.html" .S}}
|
||||||
|
|
||||||
|
<h3>Log In</h3>
|
||||||
|
<form id="login" method="POST" action="/login/" enctype="application/x-www-form-urlencoded">
|
||||||
|
<div class="input-prepend">
|
||||||
|
<div class="add-on"><i class="icon-user"></i></div>
|
||||||
|
<input type="text" placeholder="Username" size="16" name="user" autofocus="autofocus">
|
||||||
|
</div>
|
||||||
|
<div class="input-prepend">
|
||||||
|
<div class="add-on"><i class="icon-lock"></i></div>
|
||||||
|
<input type="password" placeholder="Password" size="16" name="pass">
|
||||||
|
</div>
|
||||||
|
<input class="btn btn-primary" type="submit" name="submit" value="Log In"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{{template "footer.html"}}
|
18
trantor.go
18
trantor.go
|
@ -35,21 +35,6 @@ func logoutHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loginHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
|
||||||
user := r.FormValue("user")
|
|
||||||
pass := r.FormValue("pass")
|
|
||||||
if db.UserValid(user, pass) {
|
|
||||||
log.Println("User", user, "log in")
|
|
||||||
sess.LogIn(user)
|
|
||||||
sess.Notify("Successful login!", "Welcome "+user, "success")
|
|
||||||
} else {
|
|
||||||
log.Println("User", user, "bad user or password")
|
|
||||||
sess.Notify("Invalid login!", "user or password invalid", "error")
|
|
||||||
}
|
|
||||||
sess.Save(w, r)
|
|
||||||
http.Redirect(w, r, r.Referer(), http.StatusFound)
|
|
||||||
}
|
|
||||||
|
|
||||||
type bookData struct {
|
type bookData struct {
|
||||||
S Status
|
S Status
|
||||||
Book Book
|
Book Book
|
||||||
|
@ -167,7 +152,8 @@ func setUpRouter() {
|
||||||
r.HandleFunc("/search/", GatherStats(searchHandler))
|
r.HandleFunc("/search/", GatherStats(searchHandler))
|
||||||
r.HandleFunc("/upload/", GatherStats(uploadHandler)).Methods("GET")
|
r.HandleFunc("/upload/", GatherStats(uploadHandler)).Methods("GET")
|
||||||
r.HandleFunc("/upload/", GatherStats(uploadPostHandler)).Methods("POST")
|
r.HandleFunc("/upload/", GatherStats(uploadPostHandler)).Methods("POST")
|
||||||
r.HandleFunc("/login/", GatherStats(loginHandler)).Methods("POST")
|
r.HandleFunc("/login/", GatherStats(loginHandler)).Methods("GET")
|
||||||
|
r.HandleFunc("/login/", GatherStats(loginPostHandler)).Methods("POST")
|
||||||
r.HandleFunc("/logout/", GatherStats(logoutHandler))
|
r.HandleFunc("/logout/", GatherStats(logoutHandler))
|
||||||
r.HandleFunc("/new/", GatherStats(newHandler))
|
r.HandleFunc("/new/", GatherStats(newHandler))
|
||||||
r.HandleFunc("/store/{ids:([0-9a-fA-F]+/)+}", GatherStats(storeHandler))
|
r.HandleFunc("/store/{ids:([0-9a-fA-F]+/)+}", GatherStats(storeHandler))
|
||||||
|
|
27
user.go
Normal file
27
user.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func loginHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
||||||
|
var data statusData
|
||||||
|
data.S = GetStatus(w, r)
|
||||||
|
loadTemplate(w, "login", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loginPostHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
||||||
|
user := r.FormValue("user")
|
||||||
|
pass := r.FormValue("pass")
|
||||||
|
if db.UserValid(user, pass) {
|
||||||
|
log.Println("User", user, "log in")
|
||||||
|
sess.LogIn(user)
|
||||||
|
sess.Notify("Successful login!", "Welcome "+user, "success")
|
||||||
|
} else {
|
||||||
|
log.Println("User", user, "bad user or password")
|
||||||
|
sess.Notify("Invalid login!", "user or password invalid", "error")
|
||||||
|
}
|
||||||
|
sess.Save(w, r)
|
||||||
|
http.Redirect(w, r, r.Referer(), http.StatusFound)
|
||||||
|
}
|
Reference in a new issue