|
|
@@ -2,23 +2,29 @@
|
|
|
package user
|
|
|
|
|
|
import (
|
|
|
- "github.com/runningwater/gohub/app/models"
|
|
|
- "github.com/runningwater/gohub/pkg/database"
|
|
|
+ "github.com/runningwater/gohub/app/models"
|
|
|
+ "github.com/runningwater/gohub/pkg/database"
|
|
|
+ "github.com/runningwater/gohub/pkg/hash"
|
|
|
)
|
|
|
|
|
|
// User 用户模型
|
|
|
type User struct {
|
|
|
- models.BaseModel
|
|
|
+ models.BaseModel
|
|
|
|
|
|
- Name string `json:"name,omitempty"`
|
|
|
- Email string `json:"-"`
|
|
|
- Phone string `json:"-"`
|
|
|
- Password string `json:"-"`
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ Email string `json:"-"`
|
|
|
+ Phone string `json:"-"`
|
|
|
+ Password string `json:"-"`
|
|
|
|
|
|
- models.CommonTimestampsField
|
|
|
+ models.CommonTimestampsField
|
|
|
}
|
|
|
|
|
|
// Create 创建用户, 通过 User.ID 来判断是否创建成功
|
|
|
func (u *User) Create() {
|
|
|
- database.DB.Create(&u)
|
|
|
+ database.DB.Create(&u)
|
|
|
+}
|
|
|
+
|
|
|
+// ComparePassword 密码是否匹配
|
|
|
+func (u *User) ComparePassword(_password string) bool {
|
|
|
+ return hash.BcryptCheck(_password, u.Password)
|
|
|
}
|