login_check_key.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. from .tool.func import *
  2. def login_check_key_2(conn, tool):
  3. curs = conn.cursor()
  4. # 난잡한 코드 정리 필요
  5. if flask.request.method == 'POST' or \
  6. ('c_key' in flask.session and flask.session['c_key'] == 'email_pass'):
  7. re_set_list = ['c_id', 'c_pw', 'c_ans', 'c_que', 'c_key', 'c_type', 'c_email']
  8. ip = ip_check()
  9. input_key = flask.request.form.get('key', '')
  10. user_agent = flask.request.headers.get('User-Agent', '')
  11. if 'c_type' in flask.session and \
  12. flask.session['c_type'] == 'pass_find' and \
  13. flask.session['c_key'] == input_key:
  14. curs.execute(db_change("update user set pw = ? where id = ?"), [pw_encode(flask.session['c_key']), flask.session['c_id']])
  15. conn.commit()
  16. user_id = flask.session['c_id']
  17. user_pw = flask.session['c_key']
  18. for i in re_set_list:
  19. flask.session.pop(i, None)
  20. curs.execute(db_change('select data from other where name = "reset_user_text"'))
  21. sql_d = curs.fetchall()
  22. b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
  23. curs.execute(db_change('select data from user_set where name = "2fa" and id = ?'), [user_id])
  24. if curs.fetchall():
  25. curs.execute(db_change("update user_set set data = '' where name = '2fa' and id = ?"), [user_id])
  26. return easy_minify(flask.render_template(skin_check(),
  27. imp = [load_lang('reset_user_ok'), wiki_set(), custom(), other2([0, 0])],
  28. data = b_text + load_lang('id') + ' : ' + user_id + '<br>' + load_lang('password') + ' : ' + user_pw,
  29. menu = [['user', load_lang('return')]]
  30. ))
  31. elif 'c_type' in flask.session and \
  32. (flask.session['c_key'] == input_key or flask.session['c_key'] == 'email_pass'):
  33. curs.execute(db_change('select data from other where name = "encode"'))
  34. db_data = curs.fetchall()
  35. if flask.session['c_type'] == 'register':
  36. curs.execute(db_change("select id from user limit 1"))
  37. first = 1 if not curs.fetchall() else 0
  38. curs.execute(db_change("select id from user where id = ?"), [flask.session['c_id']])
  39. if curs.fetchall():
  40. for i in re_set_lire:
  41. flask.session.pop(i, None)
  42. return re_error('/error/6')
  43. curs.execute(db_change("select id from user_application where id = ?"), [flask.session['c_id']])
  44. if curs.fetchall():
  45. for i in re_set_lire:
  46. flask.session.pop(i, None)
  47. return re_error('/error/6')
  48. curs.execute(db_change('select data from other where name = "requires_approval"'))
  49. requires_approval = curs.fetchall()
  50. if requires_approval and requires_approval[0][0] == 'on':
  51. application_token = load_random_key(32)
  52. curs.execute(db_change(
  53. "insert into user_application (id, pw, date, encode, question, answer, token, ip, ua, email) " + \
  54. "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
  55. ), [
  56. flask.session['c_id'],
  57. flask.session['c_pw'],
  58. get_time(),
  59. db_data[0][0],
  60. flask.session['c_que'],
  61. flask.session['c_ans'],
  62. application_token,
  63. ip,
  64. user_agent,
  65. flask.session['c_email']
  66. ])
  67. conn.commit()
  68. for i in re_set_list:
  69. flask.session.pop(i, None)
  70. return redirect('/application_submitted')
  71. else:
  72. curs.execute(db_change("insert into user (id, pw, acl, date, encode) values (?, ?, ?, ?, ?)"), [
  73. flask.session['c_id'],
  74. flask.session['c_pw'],
  75. get_time(),
  76. 'user' if first == 0 else 'owner',
  77. db_data[0][0]
  78. ])
  79. curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [
  80. flask.session['c_id'],
  81. flask.session['c_email']
  82. ])
  83. curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [
  84. flask.session['c_id'],
  85. ip,
  86. user_agent,
  87. get_time()
  88. ])
  89. flask.session['id'] = flask.session['c_id']
  90. flask.session['head'] = ''
  91. conn.commit()
  92. else:
  93. curs.execute(db_change('delete from user_set where name = "email" and id = ?'), [ip])
  94. curs.execute(db_change('insert into user_set (name, id, data) values ("email", ?, ?)'), [ip, flask.session['c_email']])
  95. first = 0
  96. for i in re_set_list:
  97. flask.session.pop(i, None)
  98. return redirect('/change') if first == 0 else redirect('/setting')
  99. else:
  100. for i in re_set_list:
  101. flask.session.pop(i, None)
  102. return redirect('/user')
  103. else:
  104. curs.execute(db_change('select data from other where name = "check_key_text"'))
  105. sql_d = curs.fetchall()
  106. b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
  107. return easy_minify(flask.render_template(skin_check(),
  108. imp = [load_lang('check_key'), wiki_set(), custom(), other2([0, 0])],
  109. data = '''
  110. <form method="post">
  111. ''' + b_text + '''
  112. <input placeholder="''' + load_lang('key') + '''" name="key" type="text">
  113. <hr class="main_hr">
  114. <button type="submit">''' + load_lang('save') + '''</button>
  115. </form>
  116. ''',
  117. menu = [['user', load_lang('return')]]
  118. ))