File size: 1,281 Bytes
83fe5e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4b33f1
7f5074c
83fe5e6
 
 
 
 
 
 
 
e4b33f1
83fe5e6
 
 
 
 
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
package controller

import (
	"github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
	services "github.com/abdanhafidz/ai-visual-multi-modal-backend/services"
	"github.com/gin-gonic/gin"
)

type AuhenticationController interface {
	Controller
	Login(ctx *gin.Context)
	Register(ctx *gin.Context)
}
type authenticationController struct {
	*controller[services.AuthenticationService]
}

func NewAuthenticationController(authenticationService services.AuthenticationService) AuhenticationController {
	return &authenticationController{
		controller: &controller[services.AuthenticationService]{service: authenticationService},
	}
}
func (c *authenticationController) Register(ctx *gin.Context) {
	var loginRequest models.LoginRequest
	c.RequestJSON(ctx, &loginRequest)
	if loginRequest.IPAddress == "" {
		loginRequest.IPAddress = ctx.ClientIP()
	}
	token := c.service.Register(ctx.Request.Context(), loginRequest.PassPhrase, loginRequest.TurnStile, loginRequest.IPAddress)

	c.Response(ctx, token)
}
func (c *authenticationController) Login(ctx *gin.Context) {
	var loginRequest models.LoginRequest
	c.RequestJSON(ctx, &loginRequest)

	token := c.service.Login(ctx.Request.Context(), loginRequest.PassPhrase)

	c.Response(ctx, token)
}