applications.py 5.0 KB

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