recent_app_submit.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. from .tool.func import *
  2. def recent_app_submit_2():
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. div = ''
  6. curs.execute(db_change('select data from other where name = "requires_approval"'))
  7. requires_approval = curs.fetchall()
  8. if requires_approval and requires_approval[0][0] != 'on':
  9. div += load_lang('approval_requirement_disabled')
  10. if flask.request.method == 'GET':
  11. curs.execute(db_change(
  12. 'select data from user_set where name = "application"'
  13. ))
  14. db_data = curs.fetchall()
  15. if db_data:
  16. div += '' + \
  17. load_lang('all_register_num') + ' : ' + str(len(db_data)) + \
  18. '<hr class="main_hr">' + \
  19. ''
  20. div += '''
  21. <table id="main_table_set">
  22. <tr id="main_table_top_tr">
  23. <td id="main_table_width_half">''' + load_lang('id') + '''</td>
  24. <td id="main_table_width_half">''' + load_lang('email') + '''</td>
  25. </tr>
  26. <tr id="main_table_top_tr">
  27. <td>''' + load_lang('approval_question') + '''</td>
  28. <td>''' + load_lang('answer') + '''</td>
  29. </tr>
  30. '''
  31. for application in db_data:
  32. application = json.loads(application[0])
  33. if 'question' in application:
  34. question = html.escape(application['question'])
  35. question = question if question != '' else '<br>'
  36. else:
  37. question = '<br>'
  38. if 'answer' in application:
  39. answer = html.escape(application['answer'])
  40. answer = answer if answer != '' else '<br>'
  41. else:
  42. answer = '<br>'
  43. if 'email' in application:
  44. email = html.escape(application['email'])
  45. email = email if email != '' else '<br>'
  46. else:
  47. email = '<br>'
  48. div += '''
  49. <form method="post">
  50. <tr>
  51. <td>''' + application['id'] + '''</td>
  52. <td>''' + email + '''</td>
  53. </tr>
  54. <tr>
  55. <td>''' + question + '''</td>
  56. <td>''' + answer + '''</td>
  57. </tr>
  58. <tr>
  59. <td colspan="3">
  60. <button type="submit"
  61. id="opennamu_js_save"
  62. name="approve"
  63. value="''' + application['id'] + '''">
  64. ''' + load_lang('approve') + '''
  65. </button>
  66. <button type="submit"
  67. name="decline"
  68. value="''' + application['id'] + '''">
  69. ''' + load_lang('decline') + '''
  70. </button>
  71. </td>
  72. </tr>
  73. </form>
  74. '''
  75. div += '</table>'
  76. else:
  77. div += load_lang('no_applications_now')
  78. return easy_minify(flask.render_template(skin_check(),
  79. imp = [load_lang('application_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  80. data = div,
  81. menu = [['other', load_lang('return')]]
  82. ))
  83. else:
  84. if admin_check(None, 'app submit') != 1:
  85. return re_error('/ban')
  86. if flask.request.form.get('approve', '') != '':
  87. curs.execute(db_change(
  88. 'select data from user_set where id = ? and name = "application"'
  89. ), [
  90. flask.request.form.get('approve', '')
  91. ])
  92. application = curs.fetchall()
  93. if not application:
  94. return re_error('/error/26')
  95. else:
  96. application = json.loads(application[0][0])
  97. add_user(
  98. application['id'],
  99. application['pw'],
  100. application['email'],
  101. application['encode']
  102. )
  103. curs.execute(db_change(
  104. "insert into user_set (name, id, data) values ('approval_question', ?, ?)"
  105. ), [
  106. application['id'],
  107. application['question']
  108. ])
  109. curs.execute(db_change(
  110. "insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"
  111. ), [
  112. application['id'],
  113. application['answer']
  114. ])
  115. curs.execute(db_change(
  116. 'delete from user_set where id = ? and name = "application"'
  117. ), [
  118. application['id']
  119. ])
  120. conn.commit()
  121. elif flask.request.form.get('decline', '') != '':
  122. curs.execute(db_change(
  123. 'delete from user_set where id = ? and name = "application"'
  124. ), [
  125. flask.request.form.get('decline', '')
  126. ])
  127. conn.commit()
  128. return redirect('/app_submit')