login_register.py 7.5 KB

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