auth.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package controller
  2. import (
  3. "git.wanbits.cc/sin/flytalk/config"
  4. "git.wanbits.cc/sin/flytalk/models"
  5. "git.wanbits.cc/sin/flytalk/tools"
  6. )
  7. func CheckPass(username string, password string) string {
  8. account := config.GetAccount()
  9. if account == nil {
  10. account = make(map[string]string)
  11. }
  12. if account["Username"] == "" && account["Password"] == "" {
  13. account["Username"] = "admin"
  14. account["Password"] = "admin123"
  15. }
  16. if username == account["Username"] && password == account["Password"] {
  17. sessionId := tools.Md5(username)
  18. info := make(map[string]string)
  19. info["username"] = username
  20. config.SetUserInfo(sessionId, info)
  21. return sessionId
  22. }
  23. return ""
  24. }
  25. func CheckKefuPass(username string, password string) (models.User, models.User_role, bool) {
  26. info := models.FindUser(username)
  27. var uRole models.User_role
  28. if info.Name == "" || info.Password != tools.Md5(password) {
  29. return info, uRole, false
  30. }
  31. uRole = models.FindRoleByUserId(info.ID)
  32. return info, uRole, true
  33. }
  34. func AuthLocal(username string, password string) string {
  35. account := config.GetAccount()
  36. if account == nil {
  37. account = make(map[string]string)
  38. }
  39. if account["Username"] == "" && account["Password"] == "" {
  40. account["Username"] = "admin"
  41. account["Password"] = "admin123"
  42. }
  43. if username == account["Username"] && password == account["Password"] {
  44. sessionId := tools.Md5(username)
  45. info := make(map[string]string)
  46. info["username"] = username
  47. config.SetUserInfo(sessionId, info)
  48. return sessionId
  49. }
  50. return ""
  51. }
  52. //验证是否已经登录
  53. func AuthCheck(uid string) map[string]string {
  54. info := config.GetUserInfo(uid)
  55. return info
  56. }