login_register.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_set 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. # c_id, c_pw, c_ans, c_que, c_key, c_type
  53. flask.session['c_id'] = user_id
  54. flask.session['c_pw'] = hashed
  55. flask.session['c_type'] = 'register'
  56. if requires_approval:
  57. flask.session['c_ans'] = flask.request.form.get('approval_question_answer', '')
  58. flask.session['c_que'] = approval_question
  59. curs.execute(db_change('select data from other where name = "email_have"'))
  60. sql_data = curs.fetchall()
  61. if sql_data and sql_data[0][0] != '' and admin != 1:
  62. flask.session['c_key'] = load_random_key(32)
  63. return redirect('/need_email')
  64. else:
  65. flask.session['c_key'] = 'email_pass'
  66. return redirect('/check_key')
  67. else:
  68. curs.execute(db_change('select data from other where name = "contract"'))
  69. data = curs.fetchall()
  70. contract = (data[0][0] + '<hr class="main_hr">') if data and data[0][0] != '' else ''
  71. approval_question = ''
  72. curs.execute(db_change('select data from other where name = "requires_approval"'))
  73. requires_approval = curs.fetchall()
  74. requires_approval = requires_approval and requires_approval[0][0] == 'on'
  75. requires_approval = None if admin == 1 else requires_approval
  76. if requires_approval:
  77. curs.execute(db_change('select data from other where name = "approval_question"'))
  78. data = curs.fetchall()
  79. if data and data[0][0] != '':
  80. approval_question = '''
  81. <hr class="main_hr">
  82. <span>''' + load_lang('approval_question') + ' : ' + data[0][0] + '''<span>
  83. <hr class="main_hr">
  84. <input placeholder="''' + load_lang('approval_question') + '''" name="approval_question_answer" type="text">
  85. <hr class="main_hr">
  86. '''
  87. return easy_minify(flask.render_template(skin_check(),
  88. imp = [load_lang('register'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  89. data = '''
  90. <form method="post">
  91. ''' + contract + '''
  92. <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
  93. <hr class="main_hr">
  94. <input placeholder="''' + load_lang('password') + '''" name="pw" type="password">
  95. <hr class="main_hr">
  96. <input placeholder="''' + load_lang('password_confirm') + '''" name="pw2" type="password">
  97. <hr class="main_hr">
  98. ''' + approval_question + '''
  99. ''' + captcha_get() + '''
  100. <!--
  101. <a href="" id="oauth_google">(Google)</a>
  102. <hr class="main_hr">
  103. -->
  104. <button type="submit">''' + load_lang('save') + '''</button>
  105. ''' + http_warning() + '''
  106. </form>
  107. <script>
  108. document.getElementById('oauth_google').href = '' +
  109. 'https://accounts.google.com/o/oauth2/auth' +
  110. '?client_id=ID' +
  111. '&redirect_uri=' + window.location.origin +
  112. '&response_type=code' +
  113. '&scope=https://www.googleapis.com/auth/userinfo.email' +
  114. '&approval_prompt=force' +
  115. '&access_type=offline' +
  116. '';
  117. </script>
  118. ''',
  119. menu = [['user', load_lang('return')]]
  120. ))