signout
This commit is contained in:
		@@ -140,19 +140,22 @@ func SessionsItemDelete(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
	user := models.User{ID: session.UserID}
 | 
						user := models.User{ID: session.UserID}
 | 
				
			||||||
	configs.ORMDB().Find(&user)
 | 
						configs.ORMDB().Find(&user)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sessionx := models.Session{ID: mux.Vars(r)["session_id"]}
 | 
						// 獲取目標 session
 | 
				
			||||||
 | 
						sessionx := models.Session{ID: mux.Vars(r)["id"]}
 | 
				
			||||||
	if err := configs.ORMDB().Find(&sessionx).Error; err != nil {
 | 
						if err := configs.ORMDB().Find(&sessionx).Error; err != nil {
 | 
				
			||||||
		w.WriteHeader(http.StatusNotFound)
 | 
							w.WriteHeader(http.StatusNotFound)
 | 
				
			||||||
		w.Write([]byte("404 - Not Found"))
 | 
							w.Write([]byte("404 - Not Found"))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 驗證用戶身(只能刪除自己的會話)
 | 
				
			||||||
	if user.ID != sessionx.UserID {
 | 
						if user.ID != sessionx.UserID {
 | 
				
			||||||
		w.WriteHeader(http.StatusUnauthorized)
 | 
							w.WriteHeader(http.StatusUnauthorized)
 | 
				
			||||||
		w.Write([]byte("401 - 沒有權限"))
 | 
							w.Write([]byte("401 - 沒有權限:"))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 刪除目标會話
 | 
				
			||||||
	if err := configs.ORMDB().Delete(&sessionx).Error; err != nil {
 | 
						if err := configs.ORMDB().Delete(&sessionx).Error; err != nil {
 | 
				
			||||||
		w.WriteHeader(http.StatusNotFound)
 | 
							w.WriteHeader(http.StatusNotFound)
 | 
				
			||||||
		w.Write([]byte("404 - Not Found"))
 | 
							w.Write([]byte("404 - Not Found"))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user