login_find_email_check.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. from .tool.func import *
  2. # 개편 필요
  3. def login_find_email_check(tool):
  4. with get_db_connect() as conn:
  5. curs = conn.cursor()
  6. if flask.request.method == 'POST' or \
  7. ('c_key' in flask.session and flask.session['c_key'] == 'email_pass'):
  8. re_set_list = ['c_id', 'c_pw', 'c_ans', 'c_que', 'c_key', 'c_type', 'c_email']
  9. ip = ip_check()
  10. input_key = flask.request.form.get('key', '')
  11. user_agent = flask.request.headers.get('User-Agent', '')
  12. if 'c_type' in flask.session and \
  13. flask.session['c_type'] == 'pass_find' and \
  14. flask.session['c_key'] == input_key:
  15. curs.execute(db_change("update user_set set data = ? where name = 'pw' and id = ?"), [
  16. pw_encode(flask.session['c_key']),
  17. flask.session['c_id']
  18. ])
  19. curs.execute(db_change('select data from user_set where name = "2fa" and id = ?'), [user_id])
  20. if curs.fetchall():
  21. curs.execute(db_change("update user_set set data = '' where name = '2fa' and id = ?"), [user_id])
  22. user_id = flask.session['c_id']
  23. user_pw = flask.session['c_key']
  24. for i in re_set_list:
  25. flask.session.pop(i, None)
  26. curs.execute(db_change('select data from other where name = "reset_user_text"'))
  27. sql_d = curs.fetchall()
  28. b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
  29. conn.commit()
  30. return easy_minify(flask.render_template(skin_check(),
  31. imp = [load_lang('reset_user_ok'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  32. data = '' + \
  33. b_text + \
  34. load_lang('id') + ' : ' + user_id + \
  35. '<hr class="main_hr">' + \
  36. load_lang('password') + ' : ' + user_pw + \
  37. '',
  38. menu = [['user', load_lang('return')]]
  39. ))
  40. elif 'c_type' in flask.session and \
  41. (flask.session['c_key'] == input_key or flask.session['c_key'] == 'email_pass'):
  42. curs.execute(db_change('select data from other where name = "encode"'))
  43. db_data = curs.fetchall()
  44. if flask.session['c_type'] == 'register':
  45. if flask.session['c_key'] == 'email_pass':
  46. flask.session['c_email'] = ''
  47. curs.execute(db_change("select id from user_set limit 1"))
  48. first = 1 if not curs.fetchall() else 0
  49. curs.execute(db_change("select id from user_set where id = ?"), [
  50. flask.session['c_id']
  51. ])
  52. if curs.fetchall():
  53. for i in re_set_list:
  54. flask.session.pop(i, None)
  55. return re_error('/error/6')
  56. curs.execute(db_change("select id from user_set where id = ? and name = 'application'"), [
  57. flask.session['c_id']
  58. ])
  59. if curs.fetchall():
  60. for i in re_set_list:
  61. flask.session.pop(i, None)
  62. return re_error('/error/6')
  63. curs.execute(db_change(
  64. 'select data from other where name = "requires_approval"'
  65. ))
  66. requires_approval = curs.fetchall()
  67. if requires_approval and requires_approval[0][0] == 'on':
  68. user_app_data = {}
  69. user_app_data['id'] = flask.session['c_id']
  70. user_app_data['pw'] = flask.session['c_pw']
  71. user_app_data['date'] = get_time()
  72. user_app_data['encode'] = db_data[0][0]
  73. user_app_data['question'] = flask.session['c_que']
  74. user_app_data['answer'] = flask.session['c_ans']
  75. user_app_data['ip'] = ip
  76. user_app_data['ua'] = user_agent
  77. user_app_data['email'] = flask.session['c_email']
  78. curs.execute(db_change(
  79. "insert into user_set (id, name, data) values (?, ?, ?)"
  80. ), [
  81. flask.session['c_id'],
  82. 'application',
  83. json.dumps(user_app_data)
  84. ])
  85. conn.commit()
  86. for i in re_set_list:
  87. flask.session.pop(i, None)
  88. return redirect('/application_submitted')
  89. else:
  90. if first == 0:
  91. user_auth = 'user'
  92. else:
  93. user_auth = 'owner'
  94. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'pw', ?)"), [
  95. flask.session['c_id'],
  96. flask.session['c_pw']
  97. ])
  98. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'acl', ?)"), [
  99. flask.session['c_id'],
  100. user_auth
  101. ])
  102. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'date', ?)"), [
  103. flask.session['c_id'],
  104. get_time()
  105. ])
  106. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'encode', ?)"), [
  107. flask.session['c_id'],
  108. db_data[0][0]
  109. ])
  110. curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [
  111. flask.session['c_id'],
  112. flask.session['c_email']
  113. ])
  114. ua_plus(flask.session['c_id'], ip, user_agent, get_time())
  115. flask.session['id'] = flask.session['c_id']
  116. flask.session['head'] = ''
  117. conn.commit()
  118. else:
  119. curs.execute(db_change('delete from user_set where name = "email" and id = ?'), [ip])
  120. curs.execute(db_change('insert into user_set (name, id, data) values ("email", ?, ?)'), [ip, flask.session['c_email']])
  121. first = 0
  122. for i in re_set_list:
  123. flask.session.pop(i, None)
  124. return redirect('/change') if first == 0 else redirect('/setting')
  125. else:
  126. for i in re_set_list:
  127. flask.session.pop(i, None)
  128. return redirect('/user')
  129. else:
  130. curs.execute(db_change('select data from other where name = "check_key_text"'))
  131. sql_d = curs.fetchall()
  132. b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
  133. return easy_minify(flask.render_template(skin_check(),
  134. imp = [load_lang('check_key'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  135. data = '''
  136. <form method="post">
  137. ''' + b_text + '''
  138. <input placeholder="''' + load_lang('key') + '''" name="key" type="password">
  139. <hr class="main_hr">
  140. <button type="submit">''' + load_lang('save') + '''</button>
  141. </form>
  142. ''',
  143. menu = [['user', load_lang('return')]]
  144. ))