applications.py 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 from user_application'))
  14. db_data = curs.fetchall()
  15. if db_data:
  16. div += '''
  17. <form method=\"post\">
  18. <table id=\"main_table_set\">
  19. <tbody>
  20. <tr>
  21. <td>''' + load_lang('id') + '''</td>
  22. <td>''' + load_lang('application_time') + '''</td>
  23. <td>''' + load_lang('approval_question') + '''</td>
  24. <td>''' + load_lang('answer') + '''</td>
  25. <td>''' + load_lang('approve_or_decline') + '''</td>
  26. </tr>
  27. '''
  28. for application in db_data:
  29. question = application[2]
  30. answer = application[3]
  31. if not question or question == '':
  32. question = '(질문 없음)'
  33. if not answer or answer == '':
  34. answer = '(대답 없음)'
  35. div += '''
  36. <tr>
  37. <td>''' + application[0] + '''</td>
  38. <td>''' + application[1] + '''</td>
  39. <td>''' + question + '''</td>
  40. <td>''' + answer + '''</td>
  41. <td>
  42. <button type=\"submit\" name=\"approve\" value=\"''' + application[4] + '''\">''' + load_lang('approve') + '''</button>
  43. <button type=\"submit\" name=\"decline\" value=\"''' + application[4] + '''\">''' + load_lang('decline') + '''</button>
  44. </td>
  45. </tr>
  46. '''
  47. div += '</tbody></table></form>'
  48. else:
  49. div += load_lang('no_applications_now')
  50. else:
  51. if flask.request.form.get('approve', '') != '':
  52. curs.execute(db_change('select id, pw, date, encode, question, answer, ip, ua, email from user_application where token = ?'), [flask.request.form.get('approve', '')])
  53. application = curs.fetchall()
  54. if not application:
  55. return re_error('/error/26')
  56. application = application[0]
  57. curs.execute(db_change("select id from user where id = ?"), [application[0]])
  58. if curs.fetchall():
  59. return re_error('/error/6')
  60. curs.execute(db_change("insert into user (id, pw, acl, date, encode) values (?, ?, 'user', ?, ?)"), [application[0], application[1], application[2], application[3]])
  61. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question', ?, ?)"), [application[0], application[4]])
  62. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"), [application[0], application[5]])
  63. curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [application[0], application[6], application[7], application[2]])
  64. if application[8] and application[8] != '':
  65. curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [application[0], application[8]])
  66. curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('approve', '')])
  67. conn.commit()
  68. elif flask.request.form.get('decline', '') != '':
  69. curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('decline', '')])
  70. conn.commit()
  71. return redirect('/applications')
  72. return easy_minify(flask.render_template(skin_check(),
  73. imp = [load_lang('application_list'), wiki_set(), custom(), other2([0, 0])],
  74. data = div,
  75. menu = [['other', load_lang('return')]]
  76. ))