account.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SiYuan - Refactor your thinking
  2. // Copyright (c) 2020-present, b3log.org
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. package api
  17. import (
  18. "net/http"
  19. "github.com/88250/gulu"
  20. "github.com/gin-gonic/gin"
  21. "github.com/siyuan-note/siyuan/kernel/model"
  22. "github.com/siyuan-note/siyuan/kernel/util"
  23. )
  24. func startFreeTrial(c *gin.Context) {
  25. ret := gulu.Ret.NewResult()
  26. defer c.JSON(http.StatusOK, ret)
  27. err := model.StartFreeTrial()
  28. if nil != err {
  29. ret.Code = -1
  30. ret.Msg = err.Error()
  31. return
  32. }
  33. }
  34. func useActivationcode(c *gin.Context) {
  35. ret := gulu.Ret.NewResult()
  36. defer c.JSON(http.StatusOK, ret)
  37. arg, ok := util.JsonArg(c, ret)
  38. if !ok {
  39. return
  40. }
  41. code := arg["data"].(string)
  42. err := model.UseActivationcode(code)
  43. if nil != err {
  44. ret.Code = -1
  45. ret.Msg = err.Error()
  46. return
  47. }
  48. }
  49. func checkActivationcode(c *gin.Context) {
  50. ret := gulu.Ret.NewResult()
  51. defer c.JSON(http.StatusOK, ret)
  52. arg, ok := util.JsonArg(c, ret)
  53. if !ok {
  54. return
  55. }
  56. code := arg["data"].(string)
  57. ret.Code, ret.Msg = model.CheckActivationcode(code)
  58. }
  59. func deactivateUser(c *gin.Context) {
  60. ret := gulu.Ret.NewResult()
  61. defer c.JSON(http.StatusOK, ret)
  62. err := model.DeactivateUser()
  63. if nil != err {
  64. ret.Code = -1
  65. ret.Msg = err.Error()
  66. return
  67. }
  68. }
  69. func login(c *gin.Context) {
  70. ret := gulu.Ret.NewResult()
  71. arg, ok := util.JsonArg(c, ret)
  72. if !ok {
  73. c.JSON(http.StatusOK, ret)
  74. return
  75. }
  76. name := arg["userName"].(string)
  77. password := arg["userPassword"].(string)
  78. captcha := arg["captcha"].(string)
  79. cloudRegion := int(arg["cloudRegion"].(float64))
  80. ret = model.Login(name, password, captcha, cloudRegion)
  81. c.JSON(http.StatusOK, ret)
  82. }