login_register.py 7.4 KB

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