mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-20 01:31:09 +01:00
Admin: Added user deletion route and button
This commit is contained in:
parent
b812b8be26
commit
f3779aa4bd
|
@ -35,12 +35,14 @@ There are a couple options for getting Pogo up and running.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
|
_Note: [This requires a valid Go enviornment setup!](https://golang.org/doc/install)_
|
||||||
|
|
||||||
```
|
```
|
||||||
# Clone the repository
|
# Go get the repository
|
||||||
git clone https://github.com/gmemstr/pogo
|
go get github.com/gmemstr/pogo
|
||||||
|
|
||||||
# Go to directory
|
# Go to directory
|
||||||
cd pogo
|
cd $GOPATH/src/github.com/gmemstr/pogo
|
||||||
|
|
||||||
# Get godep
|
# Get godep
|
||||||
go get github.com/tools/godep
|
go get github.com/tools/godep
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/gmemstr/pogo/common"
|
"github.com/gmemstr/pogo/common"
|
||||||
)
|
)
|
||||||
|
@ -169,6 +170,52 @@ func EditUser() common.Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteUser() common.Handler {
|
||||||
|
|
||||||
|
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite3", "assets/config/users.db")
|
||||||
|
if err != nil {
|
||||||
|
return &common.HTTPError{
|
||||||
|
Message: fmt.Sprintf("error opening sqlite3 file: %v", err),
|
||||||
|
StatusCode: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
statement, err := db.Prepare("DELETE FROM users WHERE id=?")
|
||||||
|
if err != nil {
|
||||||
|
return &common.HTTPError{
|
||||||
|
Message: fmt.Sprintf("error preparing sqlite3 statement: %v", err),
|
||||||
|
StatusCode: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return &common.HTTPError{
|
||||||
|
Message: err.Error(),
|
||||||
|
StatusCode: http.StatusBadRequest,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
id := vars["id"]
|
||||||
|
if id == "1" {
|
||||||
|
w.Write([]byte("<script>window.location = '/admin#/msg/Cannot%20Delete%20Admin%20User';</script>"))
|
||||||
|
db.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = statement.Exec(id)
|
||||||
|
if err != nil {
|
||||||
|
return &common.HTTPError{
|
||||||
|
Message: fmt.Sprintf("error executing sqlite3 statement: %v", err),
|
||||||
|
StatusCode: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.Write([]byte("<script>window.location = '/admin#/msg/Deleted%20User';</script>"))
|
||||||
|
db.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ListUsers() common.Handler {
|
func ListUsers() common.Handler {
|
||||||
|
|
||||||
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
|
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
|
||||||
|
|
Binary file not shown.
|
@ -118,6 +118,7 @@ const useredit = {
|
||||||
<input name="id" id="id" :value="user.id" type="hidden">
|
<input name="id" id="id" :value="user.id" type="hidden">
|
||||||
<br />
|
<br />
|
||||||
<input type="submit" value="Save"></form>
|
<input type="submit" value="Save"></form>
|
||||||
|
<a v-bind:href="'/admin/deleteuser/'+user.id+''">Delete User</a>
|
||||||
</div>
|
</div>
|
||||||
</div>`,
|
</div>`,
|
||||||
data() {
|
data() {
|
||||||
|
|
|
@ -92,7 +92,10 @@ func Init() *mux.Router {
|
||||||
auth.RequireAuthorization(),
|
auth.RequireAuthorization(),
|
||||||
admin.AddUser(),
|
admin.AddUser(),
|
||||||
)).Methods("POST")
|
)).Methods("POST")
|
||||||
|
r.Handle("/admin/deleteuser/{id}", Handle(
|
||||||
|
auth.RequireAuthorization(),
|
||||||
|
admin.DeleteUser(),
|
||||||
|
)).Methods("GET")
|
||||||
r.Handle("/admin/edit", Handle(
|
r.Handle("/admin/edit", Handle(
|
||||||
auth.RequireAuthorization(),
|
auth.RequireAuthorization(),
|
||||||
admin.EditEpisode(),
|
admin.EditEpisode(),
|
||||||
|
|
|
@ -23,6 +23,6 @@ func main() {
|
||||||
// Define routes
|
// Define routes
|
||||||
// We're live
|
// We're live
|
||||||
r := router.Init()
|
r := router.Init()
|
||||||
fmt.Println("Listening on port :3000")
|
fmt.Println("Your Pogo instance is live on port :3000")
|
||||||
log.Fatal(http.ListenAndServe(":3000", r))
|
log.Fatal(http.ListenAndServe(":3000", r))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue