2
0

applications.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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(), custom(), other2([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 where id = ?"), [application[0]])
  73. if curs.fetchall():
  74. return re_error('/error/6')
  75. curs.execute(db_change("insert into user (id, pw, acl, date, encode) values (?, ?, 'user', ?, ?)"), [
  76. application[0],
  77. application[1],
  78. application[2],
  79. application[3]
  80. ])
  81. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question', ?, ?)"), [application[0], application[4]])
  82. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"), [application[0], application[5]])
  83. ua_plus(application[0], application[6], application[7], application[2])
  84. if application[8] and application[8] != '':
  85. curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [application[0], application[8]])
  86. curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('approve', '')])
  87. conn.commit()
  88. elif flask.request.form.get('decline', '') != '':
  89. curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('decline', '')])
  90. conn.commit()
  91. return redirect('/applications')