applications.py 6.7 KB

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