| 273 | } |
| 274 | |
| 275 | func (s *Server) handleDelete(c *gin.Context) { |
| 276 | if !validateOrigin(c.Request) { |
| 277 | c.Status(http.StatusForbidden) |
| 278 | return |
| 279 | } |
| 280 | |
| 281 | currentSession, ok := s.getSession(c.GetHeader(SessionHeader)) |
| 282 | if !ok { |
| 283 | c.Status(http.StatusNotFound) |
| 284 | return |
| 285 | } |
| 286 | |
| 287 | user := c.Request.Context().Value(conf.UserKey).(*model.User) |
| 288 | if currentSession.userID != user.ID { |
| 289 | c.Status(http.StatusNotFound) |
| 290 | return |
| 291 | } |
| 292 | |
| 293 | s.deleteSession(currentSession.id) |
| 294 | c.Status(http.StatusNoContent) |
| 295 | } |
| 296 | |
| 297 | func (s *Server) createSession(userID uint) *session { |
| 298 | s.mu.Lock() |