applications.py 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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>총 ' + 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', ?, ?)"), [application[0], application[1], application[2], application[3]])
  70. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question', ?, ?)"), [application[0], application[4]])
  71. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"), [application[0], application[5]])
  72. curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [application[0], application[6], application[7], application[2]])
  73. if application[8] and application[8] != '':
  74. curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [application[0], application[8]])
  75. curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('approve', '')])
  76. conn.commit()
  77. elif flask.request.form.get('decline', '') != '':
  78. curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('decline', '')])
  79. conn.commit()
  80. return redirect('/applications')
  81. return easy_minify(flask.render_template(skin_check(),
  82. imp = [load_lang('application_list'), wiki_set(), custom(), other2([0, 0])],
  83. data = div,
  84. menu = [['other', load_lang('return')]]
  85. ))