user.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package fetdata
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. type User struct {
  7. wrap *wrapper.Wrapper
  8. object *utils.MySql_user
  9. }
  10. func (this *User) load() *User {
  11. return this
  12. }
  13. func (this *User) loadById(id int) {
  14. if this == nil {
  15. return
  16. }
  17. if this.object != nil {
  18. return
  19. }
  20. this.object = &utils.MySql_user{}
  21. if err := this.wrap.DB.QueryRow(`
  22. SELECT
  23. id,
  24. first_name,
  25. last_name,
  26. email,
  27. admin,
  28. active
  29. FROM
  30. users
  31. WHERE
  32. id = ?
  33. LIMIT 1;`,
  34. id,
  35. ).Scan(
  36. &this.object.A_id,
  37. &this.object.A_first_name,
  38. &this.object.A_last_name,
  39. &this.object.A_email,
  40. &this.object.A_admin,
  41. &this.object.A_active,
  42. ); *this.wrap.LogCpError(&err) != nil {
  43. return
  44. }
  45. }
  46. func (this *User) Id() int {
  47. if this == nil {
  48. return 0
  49. }
  50. return this.object.A_id
  51. }
  52. func (this *User) FirstName() string {
  53. if this == nil {
  54. return ""
  55. }
  56. return this.object.A_first_name
  57. }
  58. func (this *User) LastName() string {
  59. if this == nil {
  60. return ""
  61. }
  62. return this.object.A_last_name
  63. }
  64. func (this *User) Email() string {
  65. if this == nil {
  66. return ""
  67. }
  68. return this.object.A_email
  69. }
  70. func (this *User) IsAdmin() bool {
  71. if this == nil {
  72. return false
  73. }
  74. return this.object.A_admin == 1
  75. }
  76. func (this *User) IsActive() bool {
  77. if this == nil {
  78. return false
  79. }
  80. return this.object.A_active == 1
  81. }