714563e59b1b1d5acc8c38510bd37a6026ee6245.svn-base 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. has, err := Engine.Exist(&User{Username: username,Password:password})
  32. return has, err
  33. }
  34. func GetUserInfo(username string )(map[string]interface{}){
  35. valuesMap, err := Engine.SQL("SELECT * FROM `user` WHERE `username` = ? and `enable` >0 ", username).Query().List()
  36. if err != nil {
  37. return nil
  38. }
  39. if len(valuesMap)>0 {
  40. valuesMap2, err := Engine.SQL("SELECT r.`name`,r.`id` FROM `user` u JOIN `role` r ON r.id=u.`roleid` WHERE r.`enable`>0 AND u.username=?", username).Query().List()
  41. if err == nil {
  42. valuesMap[0]["role"] = valuesMap2
  43. }
  44. return valuesMap[0]
  45. }
  46. return nil
  47. }
  48. /*
  49. func GetByName(username string) (User, error) {
  50. user := &User{Username:username}
  51. has, err := engine.Get(user)
  52. var valuesMap1 = make(map[string]string)
  53. engine.Find(&User{Username: username,Password:password})
  54. has, err := db.Sql("select * from article where id=?", 2).Get(&valuesMap1)
  55. has, err := engine.Exist(&User{Username: username})
  56. err := engine.Where("name = ?", name).And("age > 10").Limit(10, 0).Find(&users)
  57. has, err := engine.Where("Username = ?", username).Get(&user)
  58. return has, err
  59. }*/