views.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. import json
  2. import jwt
  3. from django.shortcuts import redirect
  4. from django.utils.decorators import method_decorator
  5. from django.views import View
  6. from django.contrib.auth import authenticate, login, logout
  7. from django.contrib.auth.decorators import login_required
  8. from service.account.account_base_service import account_base_service_ins
  9. from service.format_response import api_response
  10. from apps.loon_base_view import LoonBaseView
  11. from schema import Schema, Regex, And, Or, Use, Optional
  12. from service.permission.manage_permission import manage_permission_check
  13. @method_decorator(login_required, name='dispatch')
  14. class LoonUserView(LoonBaseView):
  15. post_schema = Schema({
  16. 'username': And(str, lambda n: n != '', error='username is needed'),
  17. 'alias': And(str, lambda n: n != '', error='alias is needed'),
  18. 'email': And(str, lambda n: n != '', error='alias is needed'),
  19. Optional('password'): str,
  20. 'phone': str,
  21. 'dept_ids': str,
  22. 'type_id': int,
  23. 'is_active': Use(bool),
  24. })
  25. @manage_permission_check('workflow_admin')
  26. def get(self, request, *args, **kwargs):
  27. """
  28. 获取用户列表
  29. :param request:
  30. :param args:
  31. :param kwargs:
  32. :return:
  33. """
  34. request_data = request.GET
  35. search_value = request_data.get('search_value', '')
  36. per_page = int(request_data.get('per_page', 10))
  37. page = int(request_data.get('page', 1))
  38. flag, result = account_base_service_ins.get_user_list(search_value, page, per_page)
  39. if flag is not False:
  40. data = dict(value=result.get('user_result_object_format_list'),
  41. per_page=result.get('paginator_info').get('per_page'),
  42. page=result.get('paginator_info').get('page'),
  43. total=result.get('paginator_info').get('total'))
  44. code, msg, = 0, ''
  45. else:
  46. code, data, msg = -1, '', result
  47. return api_response(code, msg, data)
  48. @manage_permission_check('admin')
  49. def post(self, request, *args, **kwargs):
  50. """
  51. add user
  52. :param request:
  53. :param args:
  54. :param kwargs:
  55. :return:
  56. """
  57. json_str = request.body.decode('utf-8')
  58. if not json_str:
  59. return api_response(-1, 'post参数为空', {})
  60. request_data_dict = json.loads(json_str)
  61. username = request_data_dict.get('username')
  62. alias = request_data_dict.get('alias')
  63. email = request_data_dict.get('email')
  64. password = request_data_dict.get('password')
  65. phone = request_data_dict.get('phone')
  66. dept_ids = request_data_dict.get('dept_ids')
  67. is_active = request_data_dict.get('is_active')
  68. type_id = request_data_dict.get('type_id')
  69. creator = request.user.username
  70. flag, result = account_base_service_ins.add_user(username, alias, email, phone, dept_ids, is_active, type_id, creator, password)
  71. if flag is False:
  72. code, msg, data = -1, result, {}
  73. else:
  74. code, msg, data = 0, '', result
  75. return api_response(code, msg, data)
  76. @method_decorator(login_required, name='dispatch')
  77. class LoonUserDetailView(LoonBaseView):
  78. patch_schema = Schema({
  79. 'username': And(str, lambda n: n != ''),
  80. 'alias': And(str, lambda n: n != ''),
  81. 'email': And(str, lambda n: n != ''),
  82. Optional('password'): str,
  83. 'phone': str,
  84. 'dept_ids': str,
  85. 'is_active': Use(bool),
  86. 'type_id': int
  87. })
  88. @manage_permission_check('admin')
  89. def patch(self, request, *args, **kwargs):
  90. """
  91. edit user
  92. :param request:
  93. :param args:
  94. :param kwargs:
  95. :return:
  96. """
  97. json_str = request.body.decode('utf-8')
  98. user_id = kwargs.get('user_id')
  99. request_data_dict = json.loads(json_str)
  100. username = request_data_dict.get('username')
  101. alias = request_data_dict.get('alias')
  102. email = request_data_dict.get('email')
  103. phone = request_data_dict.get('phone')
  104. dept_ids = request_data_dict.get('dept_ids')
  105. type_id = request_data_dict.get('type_id')
  106. is_active = request_data_dict.get('is_active')
  107. flag, result = account_base_service_ins.edit_user(user_id, username, alias, email, phone, dept_ids, is_active,
  108. type_id)
  109. if flag is not False:
  110. code, msg, data = 0, '', {}
  111. else:
  112. code, msg, data = -1, result, {}
  113. return api_response(code, msg, data)
  114. @manage_permission_check('admin')
  115. def delete(self, request, *args, **kwargs):
  116. """
  117. delete user record
  118. :param request:
  119. :param args:
  120. :param kwargs:
  121. :return:
  122. """
  123. user_id = kwargs.get('user_id')
  124. flag, result = account_base_service_ins.delete_user(user_id)
  125. if flag:
  126. code, msg, data = 0, '', {}
  127. return api_response(code, msg, data)
  128. code, msg, data = -1, result, {}
  129. return api_response(code, msg, data)
  130. @method_decorator(login_required, name='dispatch')
  131. class LoonRoleView(LoonBaseView):
  132. post_schema = Schema({
  133. 'name': And(str, lambda n: n != ''),
  134. Optional('description'): str,
  135. Optional('label'): str,
  136. })
  137. @manage_permission_check('admin')
  138. def get(self, request, *args, **kwargs):
  139. """
  140. 用户角色列表
  141. :param request:
  142. :param args:
  143. :param kwargs:
  144. :return:
  145. """
  146. request_data = request.GET
  147. search_value = request_data.get('search_value', '')
  148. per_page = int(request_data.get('per_page', 10))
  149. page = int(request_data.get('page', 1))
  150. flag, result = account_base_service_ins.get_role_list(search_value, page, per_page)
  151. if flag is not False:
  152. data = dict(value=result.get('role_result_object_format_list'),
  153. per_page=result.get('paginator_info').get('per_page'),
  154. page=result.get('paginator_info').get('page'),
  155. total=result.get('paginator_info').get('total'))
  156. code, msg, = 0, ''
  157. else:
  158. code, data = -1, ''
  159. return api_response(code, msg, data)
  160. @manage_permission_check('admin')
  161. def post(self, request, *args, **kwargs):
  162. """
  163. add role
  164. 新增角色
  165. :param request:
  166. :param args:
  167. :param kwargs:
  168. :return:
  169. """
  170. json_str = request.body.decode('utf-8')
  171. request_data_dict = json.loads(json_str)
  172. name = request_data_dict.get('name')
  173. description = request_data_dict.get('description', '')
  174. label = request_data_dict.get('label', '')
  175. creator = request.user.username
  176. flag, result = account_base_service_ins.add_role(name=name, description=description, label=label,
  177. creator=creator)
  178. if flag is False:
  179. return api_response(-1, result, {})
  180. return api_response(0, result, {})
  181. @method_decorator(login_required, name='dispatch')
  182. class LoonRoleDetailView(LoonBaseView):
  183. patch_schema = Schema({
  184. 'name': And(str, lambda n: n != '', error='name is need'),
  185. Optional('description'): str,
  186. Optional('label'): str,
  187. })
  188. @manage_permission_check('admin')
  189. def patch(self, request, *args, **kwargs):
  190. """
  191. update role
  192. 更新角色信息
  193. :param request:
  194. :param args:
  195. :param kwargs:
  196. :return:
  197. """
  198. role_id = kwargs.get('role_id')
  199. json_str = request.body.decode('utf-8')
  200. request_data_dict = json.loads(json_str)
  201. name = request_data_dict.get('name')
  202. description = request_data_dict.get('description')
  203. label = request_data_dict.get('label')
  204. flag, result = account_base_service_ins.update_role(role_id, name, description, label)
  205. if flag is False:
  206. return api_response(-1, result, {})
  207. return api_response(0, '', {})
  208. @manage_permission_check('admin')
  209. def delete(self, request, *args, **kwargs):
  210. """
  211. delete role
  212. :param request:
  213. :param args:
  214. :param kwargs:
  215. :return:
  216. """
  217. role_id = kwargs.get('role_id')
  218. flag, result = account_base_service_ins.delete_role(role_id)
  219. if flag is False:
  220. return api_response(-1, result, {})
  221. return api_response(0, '', {})
  222. @method_decorator(login_required, name='dispatch')
  223. class LoonDeptView(LoonBaseView):
  224. post_schema = Schema({
  225. 'name': And(str, lambda n: n != ''),
  226. Optional('parent_dept_id'): int,
  227. Optional('leader'): str,
  228. Optional('approver'): str,
  229. Optional('label'): str,
  230. })
  231. @manage_permission_check('admin')
  232. def get(self, request, *args, **kwargs):
  233. """
  234. 部门列表
  235. :param request:
  236. :param args:
  237. :param kwargs:
  238. :return:
  239. """
  240. request_data = request.GET
  241. search_value = request_data.get('search_value', '')
  242. per_page = int(request_data.get('per_page', 10))
  243. page = int(request_data.get('page', 1))
  244. flag, result = account_base_service_ins.get_dept_list(search_value, page, per_page)
  245. if flag is not False:
  246. paginator_info = result.get('paginator_info')
  247. data = dict(value=result.get('dept_result_object_format_list'), per_page=paginator_info.get('per_page'),
  248. page=paginator_info.get('page'), total=paginator_info.get('total'))
  249. code, msg, = 0, ''
  250. else:
  251. code, data = -1, ''
  252. return api_response(code, msg, data)
  253. @manage_permission_check('admin')
  254. def post(self, request, *args, **kwargs):
  255. """
  256. 新增部门
  257. :param request:
  258. :param args:
  259. :param kwargs:
  260. :return:
  261. """
  262. json_str = request.body.decode('utf-8')
  263. request_data_dict = json.loads(json_str)
  264. name = request_data_dict.get('name')
  265. parent_dept_id = request_data_dict.get('parent_dept_id')
  266. leader = request_data_dict.get('leader')
  267. approver = request_data_dict.get('approver')
  268. label = request_data_dict.get('label')
  269. creator = request.user.username
  270. flag, result = account_base_service_ins.add_dept(name, parent_dept_id, leader, approver, label, creator)
  271. if flag is False:
  272. return api_response(-1, result, {})
  273. return api_response(0, result, {})
  274. @method_decorator(login_required, name='dispatch')
  275. class LoonDeptDetailView(LoonBaseView):
  276. patch_schema = Schema({
  277. 'name': And(str, lambda n: n != '', error='name is need'),
  278. Optional('parent_dept_id'): int,
  279. Optional('leader'): str,
  280. Optional('approver'): str,
  281. Optional('label'): str,
  282. })
  283. @manage_permission_check('admin')
  284. def delete(self, request, *args, **kwargs):
  285. """
  286. delete dept
  287. 删除部门
  288. :param request:
  289. :param args:
  290. :param kwargs:
  291. :return:
  292. """
  293. operator = request.user.username
  294. dept_id = kwargs.get('dept_id')
  295. flag, result = account_base_service_ins.delete_dept(dept_id)
  296. if flag is False:
  297. return api_response(-1, result, {})
  298. return api_response(0, '', {})
  299. @manage_permission_check('admin')
  300. def patch(self, request, *args, **kwargs):
  301. """
  302. 更新部门
  303. :param request:
  304. :param args:
  305. :param kwargs:
  306. :return:
  307. """
  308. dept_id = kwargs.get('dept_id')
  309. json_str = request.body.decode('utf-8')
  310. request_data_dict = json.loads(json_str)
  311. name = request_data_dict.get('name')
  312. parent_dept_id = request_data_dict.get('parent_dept_id')
  313. leader = request_data_dict.get('leader')
  314. approver = request_data_dict.get('approver')
  315. label = request_data_dict.get('label')
  316. flag, result = account_base_service_ins.update_dept(dept_id,name, parent_dept_id, leader,
  317. approver, label)
  318. if flag is False:
  319. return api_response(-1, result, {})
  320. return api_response(0, '', {})
  321. class LoonSimpleDeptView(LoonBaseView):
  322. def get(self, request, *args, **kwargs):
  323. """
  324. 部门列表,简单信息
  325. :param request:
  326. :param args:
  327. :param kwargs:
  328. :return:
  329. """
  330. request_data = request.GET
  331. search_value = request_data.get('search_value', '')
  332. per_page = int(request_data.get('per_page', 10))
  333. page = int(request_data.get('page', 1))
  334. flag, result = account_base_service_ins.get_dept_list(search_value, page, per_page, simple=True)
  335. if flag is not False:
  336. paginator_info = result.get('paginator_info')
  337. data = dict(value=result.get('dept_result_object_format_list'), per_page=paginator_info.get('per_page'),
  338. page=paginator_info.get('page'), total=paginator_info.get('total'))
  339. code, msg, = 0, ''
  340. else:
  341. code, data = -1, ''
  342. return api_response(code, msg, data)
  343. @method_decorator(login_required, name='dispatch')
  344. class LoonAppTokenView(LoonBaseView):
  345. post_schema = Schema({
  346. 'app_name': And(str, lambda n: n != '', error='app_name is needed'),
  347. Optional('ticket_sn_prefix'): str,
  348. Optional('workflow_ids'): str,
  349. })
  350. @manage_permission_check('admin')
  351. def get(self, request, *args, **kwargs):
  352. """
  353. call api permission
  354. 调用权限列表
  355. :param request:
  356. :param args:
  357. :param kwargs:
  358. :return:
  359. """
  360. request_data = request.GET
  361. search_value = request_data.get('search_value', '')
  362. per_page = int(request_data.get('per_page', 10))
  363. page = int(request_data.get('page', 1))
  364. flag, result = account_base_service_ins.get_token_list(search_value, page, per_page)
  365. if flag is not False:
  366. paginator_info = result.get('paginator_info')
  367. data = dict(value=result.get('token_result_object_format_list'), per_page=paginator_info.get('per_page'),
  368. page=paginator_info.get('page'), total=paginator_info.get('total'))
  369. code, msg, = 0, ''
  370. else:
  371. code, data, msg = -1, '', result
  372. return api_response(code, msg, data)
  373. @manage_permission_check('admin')
  374. def post(self, request, *args, **kwargs):
  375. """
  376. add call api permission
  377. 新增调用权限记录
  378. :param request:
  379. :param args:
  380. :param kwargs:
  381. :return:
  382. """
  383. json_str = request.body.decode('utf-8')
  384. request_data_dict = json.loads(json_str)
  385. app_name = request_data_dict.get('app_name', '')
  386. ticket_sn_prefix = request_data_dict.get('ticket_sn_prefix', '')
  387. workflow_ids = request_data_dict.get('workflow_ids', '')
  388. username = request.user.username
  389. flag, result = account_base_service_ins.add_token_record(app_name, ticket_sn_prefix, workflow_ids, username)
  390. if flag is False:
  391. code, data = -1, {}
  392. else:
  393. code, data = 0, {'id': result.get('app_token_id')}
  394. return api_response(code, result, data)
  395. @method_decorator(login_required, name='dispatch')
  396. class LoonSimpleAppTokenView(LoonBaseView):
  397. @manage_permission_check('workflow_admin')
  398. def get(self, request, *args, **kwargs):
  399. """
  400. call api permission
  401. 调用权限列表(返回简单数据)
  402. :param request:
  403. :param args:
  404. :param kwargs:
  405. :return:
  406. """
  407. request_data = request.GET
  408. search_value = request_data.get('search_value', '')
  409. per_page = int(request_data.get('per_page', 10))
  410. page = int(request_data.get('page', 1))
  411. flag, result = account_base_service_ins.get_token_list(search_value, page, per_page, simple=True)
  412. if flag is not False:
  413. paginator_info = result.get('paginator_info')
  414. data = dict(value=result.get('token_result_object_format_list'), per_page=paginator_info.get('per_page'),
  415. page=paginator_info.get('page'), total=paginator_info.get('total'))
  416. code, msg, = 0, ''
  417. else:
  418. code, data, msg = -1, '', result
  419. return api_response(code, msg, data)
  420. @method_decorator(login_required, name='dispatch')
  421. class LoonAppTokenDetailView(LoonBaseView):
  422. patch_schema = Schema({
  423. Optional('ticket_sn_prefix'): str,
  424. Optional('workflow_ids'): str,
  425. })
  426. @manage_permission_check('admin')
  427. def patch(self, request, *args, **kwargs):
  428. """
  429. 编辑token
  430. :param request:
  431. :param args:
  432. :param kwargs:
  433. :return:
  434. """
  435. app_token_id = kwargs.get('app_token_id')
  436. json_str = request.body.decode('utf-8')
  437. request_data_dict = json.loads(json_str)
  438. ticket_sn_prefix = request_data_dict.get('ticket_sn_prefix', '')
  439. workflow_ids = request_data_dict.get('workflow_ids', '')
  440. flag, msg = account_base_service_ins.update_token_record(app_token_id, ticket_sn_prefix, workflow_ids)
  441. if flag is False:
  442. code, data = -1, {}
  443. else:
  444. code, data = 0, {}
  445. return api_response(code, msg, data)
  446. @manage_permission_check('admin')
  447. def delete(self, request, *args, **kwargs):
  448. """
  449. 删除记录
  450. :param request:
  451. :param args:
  452. :param kwargs:
  453. :return:
  454. """
  455. app_token_id = kwargs.get('app_token_id')
  456. flag, msg = account_base_service_ins.del_token_record(app_token_id)
  457. if flag is False:
  458. code, data = -1, {}
  459. else:
  460. code, data = 0, {}
  461. return api_response(code, msg, data)
  462. class LoonLoginView(LoonBaseView):
  463. def post(self, request, *args, **kwargs):
  464. """
  465. 登录验证
  466. :param request:
  467. :param args:
  468. :param kwargs:
  469. :return:
  470. """
  471. json_str = request.body.decode('utf-8')
  472. if not json_str:
  473. return api_response(-1, 'patch参数为空', {})
  474. request_data_dict = json.loads(json_str)
  475. username = request_data_dict.get('username', '')
  476. password = request_data_dict.get('password', '')
  477. try:
  478. user = authenticate(username=username, password=password)
  479. except Exception as e:
  480. return api_response(-1, e.__str__(), {})
  481. if user is not None:
  482. login(request, user)
  483. return api_response(0, '', {})
  484. else:
  485. return api_response(-1, 'username or password is invalid', {})
  486. class LoonLogoutView(LoonBaseView):
  487. def get(self, request, *args, **kwargs):
  488. """
  489. 注销
  490. :param request:
  491. :param args:
  492. :param kwargs:
  493. :return:
  494. """
  495. logout(request)
  496. return redirect('/manage')
  497. class LoonJwtLoginView(LoonBaseView):
  498. def post(self, request, *args, **kwargs):
  499. json_str = request.body.decode('utf-8')
  500. if not json_str:
  501. return api_response(-1, 'invalid args', {})
  502. request_data_dict = json.loads(json_str)
  503. username = request_data_dict.get('username', '')
  504. password = request_data_dict.get('password', '')
  505. try:
  506. user = authenticate(username=username, password=password)
  507. except Exception as e:
  508. return api_response(-1, e.__str__(), {})
  509. if user is not None:
  510. # todo: get jwt
  511. flag, jwt_info = account_base_service_ins.get_user_jwt(username)
  512. if flag is False:
  513. return api_response(-1, '', {})
  514. else:
  515. login(request, user)
  516. return api_response(0, '', {'jwt': jwt_info})
  517. else:
  518. return api_response(-1, 'username or password is invalid', {})
  519. @method_decorator(login_required, name='dispatch')
  520. class LoonUserRoleView(LoonBaseView):
  521. @manage_permission_check('admin')
  522. def get(self, request, *args, **kwargs):
  523. """
  524. 用户角色信息
  525. """
  526. user_id = kwargs.get('user_id', 0)
  527. search_value = request.GET.get('search_value', '')
  528. flag, result = account_base_service_ins.get_user_role_info_by_user_id(user_id, search_value)
  529. if flag is not False:
  530. data = dict(value=result.get('role_result_format_list'), per_page=result.get('paginator_info').get('per_page'),
  531. page=result.get('paginator_info').get('page'), total=result.get('paginator_info').get('total'))
  532. code, msg, = 0, ''
  533. else:
  534. code, data = -1, ''
  535. return api_response(code, msg, data)
  536. @method_decorator(login_required, name='dispatch')
  537. class LoonRoleUserView(LoonBaseView):
  538. post_schema = Schema({
  539. 'user_id': And(int, error='user_id is needed and should be int')
  540. })
  541. @manage_permission_check('admin')
  542. def get(self, request, *args, **kwargs):
  543. """
  544. 角色的用户信息
  545. :param request:
  546. :param args:
  547. :param kwargs:
  548. :return:
  549. """
  550. role_id = kwargs.get('role_id', 0)
  551. request_data = request.GET
  552. page = int(request_data.get('page', 1))
  553. per_page = int(request_data.get('per_page', 10))
  554. search_value = request.GET.get('search_value', '')
  555. flag, result = account_base_service_ins.get_role_user_info_by_role_id(role_id, search_value, page, per_page)
  556. if flag is not False:
  557. data = dict(value=result.get('user_result_format_list'), per_page=result.get('paginator_info').get('per_page'),
  558. page=result.get('paginator_info').get('page'), total=result.get('paginator_info').get('total'))
  559. code, msg, = 0, ''
  560. else:
  561. code, data = -1, ''
  562. return api_response(code, msg, data)
  563. @manage_permission_check('admin')
  564. def post(self, request, *args, **kwargs):
  565. """
  566. add role's user
  567. 新增角色用户
  568. :param request:
  569. :param args:
  570. :param kwargs:
  571. :return:
  572. """
  573. role_id = kwargs.get('role_id', 0)
  574. creator = request.user.username
  575. json_str = request.body.decode('utf-8')
  576. request_data_dict = json.loads(json_str)
  577. user_id = request_data_dict.get('user_id', 0)
  578. flag, result = account_base_service_ins.add_role_user(role_id, user_id, creator)
  579. if flag is False:
  580. return api_response(-1, result, {})
  581. return api_response(0, '', {})
  582. @method_decorator(login_required, name='dispatch')
  583. class LoonRoleUserDetailView(LoonBaseView):
  584. @manage_permission_check('admin')
  585. def delete(self, request, *args, **kwargs):
  586. """
  587. delete role's user
  588. 删除角色用户
  589. :param request:
  590. :param args:
  591. :param kwargs:
  592. :return:
  593. """
  594. user_id = kwargs.get('user_id', 0)
  595. flag, result = account_base_service_ins.delete_role_user(user_id)
  596. if flag is False:
  597. return api_response(-1, result, {})
  598. return api_response(0, '', {})
  599. class LoonUserResetPasswordView(LoonBaseView):
  600. @manage_permission_check('admin')
  601. def post(self, request, *args, **kwargs):
  602. """
  603. 重置密码
  604. :param requesdt:
  605. :param args:
  606. :param kwargs:
  607. :return:
  608. """
  609. user_id = kwargs.get('user_id')
  610. flag, result = account_base_service_ins.reset_password(user_id=user_id)
  611. if flag is False:
  612. return api_response(-1, result, {})
  613. return api_response(0, result, {})
  614. class LoonUserChangePasswordView(LoonBaseView):
  615. def post(self, request, *args, **kwargs):
  616. """
  617. 修改密码
  618. :param request:
  619. :param args:
  620. :param kwargs:
  621. :return:
  622. """
  623. username = request.user.username
  624. json_str = request.body.decode('utf-8')
  625. request_data_dict = json.loads(json_str)
  626. new_password = request_data_dict.get('new_password', '')
  627. source_password = request_data_dict.get('source_password', '')
  628. new_password_again = request_data_dict.get('new_password_again', '')
  629. if new_password != new_password_again:
  630. return api_response(-1, '两次密码不一致,请重新输入', {})
  631. flag, result = account_base_service_ins.change_password(username, source_password, new_password)
  632. if flag is False:
  633. return api_response(-1, result, {})
  634. return api_response(0, result, {})
  635. class LoonSimpleUserView(LoonBaseView):
  636. def get(self, request, *args, **kwargs):
  637. """
  638. 获取用户简要信息列表
  639. :param request:
  640. :param args:
  641. :param kwargs:
  642. :return:
  643. """
  644. request_data = request.GET
  645. search_value = request_data.get('search_value', '')
  646. per_page = int(request_data.get('per_page', 10))
  647. page = int(request_data.get('page', 1))
  648. flag, result = account_base_service_ins.get_user_list(search_value, page, per_page, simple=True)
  649. if flag is not False:
  650. data = dict(value=result.get('user_result_object_format_list'),
  651. per_page=result.get('paginator_info').get('per_page'),
  652. page=result.get('paginator_info').get('page'),
  653. total=result.get('paginator_info').get('total'))
  654. code, msg, = 0, ''
  655. else:
  656. code, data, msg = -1, '', result
  657. return api_response(code, msg, data)