67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
|
package controllers
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
|
||
|
"git.1248.nz/1248/Otfe/misc/helpers"
|
||
|
"git.1248.nz/1248/Otfe/models"
|
||
|
"github.com/husobee/vestigo"
|
||
|
)
|
||
|
|
||
|
//User handlers
|
||
|
type Post struct {
|
||
|
Title string
|
||
|
}
|
||
|
|
||
|
//Index of posts
|
||
|
func (p Post) Index(w http.ResponseWriter, r *http.Request) {
|
||
|
p.Title = "Posts"
|
||
|
t(w, p, "/post/posts.gtpl")
|
||
|
}
|
||
|
|
||
|
//Show given user
|
||
|
func (p Post) Show(w http.ResponseWriter, r *http.Request) {
|
||
|
t(w, p, "/post/post.gtpl")
|
||
|
}
|
||
|
|
||
|
//New user form
|
||
|
func (p Post) New(w http.ResponseWriter, r *http.Request) {
|
||
|
t(w, p, "/post/new.gtpl")
|
||
|
}
|
||
|
|
||
|
//Create new a user
|
||
|
func (p Post) Create(w http.ResponseWriter, r *http.Request) {
|
||
|
r.ParseForm()
|
||
|
var user models.User
|
||
|
var err error
|
||
|
user.Username = r.Form.Get("username")
|
||
|
user.Email = r.Form.Get("email")
|
||
|
user.Password, err = helpers.HashPassword(r.Form.Get("password"))
|
||
|
helpers.CheckError(err)
|
||
|
user.Create()
|
||
|
http.Redirect(w, r, "/user/"+user.Username, http.StatusFound)
|
||
|
|
||
|
}
|
||
|
|
||
|
//Edit form
|
||
|
func (p Post) Edit(w http.ResponseWriter, r *http.Request) {
|
||
|
var data userData
|
||
|
data.User.Read("username", vestigo.Param(r, "username"))
|
||
|
|
||
|
}
|
||
|
|
||
|
//Update user
|
||
|
func (p Post) Update(w http.ResponseWriter, r *http.Request) {
|
||
|
|
||
|
}
|
||
|
|
||
|
//Delete user
|
||
|
func (p Post) Delete(w http.ResponseWriter, r *http.Request) {
|
||
|
fmt.Println("Deleting " + vestigo.Param(r, "username"))
|
||
|
var user models.User
|
||
|
user.Delete("username", vestigo.Param(r, "username"))
|
||
|
http.Redirect(w, r, "/user", http.StatusFound)
|
||
|
|
||
|
}
|