applications.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 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. curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('approve', '')])
  65. conn.commit()
  66. elif flask.request.form.get('decline', '') != '':
  67. curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('decline', '')])
  68. conn.commit()
  69. return redirect('/applications')
  70. return easy_minify(flask.render_template(skin_check(),
  71. imp = [load_lang('application_list'), wiki_set(), custom(), other2([0, 0])],
  72. data = div,
  73. menu = [['other', load_lang('return')]]
  74. ))