Move login-code to http

This commit is contained in:
2016-12-19 22:47:45 +01:00
parent 227028f99d
commit 8231b3d176
2 changed files with 45 additions and 37 deletions

View File

@ -13,40 +13,4 @@ func main() {
h := &http.Handler{UserService=us}
h.Serve()
}
func restricted(c *gin.Context) {
claims, ok := verifyLogin(c)
if !ok {
c.Redirect(http.StatusTemporaryRedirect, "/login")
return
}
name := claims["name"].(string)
c.String(http.StatusOK, "Welcome "+name+"!")
}
func login(c *gin.Context) {
if _, ok := verifyLogin(c); ok {
c.Redirect(http.StatusTemporaryRedirect, "/api/v1/hello")
return
}
c.HTML(http.StatusOK, "login", nil)
}
func logout(c *gin.Context) {
clearLogin(c)
}
func loginPost(c *gin.Context) {
username, _ := c.GetPostForm("username")
password, _ := c.GetPostForm("password")
if username != "jan" || password != "passwort" {
c.AbortWithStatus(http.StatusUnauthorized)
return
}
loginSuccess(c, username, "Jan Bader")
}
}