aboutsummaryrefslogtreecommitdiff
path: root/src/user/routes.go
blob: f826822d0ee98c755bbca09e0d45230c6a5fff99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package user

import (
	"fmt"
	"net/http"

	"gitlab.com/alexkavon/newsstand/src/server"
)

var Routes = server.Routes{
	server.Route{
		Name:        "Create",
		Method:      "GET",
		Path:        "/user/create",
		HandlerFunc: Create,
	},
	server.Route{
		Name:        "Store",
		Method:      "POST",
		Path:        "/user",
		HandlerFunc: Store,
	},
	server.Route{
		Name:        "LoginForm",
		Method:      "GET",
		Path:        "/user/auth",
		HandlerFunc: LoginForm,
	},
	server.Route{
		Name:        "Authenticate",
		Method:      "POST",
		Path:        "/user/auth",
		HandlerFunc: Authenticate,
	},
	server.Route{
		Name:         "Me",
		Method:       "GET",
		Path:         "/user/me",
		AuthRequired: true,
		HandlerFunc:  Show,
	},
}

func Create(s *server.Server) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		s.Ui.Render(w, "user/create", nil)
	}
}

func Store(s *server.Server) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		r.ParseForm()
		fmt.Println(r.PostForm)
		s.Ui.RenderTemplate(w, "core", "messages", &struct{ Message string }{Message: "Congrats"})
	}
}

func LoginForm(s *server.Server) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		s.Ui.Render(w, "user/login", nil)
	}
}

func Authenticate(s *server.Server) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {}
}

func Show(s *server.Server) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {}
}