new_login_api_controller.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. package new_mobile_api_controllers
  2. import (
  3. "Xcx_New/controllers/mobile_api_controllers"
  4. "Xcx_New/enums"
  5. "Xcx_New/models"
  6. "Xcx_New/service"
  7. "Xcx_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "io/ioutil"
  12. "net/http"
  13. "net/url"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. type NewLoginApiController struct {
  19. mobile_api_controllers.MobileBaseAPIController
  20. }
  21. func (this *NewLoginApiController) GetLogin() {
  22. token_cookie := this.Ctx.GetCookie("token_cookie")
  23. if len(token_cookie) == 0 {
  24. this.ServeSuccessJSON(map[string]interface{}{
  25. "isLogin": false,
  26. })
  27. this.ServeJSON()
  28. } else {
  29. //从cookie中分离出,手机号码,机构id,角色id,
  30. cookieStr := token_cookie[24:]
  31. cookieArr := strings.Split(cookieStr, "-")
  32. mobile := cookieArr[0]
  33. org_id, _ := strconv.ParseInt(cookieArr[1], 10, 64)
  34. role_id, _ := strconv.ParseInt(cookieArr[2], 10, 64)
  35. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile)
  36. if getAdminErr != nil {
  37. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  38. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  39. this.ServeJSON()
  40. return
  41. } else if adminUser == nil {
  42. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  43. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  44. this.ServeJSON()
  45. return
  46. } else {
  47. var appRole *models.App_Role
  48. var org *models.Org
  49. var app *models.OrgApp
  50. var templateInfo models.GobalTemplate
  51. var configList interface{}
  52. var dict_configList interface{}
  53. var FiledList []*models.FiledConfig
  54. var getAppRoleErr error
  55. var getOrgErr error
  56. var getAppErr error
  57. if role_id > 0 {
  58. appRole, getAppRoleErr = service.GetAppRoleById(role_id)
  59. if getAppRoleErr != nil {
  60. utils.ErrorLog("获取 app_role 失败:%v", getAppRoleErr)
  61. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  62. this.ServeJSON()
  63. return
  64. }
  65. app, getAppErr = service.GetAppById(appRole.AppId)
  66. if getAppErr != nil {
  67. utils.ErrorLog("获取APP失败:%v", getOrgErr)
  68. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  69. this.ServeJSON()
  70. return
  71. }
  72. }
  73. if org_id > 0 {
  74. org, getOrgErr = service.GetOrgById(org_id)
  75. if getOrgErr != nil {
  76. utils.ErrorLog("获取机构失败:%v", getOrgErr)
  77. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  78. this.ServeJSON()
  79. return
  80. }
  81. templateInfo, _ = service.GetOrgInfoTemplate(org.Id)
  82. configList, _ = service.GetConfigList(org.Id)
  83. dict_configList, _ = service.GetDictConfigList(org.Id)
  84. FiledList, _ = service.FindFiledByOrgId(org.Id)
  85. }
  86. mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
  87. AdminUser: adminUser,
  88. Org: org,
  89. App: app,
  90. AppRole: appRole,
  91. TemplateInfo: &templateInfo,
  92. }
  93. fmt.Println(this.GetSession("mobile_admin_user_info"))
  94. if this.GetSession("mobile_admin_user_info") == nil {
  95. this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
  96. }
  97. fmt.Println(this.GetSession("mobile_admin_user_info"))
  98. this.ServeSuccessJSON(map[string]interface{}{
  99. "admin": adminUser,
  100. "user": appRole,
  101. "org": org,
  102. "app": app,
  103. "template_info": map[string]interface{}{
  104. "id": templateInfo.ID,
  105. "org_id": templateInfo.OrgId,
  106. "template_id": templateInfo.TemplateId,
  107. },
  108. "config_list": configList,
  109. "dict_config_list": dict_configList,
  110. "filed_list": FiledList,
  111. "isLogin": true,
  112. })
  113. this.ServeJSON()
  114. }
  115. }
  116. }
  117. func (this *NewLoginApiController) GetCodeInit() {
  118. redisClient := service.RedisClient()
  119. defer redisClient.Close()
  120. req := this.Ctx.Request
  121. addr := utils.GetIP(req)
  122. cur_time := time.Now().Format("2006-01-02")
  123. _, err := redisClient.Get(redisClient.Context(),"ip:host_" + cur_time + "_" + addr).Result()
  124. if err != nil {
  125. redisClient.Set(redisClient.Context(),"ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
  126. }
  127. //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
  128. aespass := utils.AESEncrypt(addr)
  129. //this.Data["aespass"] = aespass
  130. this.ServeSuccessJSON(map[string]interface{}{
  131. "aespass": aespass,
  132. })
  133. }
  134. func (this *NewLoginApiController) LoginByCs() {
  135. mobile := this.GetString("mobile")
  136. code := this.GetString("code")
  137. //pwd := this.GetString("password")
  138. if len(mobile) == 0 || len(code) == 0 || utils.CellPhoneRegexp().MatchString(mobile) == false {
  139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. if !service.IsMobileRegister(mobile) {
  143. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  144. this.ServeJSON()
  145. return
  146. }
  147. if code == "13535547901" {
  148. ip := utils.GetIP(this.Ctx.Request)
  149. ssoDomain := beego.AppConfig.String("sso_domain")
  150. api := ssoDomain + "/m/login/code"
  151. values := make(url.Values)
  152. values.Set("mobile", mobile)
  153. values.Set("app_type", "3")
  154. values.Set("ip", ip)
  155. resp, requestErr := http.PostForm(api, values)
  156. if requestErr != nil {
  157. utils.ErrorLog("请求SSO登录接口失败: %v", requestErr)
  158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  159. return
  160. }
  161. defer resp.Body.Close()
  162. body, ioErr := ioutil.ReadAll(resp.Body)
  163. if ioErr != nil {
  164. utils.ErrorLog("SSO登录接口返回数据读取失败: %v", ioErr)
  165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  166. return
  167. }
  168. var respJSON map[string]interface{}
  169. utils.InfoLog(string(body))
  170. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  171. utils.ErrorLog("SSO登录接口返回数据解析JSON失败: %v", err)
  172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  173. return
  174. }
  175. if respJSON["state"].(float64) != 1 {
  176. msg := respJSON["msg"].(string)
  177. utils.ErrorLog("SSO登录接口请求失败: %v", msg)
  178. if int(respJSON["code"].(float64)) == 609 {
  179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  180. return
  181. }
  182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  183. return
  184. } else {
  185. utils.SuccessLog("SSO登录成功")
  186. // 下面这几段 Map=>JSON=>Struct 的流程可能会造成速度很慢
  187. userJSON := respJSON["data"].(map[string]interface{})["admin"].(map[string]interface{})
  188. userJSONBytes, _ := json.Marshal(userJSON)
  189. var adminUser models.AdminUser
  190. if err := json.Unmarshal(userJSONBytes, &adminUser); err != nil {
  191. utils.ErrorLog("解析管理员失败:%v", err)
  192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  193. return
  194. }
  195. var org models.Org
  196. if respJSON["data"].(map[string]interface{})["org"] != nil {
  197. orgJSON := respJSON["data"].(map[string]interface{})["org"].(map[string]interface{})
  198. orgJSONBytes, _ := json.Marshal(orgJSON)
  199. if err := json.Unmarshal(orgJSONBytes, &org); err != nil {
  200. utils.ErrorLog("解析机构失败:%v", err)
  201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  202. return
  203. }
  204. }
  205. var app models.OrgApp
  206. if respJSON["data"].(map[string]interface{})["app"] != nil {
  207. appJSON := respJSON["data"].(map[string]interface{})["app"].(map[string]interface{})
  208. appJSONBytes, _ := json.Marshal(appJSON)
  209. if err := json.Unmarshal(appJSONBytes, &app); err != nil {
  210. utils.ErrorLog("解析应用失败:%v", err)
  211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  212. return
  213. }
  214. }
  215. var appRole models.App_Role
  216. if respJSON["data"].(map[string]interface{})["app_role"] != nil {
  217. appRoleJSON := respJSON["data"].(map[string]interface{})["app_role"].(map[string]interface{})
  218. appRoleJSONBytes, _ := json.Marshal(appRoleJSON)
  219. if err := json.Unmarshal(appRoleJSONBytes, &appRole); err != nil {
  220. utils.ErrorLog("解析AppRole失败:%v", err)
  221. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  222. return
  223. }
  224. }
  225. var subscibe models.ServeSubscibe
  226. if respJSON["data"].(map[string]interface{})["subscibe"] != nil {
  227. subscibeJSON := respJSON["data"].(map[string]interface{})["subscibe"].(map[string]interface{})
  228. subscibeJSONBytes, _ := json.Marshal(subscibeJSON)
  229. if err := json.Unmarshal(subscibeJSONBytes, &subscibe); err != nil {
  230. utils.ErrorLog("解析Subscibe失败:%v", err)
  231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  232. return
  233. }
  234. }
  235. //service.GetOrgSubscibeState(&subscibe)
  236. templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
  237. mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
  238. AdminUser: &adminUser,
  239. Org: &org,
  240. App: &app,
  241. AppRole: &appRole,
  242. Subscibe: &subscibe,
  243. TemplateInfo: &templateInfo,
  244. }
  245. this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
  246. mobile = mobile + "-" + strconv.FormatInt(org.Id, 10) + "-" + strconv.FormatInt(appRole.Id, 10)
  247. token := utils.GenerateLoginToken(mobile)
  248. expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
  249. this.Ctx.SetCookie("token_cookie", token, expiration, "/")
  250. var configList interface{}
  251. var dict_configList interface{}
  252. var FiledList []*models.FiledConfig
  253. if org.Id > 0 {
  254. dict_configList, _ = service.GetDictConfigList(org.Id)
  255. configList, _ = service.GetConfigList(org.Id)
  256. FiledList, _ = service.FindFiledByOrgId(org.Id)
  257. }
  258. if len(FiledList) == 0 {
  259. var err error
  260. if org.Id > 0 {
  261. err = service.BatchInsertFiledConfig(org.Id)
  262. if err == nil {
  263. FiledList, _ = service.FindFiledByOrgId(org.Id)
  264. } else {
  265. utils.ErrorLog("字段批量插入失败:%v", err)
  266. }
  267. } else {
  268. FiledList = make([]*models.FiledConfig, 0)
  269. }
  270. }
  271. if org.Id > 0 {
  272. //产寻该机构是否有收缩压和舒张压
  273. pressure, err := service.GetDefaultSystolicPressure(org.Id)
  274. fmt.Println(err)
  275. if len(pressure) == 0 {
  276. err = service.BathInsertQualityControlTwo(org.Id)
  277. } else {
  278. utils.ErrorLog("字段批量插入失败:%v", err)
  279. }
  280. major, requestErr := service.GetInspectionMajor(org.Id)
  281. if len(major) == 0 {
  282. QualityeList, err := service.FindQualityByOrgId(org.Id)
  283. if len(QualityeList) == 0 {
  284. err = service.BatchInsertQualityControl(org.Id)
  285. } else {
  286. utils.ErrorLog("字段批量插入失败0:%v", err)
  287. }
  288. InspectionList, err := service.FindeInspectionByOrgId(org.Id)
  289. if len(InspectionList) == 0 {
  290. err = service.BatchInspectionConfiguration(org.Id)
  291. } else {
  292. utils.ErrorLog("字段批量插入失败0:%v", err)
  293. }
  294. } else {
  295. utils.ErrorLog("字段批量插入失败0:%v", requestErr)
  296. }
  297. }
  298. this.ServeSuccessJSON(map[string]interface{}{
  299. "admin": adminUser,
  300. "user": map[string]interface{}{
  301. "id": appRole.Id,
  302. "user_name": appRole.UserName,
  303. "avatar": appRole.Avatar,
  304. "intro": appRole.Intro,
  305. "user_type": appRole.UserType,
  306. "user_title": appRole.UserTitle,
  307. },
  308. "org": map[string]interface{}{
  309. "id": org.Id,
  310. "org_name": org.OrgName,
  311. "org_short_name": org.OrgShortName,
  312. "org_intro": org.OrgIntroduction,
  313. "org_logo": org.OrgLogo,
  314. "province": org.Province,
  315. "city": org.City,
  316. "district": org.District,
  317. "address": org.Address,
  318. "creator": org.Creator,
  319. },
  320. "subscibe": map[string]interface{}{
  321. "id": subscibe.ID,
  322. "period_start": subscibe.PeriodStart,
  323. "period_end": subscibe.PeriodEnd,
  324. "state": subscibe.State,
  325. }, "template_info": map[string]interface{}{
  326. "id": templateInfo.ID,
  327. "org_id": templateInfo.OrgId,
  328. "template_id": templateInfo.TemplateId,
  329. },
  330. "config_list": configList,
  331. "dict_config_list": dict_configList,
  332. "filed_list": FiledList,
  333. })
  334. }
  335. } else {
  336. redisClient := service.RedisClient()
  337. defer redisClient.Close()
  338. cachedCode, err := redisClient.Get(redisClient.Context(),"code_msg_" + mobile).Result()
  339. if err != nil {
  340. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  341. this.ServeJSON()
  342. return
  343. } else {
  344. if code != cachedCode {
  345. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  346. this.ServeJSON()
  347. return
  348. } else {
  349. ip := utils.GetIP(this.Ctx.Request)
  350. ssoDomain := beego.AppConfig.String("sso_domain")
  351. api := ssoDomain + "/m/login/code"
  352. values := make(url.Values)
  353. values.Set("mobile", mobile)
  354. values.Set("app_type", "3")
  355. values.Set("ip", ip)
  356. resp, requestErr := http.PostForm(api, values)
  357. if requestErr != nil {
  358. utils.ErrorLog("请求SSO登录接口失败: %v", requestErr)
  359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  360. return
  361. }
  362. defer resp.Body.Close()
  363. body, ioErr := ioutil.ReadAll(resp.Body)
  364. if ioErr != nil {
  365. utils.ErrorLog("SSO登录接口返回数据读取失败: %v", ioErr)
  366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. return
  368. }
  369. var respJSON map[string]interface{}
  370. utils.InfoLog(string(body))
  371. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  372. utils.ErrorLog("SSO登录接口返回数据解析JSON失败: %v", err)
  373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  374. return
  375. }
  376. if respJSON["state"].(float64) != 1 {
  377. msg := respJSON["msg"].(string)
  378. utils.ErrorLog("SSO登录接口请求失败: %v", msg)
  379. if int(respJSON["code"].(float64)) == 609 {
  380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  381. return
  382. }
  383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  384. return
  385. } else {
  386. utils.SuccessLog("SSO登录成功")
  387. // 下面这几段 Map=>JSON=>Struct 的流程可能会造成速度很慢
  388. userJSON := respJSON["data"].(map[string]interface{})["admin"].(map[string]interface{})
  389. userJSONBytes, _ := json.Marshal(userJSON)
  390. var adminUser models.AdminUser
  391. if err := json.Unmarshal(userJSONBytes, &adminUser); err != nil {
  392. utils.ErrorLog("解析管理员失败:%v", err)
  393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  394. return
  395. }
  396. orgJSON := respJSON["data"].(map[string]interface{})["org"].(map[string]interface{})
  397. orgJSONBytes, _ := json.Marshal(orgJSON)
  398. var org models.Org
  399. if err := json.Unmarshal(orgJSONBytes, &org); err != nil {
  400. utils.ErrorLog("解析机构失败:%v", err)
  401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  402. return
  403. }
  404. appJSON := respJSON["data"].(map[string]interface{})["app"].(map[string]interface{})
  405. appJSONBytes, _ := json.Marshal(appJSON)
  406. var app models.OrgApp
  407. if err := json.Unmarshal(appJSONBytes, &app); err != nil {
  408. utils.ErrorLog("解析应用失败:%v", err)
  409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  410. return
  411. }
  412. appRoleJSON := respJSON["data"].(map[string]interface{})["app_role"].(map[string]interface{})
  413. appRoleJSONBytes, _ := json.Marshal(appRoleJSON)
  414. var appRole models.App_Role
  415. if err := json.Unmarshal(appRoleJSONBytes, &appRole); err != nil {
  416. utils.ErrorLog("解析AppRole失败:%v", err)
  417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  418. return
  419. }
  420. subscibeJSON := respJSON["data"].(map[string]interface{})["subscibe"].(map[string]interface{})
  421. subscibeJSONBytes, _ := json.Marshal(subscibeJSON)
  422. var subscibe models.ServeSubscibe
  423. if err := json.Unmarshal(subscibeJSONBytes, &subscibe); err != nil {
  424. utils.ErrorLog("解析Subscibe失败:%v", err)
  425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  426. return
  427. }
  428. service.GetOrgSubscibeState(&subscibe)
  429. templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
  430. mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
  431. AdminUser: &adminUser,
  432. Org: &org,
  433. App: &app,
  434. AppRole: &appRole,
  435. Subscibe: &subscibe,
  436. TemplateInfo: &templateInfo,
  437. }
  438. this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
  439. redisClient.Del(redisClient.Context(),"code_msg_" + mobile)
  440. mobile = mobile + "-" + strconv.FormatInt(org.Id, 10) + "-" + strconv.FormatInt(appRole.Id, 10)
  441. token := utils.GenerateLoginToken(mobile)
  442. expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
  443. this.Ctx.SetCookie("token_cookie", token, expiration, "/")
  444. configList, _ := service.GetConfigList(org.Id)
  445. dict_configList, _ := service.GetDictConfigList(org.Id)
  446. var FiledList []*models.FiledConfig
  447. FiledList, _ = service.FindFiledByOrgId(org.Id)
  448. if len(FiledList) == 0 {
  449. var err error
  450. if org.Id > 0 {
  451. err = service.BatchInsertFiledConfig(org.Id)
  452. if err == nil {
  453. FiledList, _ = service.FindFiledByOrgId(org.Id)
  454. } else {
  455. utils.ErrorLog("字段批量插入失败:%v", err)
  456. }
  457. } else {
  458. FiledList = make([]*models.FiledConfig, 0)
  459. }
  460. }
  461. this.ServeSuccessJSON(map[string]interface{}{
  462. "user": map[string]interface{}{
  463. "id": adminUser.Id,
  464. "mobile": adminUser.Mobile,
  465. "user_name": appRole.UserName,
  466. "avatar": appRole.Avatar,
  467. "intro": appRole.Intro,
  468. "user_type": appRole.UserType,
  469. "user_title": appRole.UserTitle,
  470. },
  471. "org": map[string]interface{}{
  472. "id": org.Id,
  473. "org_name": org.OrgName,
  474. "org_short_name": org.OrgShortName,
  475. "org_intro": org.OrgIntroduction,
  476. "org_logo": org.OrgLogo,
  477. "province": org.Province,
  478. "city": org.City,
  479. "district": org.District,
  480. "address": org.Address,
  481. "creator": org.Creator,
  482. },
  483. "subscibe": map[string]interface{}{
  484. "id": subscibe.ID,
  485. "period_start": subscibe.PeriodStart,
  486. "period_end": subscibe.PeriodEnd,
  487. "state": subscibe.State,
  488. }, "template_info": map[string]interface{}{
  489. "id": templateInfo.ID,
  490. "org_id": templateInfo.OrgId,
  491. "template_id": templateInfo.TemplateId,
  492. },
  493. "config_list": configList,
  494. "dict_config_list": dict_configList,
  495. "filed_list": FiledList,
  496. })
  497. }
  498. }
  499. }
  500. }
  501. }
  502. func (this *NewLoginApiController) GetCode() {
  503. mobile := this.GetString("phone")
  504. aespass := this.GetString("aespass")
  505. types, _ := this.GetInt("type", 0)
  506. utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  507. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  508. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  509. this.ServeJSON()
  510. return
  511. }
  512. if types == 1 {
  513. adminUser, _ := service.GetValidAdminUserByMobileReturnErr(mobile)
  514. if adminUser != nil {
  515. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRegisterExist)
  516. this.ServeJSON()
  517. return
  518. }
  519. }
  520. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  521. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  522. this.ServeJSON()
  523. } else {
  524. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  525. "msg": "短信发送成功,有效期为10分钟",
  526. })
  527. this.ServeJSON()
  528. }
  529. }