Login handles authentication verification
(c *gin.Context)
| 87 | |
| 88 | // Login handles authentication verification |
| 89 | func (s *Server) Login(c *gin.Context) { |
| 90 | var req LoginRequest |
| 91 | if err := c.ShouldBindJSON(&req); err != nil { |
| 92 | c.JSON(http.StatusBadRequest, gin.H{ |
| 93 | "success": false, |
| 94 | "message": i18n.Message(c, "auth.invalid_request"), |
| 95 | }) |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | authConfig := s.config.GetAuthConfig() |
| 100 | |
| 101 | isValid := subtle.ConstantTimeCompare([]byte(req.AuthKey), []byte(authConfig.Key)) == 1 |
| 102 | |
| 103 | if isValid { |
| 104 | c.JSON(http.StatusOK, LoginResponse{ |
| 105 | Success: true, |
| 106 | Message: i18n.Message(c, "auth.authentication_successful"), |
| 107 | }) |
| 108 | } else { |
| 109 | c.JSON(http.StatusUnauthorized, LoginResponse{ |
| 110 | Success: false, |
| 111 | Message: i18n.Message(c, "auth.authentication_failed"), |
| 112 | }) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Health handles health check requests |
| 117 | func (s *Server) Health(c *gin.Context) { |
nothing calls this directly
no test coverage detected