login_register.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. from .tool.func import *
  2. def login_register_2(conn):
  3. curs = conn.cursor()
  4. if ban_check() == 1:
  5. return re_error('/ban')
  6. ip = ip_check()
  7. admin = admin_check()
  8. if admin != 1 and ip_or_user(ip) == 0:
  9. return redirect('/user')
  10. if admin != 1:
  11. curs.execute(db_change('select data from other where name = "reg"'))
  12. set_d = curs.fetchall()
  13. if set_d and set_d[0][0] == 'on':
  14. return re_error('/ban')
  15. if flask.request.method == 'POST':
  16. if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
  17. return re_error('/error/13')
  18. else:
  19. captcha_post('', 0)
  20. user_id = flask.request.form.get('id', '')
  21. user_pw = flask.request.form.get('pw', '')
  22. user_repeat = flask.request.form.get('pw2', '')
  23. if user_id == '' or user_pw == '':
  24. return re_error('/error/27')
  25. if user_pw != user_repeat:
  26. return re_error('/error/20')
  27. if re.search(r'(?:[^A-Za-zㄱ-힣0-9])', user_id):
  28. return re_error('/error/8')
  29. curs.execute(db_change('select html from html_filter where kind = "name"'))
  30. set_d = curs.fetchall()
  31. for i in set_d:
  32. check_r = re.compile(i[0], re.I)
  33. if check_r.search(user_id):
  34. return re_error('/error/8')
  35. if len(user_id) > 32:
  36. return re_error('/error/7')
  37. curs.execute(db_change("select id from user where id = ?"), [user_id])
  38. if curs.fetchall():
  39. return re_error('/error/6')
  40. hashed = pw_encode(user_pw)
  41. ans_q = flask.request.form.get('approval_question_answer', '')
  42. curs.execute(db_change('select data from other where name = "requires_approval"'))
  43. requires_approval = curs.fetchall()
  44. requires_approval = requires_approval and requires_approval[0][0] == 'on'
  45. requires_approval = None if admin == 1 else requires_approval
  46. if requires_approval:
  47. curs.execute(db_change('select data from other where name = "approval_question"'))
  48. approval_question = curs.fetchall()
  49. approval_question = approval_question[0][0] if approval_question and approval_question[0][0] else ''
  50. else:
  51. approval_question = ''
  52. curs.execute(db_change('select data from other where name = "email_have"'))
  53. sql_data = curs.fetchall()
  54. if sql_data and sql_data[0][0] != '' and admin != 1:
  55. flask.session['c_id'] = user_id
  56. flask.session['c_pw'] = hashed
  57. flask.session['c_key'] = ''.join(random.choice("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") for i in range(64))
  58. if requires_approval:
  59. flask.session['c_ans'] = flask.request.form.get('approval_question_answer', '')
  60. flask.session['c_question'] = approval_question
  61. return redirect('/need_email')
  62. else:
  63. curs.execute(db_change('select data from other where name = "encode"'))
  64. db_data = curs.fetchall()
  65. curs.execute(db_change("select id from user limit 1"))
  66. if not curs.fetchall():
  67. curs.execute(db_change("insert into user (id, pw, acl, date, encode) values (?, ?, 'owner', ?, ?)"), [
  68. user_id,
  69. hashed,
  70. get_time(),
  71. db_data[0][0]
  72. ])
  73. first = 1
  74. else:
  75. if requires_approval:
  76. application_token = ''.join(random.choice("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") for i in range(60))
  77. curs.execute(db_change(
  78. "insert into user_application (id, pw, date, encode, question, answer, token, ip, ua, email) values (?, ?, ?, ?, ?, ?, ?, ?, ?, '')"
  79. ), [
  80. user_id,
  81. hashed,
  82. get_time(),
  83. db_data[0][0],
  84. approval_question,
  85. ans_q,
  86. application_token,
  87. ip_check(),
  88. flask.request.headers.get('User-Agent')
  89. ])
  90. conn.commit()
  91. return redirect('/application_submitted')
  92. else:
  93. curs.execute(db_change("insert into user (id, pw, acl, date, encode) values (?, ?, 'user', ?, ?)"), [user_id, hashed, get_time(), db_data[0][0]])
  94. first = 0
  95. ip = ip_check()
  96. agent = flask.request.headers.get('User-Agent')
  97. curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [user_id, ip, agent, get_time()])
  98. flask.session['id'] = user_id
  99. flask.session['head'] = ''
  100. conn.commit()
  101. return redirect('/change') if first == 0 else redirect('/setting')
  102. else:
  103. curs.execute(db_change('select data from other where name = "contract"'))
  104. data = curs.fetchall()
  105. contract = (data[0][0] + '<hr class="main_hr">') if data and data[0][0] != '' else ''
  106. http_warring = '<hr class="main_hr"><span>' + load_lang('http_warring') + '</span>'
  107. approval_question = ''
  108. curs.execute(db_change('select data from other where name = "requires_approval"'))
  109. requires_approval = curs.fetchall()
  110. requires_approval = requires_approval and requires_approval[0][0] == 'on'
  111. requires_approval = None if admin == 1 else requires_approval
  112. if requires_approval:
  113. curs.execute(db_change('select data from other where name = "approval_question"'))
  114. data = curs.fetchall()
  115. if data and data[0][0] != '':
  116. approval_question = '''
  117. <hr class="main_hr">
  118. <span>''' + load_lang('approval_question') + ' : ' + data[0][0] + '''<span>
  119. <hr class="main_hr">
  120. <input placeholder="''' + load_lang('approval_question') + '''" name="approval_question_answer" type="text">
  121. <hr class="main_hr">
  122. '''
  123. return easy_minify(flask.render_template(skin_check(),
  124. imp = [load_lang('register'), wiki_set(), custom(), other2([0, 0])],
  125. data = '''
  126. <form method="post">
  127. ''' + contract + '''
  128. <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
  129. <hr class="main_hr">
  130. <input placeholder="''' + load_lang('password') + '''" name="pw" type="password">
  131. <hr class="main_hr">
  132. <input placeholder="''' + load_lang('password_confirm') + '''" name="pw2" type="password">
  133. <hr class="main_hr">
  134. ''' + approval_question + '''
  135. ''' + captcha_get() + '''
  136. <button type="submit">''' + load_lang('save') + '''</button>
  137. ''' + http_warring + '''
  138. </form>
  139. ''',
  140. menu = [['user', load_lang('return')]]
  141. ))