account.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * @description:用户相关
  3. * @Author: CP
  4. * @Date: 2020-08-27 17:03:34
  5. * @FilePath: \construction_management\web\controllers\account.go
  6. */
  7. package controllers
  8. import (
  9. "github.com/kataras/iris/v12"
  10. "github.com/kataras/iris/v12/mvc"
  11. "go.mod/comm"
  12. "go.mod/services"
  13. "go.mod/web/utils"
  14. )
  15. type AccountController struct {
  16. //框架-web应用上下文环境
  17. Ctx iris.Context
  18. // 需要用的service
  19. ServiceProjectAccount services.ProjectAccountService
  20. }
  21. // 用户首页
  22. func (c *AccountController) Get() mvc.Result {
  23. ErrMsg := c.Ctx.URLParam("errMsg")
  24. Success := c.Ctx.URLParam("success")
  25. return mvc.View{
  26. Name: "account/index.html",
  27. Data: iris.Map{
  28. "Title": "账号资料",
  29. "Channel": "account",
  30. "Action": "/account/save",
  31. "Menu": "account",
  32. "ErrMsg": ErrMsg,
  33. "Success": Success,
  34. },
  35. Layout: "account/layout.html",
  36. }
  37. }
  38. // 保存项目管理员信息
  39. func (c *AccountController) PostSave() {
  40. ErrMsg := ""
  41. // 验证内容
  42. AccountData, err := c.ServiceProjectAccount.ValidRule(c.Ctx)
  43. if err != nil {
  44. ErrMsg = utils.FormValidError(err)
  45. comm.Redirect(c.Ctx.ResponseWriter(), "/account?errMsg="+ErrMsg)
  46. } else {
  47. // 获得更新用户ID
  48. id, err := c.Ctx.Values().GetInt("accountId")
  49. if err != nil {
  50. comm.Redirect(c.Ctx.ResponseWriter(), "/account?errMsg="+ErrMsg)
  51. }
  52. // 保存信息
  53. err = c.ServiceProjectAccount.Save(AccountData, id)
  54. if err != nil {
  55. comm.Redirect(c.Ctx.ResponseWriter(), "/account?errMsg="+ErrMsg)
  56. }
  57. comm.Redirect(c.Ctx.ResponseWriter(), "/account?success=修改成功")
  58. }
  59. }
  60. // 账号安全
  61. func (c *AccountController) GetSafe() mvc.Result {
  62. return mvc.View{
  63. Name: "account/safe.html",
  64. Data: iris.Map{
  65. "Title": "账号安全",
  66. "Channel": "account",
  67. "Action": "/account",
  68. "Menu": "accountSafe",
  69. },
  70. Layout: "account/layout.html",
  71. }
  72. }