user.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package restful
  2. type User struct {
  3. Id int `xorm:"not null pk autoincr INT(10)"`
  4. Username string `xorm:"default '''' comment('账号') VARCHAR(50)"`
  5. Password string `xorm:"default '''' comment('密码') VARCHAR(50)"`
  6. Empid int `xorm:"default -1 INT(11)"`
  7. Sort int `xorm:"default 0 INT(11)"`
  8. Enable int `xorm:"default 1 TINYINT(4)"`
  9. CreatedOn int `xorm:"default NULL comment('创建时间') INT(11)"`
  10. ModifiedOn int `xorm:"default NULL comment('更新时间') INT(11)"`
  11. DeletedOn int `xorm:"default 0 comment('删除时间戳') INT(11)"`
  12. }
  13. /*
  14. type UserRole struct {
  15. Id int `xorm:"not null pk autoincr INT(10)"`
  16. UserId int `xorm:"default NULL comment('用户ID') INT(11)"`
  17. RoleId int `xorm:"default NULL comment('角色ID') INT(11)"`
  18. DeletedOn int `xorm:"default 0 comment('删除时间戳') INT(11)"`
  19. }
  20. type Role struct {
  21. Id int `xorm:"not null pk autoincr INT(10)"`
  22. Name string `xorm:"default '''' comment('名字') VARCHAR(50)"`
  23. Sort int `xorm:"default 0 INT(11)"`
  24. Enable int `xorm:"default 1 TINYINT(4)"`
  25. CreatedOn int `xorm:"default NULL comment('创建时间') INT(11)"`
  26. ModifiedOn int `xorm:"default NULL comment('更新时间') INT(11)"`
  27. DeletedOn int `xorm:"default 0 comment('删除时间戳') INT(11)"`
  28. }
  29. */
  30. func CheckUser(username, password string) (bool, error) {
  31. return true, nil
  32. }
  33. func GetUserInfo(username string) map[string]interface{} {
  34. valuesMap := make([]map[string]interface{}, 1)
  35. valuesMap2 := make([]map[string]interface{}, 1)
  36. tqueryData, err := Dbs.Queryx("SELECT * FROM `user` WHERE `username` = ? and `enable` >0 ", username)
  37. if err != nil {
  38. return nil
  39. }
  40. valuesMap, err = rows2mapObjects(tqueryData)
  41. if err != nil {
  42. return nil
  43. }
  44. if len(valuesMap) > 0 {
  45. tqueryData2, err := Dbs.Queryx("SELECT r.`name`,r.`id` FROM `user` u JOIN `user_role` ur ON u.`id`=ur.`user_id` JOIN `role` r ON r.id=ur.`role_id` WHERE r.`enable`>0 AND u.username=?", username)
  46. if err == nil {
  47. valuesMap2, err = rows2mapObjects(tqueryData2)
  48. if err == nil {
  49. valuesMap[0]["role"] = valuesMap2
  50. }
  51. }
  52. return valuesMap[0]
  53. }
  54. return nil
  55. }