applications.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 += '<p>' + load_lang('approval_requirement_disabled') + '</p>'
  11. if flask.request.method == 'GET':
  12. curs.execute(db_change('select id, date, question, answer, token, email from user_application'))
  13. db_data = curs.fetchall()
  14. if db_data:
  15. div += '<p>' + load_lang('all_register_num') + ' : ' + str(len(db_data)) + '</p><br>'
  16. for application in db_data:
  17. question = application[2]
  18. answer = application[3]
  19. email = application[5]
  20. if not question:
  21. question = ''
  22. if not answer:
  23. answer = ''
  24. if not email:
  25. email = ''
  26. div += '''
  27. <form method=\"post\">
  28. <table>
  29. <tbody>
  30. <tr>
  31. <td>''' + load_lang('id') + '''</td><td>''' + application[0] + '''</td>
  32. </tr>
  33. <tr>
  34. <td>''' + load_lang('application_time') + '''</td><td>''' + application[1] + '''</td>
  35. </tr>
  36. <tr>
  37. <td>''' + load_lang('approval_question') + '''</td><td>''' + html.escape(question) + '''</td>
  38. </tr>
  39. <tr>
  40. <td>''' + load_lang('answer') + '''</td><td>''' + html.escape(answer) + '''</td>
  41. </tr>
  42. <tr>
  43. <td>''' + load_lang('email') + '''</td><td>''' + html.escape(email) + '''</td>
  44. </tr>
  45. <tr>
  46. <td colspan=\"2\" style=\"text-align: center;\">
  47. <button type=\"submit\" name=\"approve\" value=\"''' + application[4] + '''\">''' + load_lang('approve') + '''</button>
  48. <button type=\"submit\" name=\"decline\" value=\"''' + application[4] + '''\">''' + load_lang('decline') + '''</button>
  49. </td>
  50. </tr>
  51. </tbody>
  52. </table>
  53. </form>
  54. <br>
  55. '''
  56. else:
  57. div += load_lang('no_applications_now')
  58. return easy_minify(flask.render_template(skin_check(),
  59. imp = [load_lang('application_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  60. data = div,
  61. menu = [['other', load_lang('return')]]
  62. ))
  63. else:
  64. if flask.request.form.get('approve', '') != '':
  65. curs.execute(db_change('select id, pw, date, encode, question, answer, ip, ua, email from user_application where token = ?'), [
  66. flask.request.form.get('approve', '')
  67. ])
  68. application = curs.fetchall()
  69. if not application:
  70. return re_error('/error/26')
  71. application = application[0]
  72. curs.execute(db_change("select id from user_set where id = ?"), [application[0]])
  73. if curs.fetchall():
  74. return re_error('/error/6')
  75. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'pw', ?)"), [
  76. application[0],
  77. application[1]
  78. ])
  79. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'acl', 'user')"), [
  80. application[0]
  81. ])
  82. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'date', ?)"), [
  83. application[0],
  84. application[2]
  85. ])
  86. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'encode', ?)"), [
  87. application[0],
  88. application[3]
  89. ])
  90. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question', ?, ?)"), [
  91. application[0],
  92. application[4]
  93. ])
  94. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"), [
  95. application[0],
  96. application[5]
  97. ])
  98. ua_plus(application[0], application[6], application[7], application[2])
  99. if application[8] and application[8] != '':
  100. curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [
  101. application[0],
  102. application[8]
  103. ])
  104. curs.execute(db_change('delete from user_application where token = ?'), [
  105. flask.request.form.get('approve', '')
  106. ])
  107. conn.commit()
  108. elif flask.request.form.get('decline', '') != '':
  109. curs.execute(db_change('delete from user_application where token = ?'), [
  110. flask.request.form.get('decline', '')
  111. ])
  112. conn.commit()
  113. return redirect('/applications')