recent_app_submit.py 5.5 KB

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