added user Session Handler --> closed #20
This commit is contained in:
45
Backend/endpoints/user.go
Normal file
45
Backend/endpoints/user.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package endpoints
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func UserHandler(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.PathValue("action") {
|
||||
case "login":
|
||||
LoginHandler(w, r)
|
||||
case "settings":
|
||||
UserSettingsHandler(w, r)
|
||||
case "logout":
|
||||
logoutUser(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
showLoginPage(w, r, false)
|
||||
case http.MethodPost:
|
||||
loginUser(w, r)
|
||||
default:
|
||||
http.Error(w, "Method not allowed!", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func UserSettingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
helper.RequiresLogin(Session, w, r)
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
showUserPage(w, r, 0)
|
||||
case http.MethodPost:
|
||||
switch r.FormValue("action") {
|
||||
case "change-pass":
|
||||
changePassword(w, r)
|
||||
case "logout-user":
|
||||
logoutUser(w, r)
|
||||
}
|
||||
default:
|
||||
http.Error(w, "Method not allowed!", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user