2
0

applications.py 6.7 KB

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