Bump sessions
This commit is contained in:
parent
3104cc8f7a
commit
24de5ef2e5
34
api/auth.go
34
api/auth.go
@ -38,7 +38,7 @@ func register(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
AuthController, err := controller.MakeAuthController()
|
||||
authController, err := controller.MakeAuthController()
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
@ -47,7 +47,7 @@ func register(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = AuthController.Register(transaction.Username, transaction.Password, transaction.RepeatPassword)
|
||||
err = authController.Register(transaction.Username, transaction.Password, transaction.RepeatPassword)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
@ -74,7 +74,7 @@ func login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
AuthController, err := controller.MakeAuthController()
|
||||
authController, err := controller.MakeAuthController()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": err.Error(),
|
||||
@ -82,7 +82,7 @@ func login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
token, ok, err := AuthController.Login(transaction.Username, transaction.Password)
|
||||
token, ok, err := authController.Login(transaction.Username, transaction.Password)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": err.Error(),
|
||||
@ -105,7 +105,7 @@ func login(c *gin.Context) {
|
||||
}
|
||||
|
||||
func logout(c *gin.Context) {
|
||||
AuthController, err := controller.MakeAuthController()
|
||||
authController, err := controller.MakeAuthController()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": err.Error(),
|
||||
@ -114,7 +114,7 @@ func logout(c *gin.Context) {
|
||||
}
|
||||
|
||||
token, _ := c.Get(SESSION_COOKIE) // must exist after isLoggedIn
|
||||
err = AuthController.Logout(token.(string))
|
||||
err = authController.Logout(token.(string))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": err.Error(),
|
||||
@ -127,3 +127,25 @@ func logout(c *gin.Context) {
|
||||
"message": "sucessful logout",
|
||||
})
|
||||
}
|
||||
|
||||
func bump(c *gin.Context) {
|
||||
authController, err := controller.MakeAuthController()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
token, _ := c.Get(SESSION_COOKIE)
|
||||
if err = authController.Bump(token.(string)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "bumped",
|
||||
})
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ func Listen(address string, base string) error {
|
||||
auth.POST("register", register)
|
||||
auth.POST("login", login)
|
||||
auth.GET("logout", isLoggedIn, logout)
|
||||
auth.GET("bump", isLoggedIn, bump)
|
||||
|
||||
server := &http.Server{
|
||||
Addr: address,
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
|
||||
"git.tek.govt.hu/dowerx/chat/server/config"
|
||||
"git.tek.govt.hu/dowerx/chat/server/dao"
|
||||
"git.tek.govt.hu/dowerx/chat/server/model"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@ -98,3 +99,7 @@ func (c AuthController) Login(username string, password string) (string, bool, e
|
||||
func (c AuthController) Logout(token string) error {
|
||||
return c.sessionDAO.Delete(token)
|
||||
}
|
||||
|
||||
func (c AuthController) Bump(token string) error {
|
||||
return c.sessionDAO.Bump(token, config.GetConfig().API.TokenLife)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package controller
|
||||
|
||||
func MakeAuthController() (AuthController, error) {
|
||||
AuthController := &AuthController{}
|
||||
err := AuthController.init()
|
||||
return *AuthController, err
|
||||
authController := &AuthController{}
|
||||
err := authController.init()
|
||||
return *authController, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user