email 唯一

This commit is contained in:
2023-05-16 04:55:18 +08:00
parent 983447bfc2
commit f899e84b48
2 changed files with 2 additions and 2 deletions

View File

@@ -10,7 +10,7 @@ import (
type User struct {
ID int `json:"id" gorm:"primary_key"`
Name string `json:"name"`
Email string `json:"email"`
Email string `json:"email" gorm:"unique;not null"`
Password string `json:"-"`
Slat string `json:"-"`
Admin bool `json:"admin"`

View File

@@ -63,7 +63,7 @@ func SessionsPost(w http.ResponseWriter, r *http.Request) {
// 使用Email獲取用戶
var user models.User
if err := configs.ORMDB().Where("email = ?", form.Email).First(&user).Error; err != nil {
w.WriteHeader(http.StatusUnauthorized)
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("404 - User Not Found"))
return
}