user.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package fetdata
  2. import (
  3. "golang-fave/utils"
  4. )
  5. func (this *FERData) userToBuffer() {
  6. if this.bufferUser == nil {
  7. user := utils.MySql_user{}
  8. if this.wrap.S.GetInt("UserId", 0) > 0 {
  9. err := this.wrap.DB.QueryRow(`
  10. SELECT
  11. id,
  12. first_name,
  13. last_name,
  14. email,
  15. admin,
  16. active
  17. FROM
  18. users
  19. WHERE
  20. id = ?
  21. LIMIT 1;`,
  22. this.wrap.S.GetInt("UserId", 0),
  23. ).Scan(
  24. &user.A_id,
  25. &user.A_first_name,
  26. &user.A_last_name,
  27. &user.A_email,
  28. &user.A_admin,
  29. &user.A_active,
  30. )
  31. if err != nil {
  32. this.wrap.LogError(err.Error())
  33. }
  34. }
  35. this.bufferUser = &user
  36. }
  37. }
  38. func (this *FERData) UserIsLoggedIn() bool {
  39. this.userToBuffer()
  40. return this.bufferUser.A_id > 0
  41. }
  42. func (this *FERData) UserID() int {
  43. this.userToBuffer()
  44. return this.bufferUser.A_id
  45. }
  46. func (this *FERData) UserFirstName() string {
  47. this.userToBuffer()
  48. return this.bufferUser.A_first_name
  49. }
  50. func (this *FERData) UserLastName() string {
  51. this.userToBuffer()
  52. return this.bufferUser.A_last_name
  53. }
  54. func (this *FERData) UserEmail() string {
  55. this.userToBuffer()
  56. return this.bufferUser.A_email
  57. }
  58. func (this *FERData) UserIsAdmin() bool {
  59. this.userToBuffer()
  60. return this.bufferUser.A_admin > 0
  61. }
  62. func (this *FERData) UserIsActive() bool {
  63. this.userToBuffer()
  64. return this.bufferUser.A_active > 0
  65. }