login_register.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. from .tool.func import *
  2. def login_register_2(conn):
  3. curs = conn.cursor()
  4. if ban_check(None, 'login') == 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. curs.execute(db_change("select id from user_application where id = ?"), [user_id])
  41. if curs.fetchall():
  42. return re_error('/error/6')
  43. hashed = pw_encode(user_pw)
  44. ans_q = flask.request.form.get('approval_question_answer', '')
  45. curs.execute(db_change('select data from other where name = "requires_approval"'))
  46. requires_approval = curs.fetchall()
  47. requires_approval = requires_approval and requires_approval[0][0] == 'on'
  48. requires_approval = None if admin == 1 else requires_approval
  49. if requires_approval:
  50. curs.execute(db_change('select data from other where name = "approval_question"'))
  51. approval_question = curs.fetchall()
  52. approval_question = approval_question[0][0] if approval_question and approval_question[0][0] else ''
  53. else:
  54. approval_question = ''
  55. # c_id, c_pw, c_ans, c_que, c_key, c_type
  56. flask.session['c_id'] = user_id
  57. flask.session['c_pw'] = hashed
  58. flask.session['c_type'] = 'register'
  59. if requires_approval:
  60. flask.session['c_ans'] = flask.request.form.get('approval_question_answer', '')
  61. flask.session['c_que'] = approval_question
  62. curs.execute(db_change('select data from other where name = "email_have"'))
  63. sql_data = curs.fetchall()
  64. if sql_data and sql_data[0][0] != '' and admin != 1:
  65. flask.session['c_key'] = load_random_key(32)
  66. return redirect('/need_email')
  67. else:
  68. flask.session['c_key'] = 'email_pass'
  69. return redirect('/check_key')
  70. else:
  71. curs.execute(db_change('select data from other where name = "contract"'))
  72. data = curs.fetchall()
  73. contract = (data[0][0] + '<hr class="main_hr">') if data and data[0][0] != '' else ''
  74. http_warring = '<hr class="main_hr"><span>' + load_lang('http_warring') + '</span>'
  75. approval_question = ''
  76. curs.execute(db_change('select data from other where name = "requires_approval"'))
  77. requires_approval = curs.fetchall()
  78. requires_approval = requires_approval and requires_approval[0][0] == 'on'
  79. requires_approval = None if admin == 1 else requires_approval
  80. if requires_approval:
  81. curs.execute(db_change('select data from other where name = "approval_question"'))
  82. data = curs.fetchall()
  83. if data and data[0][0] != '':
  84. approval_question = '''
  85. <hr class="main_hr">
  86. <span>''' + load_lang('approval_question') + ' : ' + data[0][0] + '''<span>
  87. <hr class="main_hr">
  88. <input placeholder="''' + load_lang('approval_question') + '''" name="approval_question_answer" type="text">
  89. <hr class="main_hr">
  90. '''
  91. return easy_minify(flask.render_template(skin_check(),
  92. imp = [load_lang('register'), wiki_set(), custom(), other2([0, 0])],
  93. data = '''
  94. <form method="post">
  95. ''' + contract + '''
  96. <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
  97. <hr class="main_hr">
  98. <input placeholder="''' + load_lang('password') + '''" name="pw" type="password">
  99. <hr class="main_hr">
  100. <input placeholder="''' + load_lang('password_confirm') + '''" name="pw2" type="password">
  101. <hr class="main_hr">
  102. ''' + approval_question + '''
  103. ''' + captcha_get() + '''
  104. <button type="submit">''' + load_lang('save') + '''</button>
  105. ''' + http_warring + '''
  106. </form>
  107. ''',
  108. menu = [['user', load_lang('return')]]
  109. ))