Skip to content
Permalink
Browse files

04-Web-Form get web login form

  • Loading branch information...
bonfy committed Sep 10, 2018
1 parent ed49bb8 commit 3e42c84122344d4024968f518bc48cb56c38fac3
Showing with 42 additions and 4 deletions.
  1. +10 −1 controller/home.go
  2. +6 −1 templates/_base.html
  3. +8 −0 templates/content/login.html
  4. +2 −2 vm/index.go
  5. +16 −0 vm/login.go
@@ -10,10 +10,19 @@ type home struct{}

func (h home) registerRoutes() {
http.HandleFunc("/", indexHandler)
http.HandleFunc("/login", loginHandler)
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
tpName := "index.html"
vop := vm.IndexViewModelOp{}
v := vop.GetVM()
templates["index.html"].Execute(w, &v)
templates[tpName].Execute(w, &v)
}

func loginHandler(w http.ResponseWriter, r *http.Request) {
tpName := "login.html"
vop := vm.LoginViewModelOp{}
v := vop.GetVM()
templates[tpName].Execute(w, &v)
}
@@ -7,7 +7,12 @@
{{end}}
</head>
<body>
<div>Blog: <a href="/">Home</a></div>
<div>
Blog:
<a href="/">Home</a>
<a href="/login">Login</a>
</div>

{{template "content" .}}
</body>
</html>
@@ -0,0 +1,8 @@
{{define "content"}}
<h1>Login</h1>
<form action="/login" method="post" name="login">
<p><input type="text" name="username" value="" placeholder="Username or Email"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p><input type="submit" name="submit" value="Login"></p>
</form>
{{end}}
@@ -22,6 +22,6 @@ func (IndexViewModelOp) GetVM() IndexViewModel {
model.Post{User: u2, Body: "The Avengers movie was so cool!"},
}

vm := IndexViewModel{BaseViewModel{Title: "Homepage"}, u1, posts}
return vm
v := IndexViewModel{BaseViewModel{Title: "Homepage"}, u1, posts}
return v
}
@@ -0,0 +1,16 @@
package vm

// LoginViewModel struct
type LoginViewModel struct {
BaseViewModel
}

// LoginViewModelOp strutc
type LoginViewModelOp struct{}

// GetVM func
func (LoginViewModelOp) GetVM() LoginViewModel {
v := LoginViewModel{}
v.SetTitle("Login")
return v
}

0 comments on commit 3e42c84

Please sign in to comment.
You can’t perform that action at this time.