user.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // User user
  7. type User struct {
  8. gorm.Model
  9. RecordId string `gorm:"column:record_id;size:32;index"`
  10. UserKey string
  11. UserRoleID int
  12. UserName string `sql:"type:varchar(20);not null;"`
  13. UserPass string `sql:"type:varchar(50);not null;"`
  14. Phone string `sql:"type:varchar(20);not null;"`
  15. Email string `sql:"type:varchar(200);not null;"`
  16. UserType int `sql:"default:1;not null;"`
  17. VendorID string `gorm:"column:vendor_id;size:32;index"`
  18. Status int `sql:"default:1;not null;"`
  19. Vendor Vendor `gorm:"foreignkey:VendorID"`
  20. }
  21. // LoginRequest 登录请求
  22. type LoginRequest struct {
  23. UserName string `json:"login_name" `
  24. Password string `json:"login_pass" `
  25. }
  26. // Reqrequest 注册请求
  27. type Reqrequest struct {
  28. UserName string `json:"username"`
  29. PassWord string `json:"password" `
  30. Phone string `json:"phone" `
  31. Email string `json:"email" `
  32. VendorName string `json:"company"`
  33. }
  34. // ChangePassWordRequest 修改密码请求结构
  35. type ChangePassWordRequest struct {
  36. OldPass string `json:"old_pass"` //base64加密后的字符串
  37. NewPass string `json:"new_pass"` //base64加密后的字符串
  38. }
  39. // Validate 验证
  40. func (a *ChangePassWordRequest) Validate() error {
  41. if a.NewPass == "" || a.OldPass == "" {
  42. return errors.New("非法参数")
  43. }
  44. return nil
  45. }
  46. // Validate 验证
  47. func (a *Reqrequest) Validate() error {
  48. if a.UserName == "" || a.PassWord == "" || a.Phone == "" || a.Email == "" || a.VendorName == "" {
  49. return errors.New("参数不能为空")
  50. }
  51. return nil
  52. }
  53. // Validate 验证
  54. func (a *LoginRequest) Validate() error {
  55. if a.UserName == "" || a.Password == "" {
  56. return errors.New("参数不能为空")
  57. }
  58. return nil
  59. }
  60. // Validate 验证
  61. func (a *User) Validate() error {
  62. if a.UserName == "" || a.UserPass == "" || a.Vendor.VendorName == "" {
  63. return errors.New("参数不能为空")
  64. }
  65. return nil
  66. }