forked from jason/cpolis
Shorten lines by referencing frontend as f and backend as b
This commit is contained in:
@@ -7,15 +7,15 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"streifling.com/jason/cpolis/cmd/backend"
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
)
|
||||
|
||||
type UserData struct {
|
||||
*backend.User
|
||||
*b.User
|
||||
Msg string
|
||||
}
|
||||
|
||||
func checkUserStrings(user *backend.User) (string, int, bool) {
|
||||
func checkUserStrings(user *b.User) (string, int, bool) {
|
||||
userLen := 15
|
||||
nameLen := 50
|
||||
|
||||
@@ -30,14 +30,14 @@ func checkUserStrings(user *backend.User) (string, int, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func CreateUser(c *backend.Config) http.HandlerFunc {
|
||||
func CreateUser(c *b.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/add-user.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func AddUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.HandlerFunc {
|
||||
func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
role, err := strconv.Atoi(r.PostFormValue("role"))
|
||||
if err != nil {
|
||||
@@ -47,7 +47,7 @@ func AddUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.Han
|
||||
}
|
||||
|
||||
htmlData := UserData{
|
||||
User: &backend.User{
|
||||
User: &b.User{
|
||||
UserName: r.PostFormValue("username"),
|
||||
FirstName: r.PostFormValue("first-name"),
|
||||
LastName: r.PostFormValue("last-name"),
|
||||
@@ -107,7 +107,7 @@ func AddUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.Han
|
||||
}
|
||||
}
|
||||
|
||||
func EditSelf(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.HandlerFunc {
|
||||
func EditSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := s.Get(r, "cookie")
|
||||
if err != nil {
|
||||
@@ -128,7 +128,7 @@ func EditSelf(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.Ha
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateSelf(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.HandlerFunc {
|
||||
func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := s.Get(r, "cookie")
|
||||
if err != nil {
|
||||
@@ -138,7 +138,7 @@ func UpdateSelf(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.
|
||||
}
|
||||
|
||||
userData := UserData{
|
||||
User: &backend.User{
|
||||
User: &b.User{
|
||||
ID: session.Values["id"].(int64),
|
||||
UserName: r.PostFormValue("username"),
|
||||
FirstName: r.PostFormValue("first-name"),
|
||||
@@ -198,16 +198,16 @@ func UpdateSelf(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.
|
||||
}
|
||||
}
|
||||
|
||||
func AddFirstUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.HandlerFunc {
|
||||
func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
|
||||
htmlData := UserData{
|
||||
User: &backend.User{
|
||||
User: &b.User{
|
||||
UserName: r.PostFormValue("username"),
|
||||
FirstName: r.PostFormValue("first-name"),
|
||||
LastName: r.PostFormValue("last-name"),
|
||||
Role: backend.Admin,
|
||||
Role: b.Admin,
|
||||
},
|
||||
}
|
||||
pass := r.PostFormValue("password")
|
||||
@@ -273,11 +273,11 @@ func AddFirstUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) htt
|
||||
}
|
||||
}
|
||||
|
||||
func ShowAllUsers(c *backend.Config, db *backend.DB, s *backend.CookieStore, action string) http.HandlerFunc {
|
||||
func ShowAllUsers(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
type htmlData struct {
|
||||
Users map[int64]*backend.User
|
||||
Users map[int64]*b.User
|
||||
Action string
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ func ShowAllUsers(c *backend.Config, db *backend.DB, s *backend.CookieStore, act
|
||||
}
|
||||
}
|
||||
|
||||
func EditUser(c *backend.Config, db *backend.DB) http.HandlerFunc {
|
||||
func EditUser(c *b.Config, db *b.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
@@ -323,7 +323,7 @@ func EditUser(c *backend.Config, db *backend.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.HandlerFunc {
|
||||
func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
@@ -340,7 +340,7 @@ func UpdateUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.
|
||||
}
|
||||
|
||||
userData := UserData{
|
||||
User: &backend.User{
|
||||
User: &b.User{
|
||||
ID: id,
|
||||
UserName: r.PostFormValue("username"),
|
||||
FirstName: r.PostFormValue("first-name"),
|
||||
@@ -407,7 +407,7 @@ func UpdateUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteUser(c *backend.Config, db *backend.DB, s *backend.CookieStore) http.HandlerFunc {
|
||||
func DeleteUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user