Fixed container tests and import
This commit is contained in:
parent
0c8c3cc41e
commit
195d572036
3 changed files with 6 additions and 7 deletions
2
Makefile
2
Makefile
|
|
@ -29,5 +29,5 @@ run:
|
|||
go run main.go
|
||||
|
||||
.PHONY: test
|
||||
run:
|
||||
test:
|
||||
go test ./...
|
||||
|
|
@ -54,7 +54,6 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
|
||||
func TestNewContainer(t *testing.T) {
|
||||
c := NewContainer()
|
||||
assert.NotNil(t, c.Web)
|
||||
assert.NotNil(t, c.Config)
|
||||
assert.NotNil(t, c.Cache)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package middleware
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"goweb/auth"
|
||||
"goweb/container"
|
||||
"goweb/context"
|
||||
"goweb/ent"
|
||||
"goweb/msg"
|
||||
|
|
@ -11,14 +11,14 @@ import (
|
|||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func LoadAuthenticatedUser(authClient *auth.Client) echo.MiddlewareFunc {
|
||||
func LoadAuthenticatedUser(authClient *container.AuthClient) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
u, err := authClient.GetAuthenticatedUser(c)
|
||||
switch err.(type) {
|
||||
case *ent.NotFoundError:
|
||||
c.Logger().Debug("auth user not found")
|
||||
case auth.NotAuthenticatedError:
|
||||
case container.NotAuthenticatedError:
|
||||
case nil:
|
||||
c.Set(context.AuthenticatedUserKey, u)
|
||||
c.Logger().Info("auth user loaded in to context: %d", u.ID)
|
||||
|
|
@ -31,7 +31,7 @@ func LoadAuthenticatedUser(authClient *auth.Client) echo.MiddlewareFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func LoadValidPasswordToken(authClient *auth.Client) echo.MiddlewareFunc {
|
||||
func LoadValidPasswordToken(authClient *container.AuthClient) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
var usr *ent.User
|
||||
|
|
@ -46,7 +46,7 @@ func LoadValidPasswordToken(authClient *auth.Client) echo.MiddlewareFunc {
|
|||
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
case auth.InvalidTokenError:
|
||||
case container.InvalidTokenError:
|
||||
msg.Warning(c, "The link is either invalid or has expired. Please request a new one.")
|
||||
return c.Redirect(http.StatusFound, c.Echo().Reverse("forgot_password"))
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue