blob: 6c6589b6767487c4978ec554bc5ed16334464a43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package auth
import (
"dove/config"
authUtils "dove/utils/auth"
"dove/utils/shortcuts"
"github.com/gofiber/fiber/v2"
)
type LoginRequest struct {
Username string `form:"username"`
Password string `form:"password"`
}
type MessageResponse struct {
Message string
}
func Authenticate(context *fiber.Ctx, request LoginRequest) (*MessageResponse, *shortcuts.Error) {
switch request.Username == config.HTTP.Username && request.Password == config.HTTP.Password {
case true:
if sessionError := authUtils.Authenticate(context); sessionError != nil {
return nil, shortcuts.ServiceError(shortcuts.Internal, sessionError.Error())
}
return &MessageResponse{
Message: Authenticated,
}, nil
default:
return nil, shortcuts.ServiceError(shortcuts.Unauthorized, InvalidCredentials)
}
}
func Deauthenticate(context *fiber.Ctx) (*MessageResponse, *shortcuts.Error) {
if sessionError := authUtils.Deauthenticate(context); sessionError != nil {
return nil, shortcuts.ServiceError(shortcuts.Internal, sessionError.Error())
}
return &MessageResponse{
Message: LoggedOut,
}, nil
}
|