login_register.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. from .tool.func import *
  2. def login_register_2():
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if ban_check(None, 'login') == 1:
  6. return re_error('/ban')
  7. ip = ip_check()
  8. admin = admin_check()
  9. if admin != 1 and ip_or_user(ip) == 0:
  10. return redirect('/user')
  11. if admin != 1:
  12. curs.execute(db_change('select data from other where name = "reg"'))
  13. set_d = curs.fetchall()
  14. if set_d and set_d[0][0] == 'on':
  15. return re_error('/ban')
  16. if flask.request.method == 'POST':
  17. # 리캡차
  18. if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
  19. return re_error('/error/13')
  20. else:
  21. captcha_post('', 0)
  22. user_id = flask.request.form.get('id', '')
  23. user_pw = flask.request.form.get('pw', '')
  24. user_repeat = flask.request.form.get('pw2', '')
  25. # PW 검증
  26. if user_id == '' or user_pw == '':
  27. return re_error('/error/27')
  28. if user_pw != user_repeat:
  29. return re_error('/error/20')
  30. # PW 길이 제한
  31. curs.execute(db_change("select data from other where name = 'password_min_length'"))
  32. db_data = curs.fetchall()
  33. if db_data and db_data[0][0] != '':
  34. password_min_length = int(number_check(db_data[0][0]))
  35. if password_min_length > len(user_pw):
  36. return re_error('/error/40')
  37. if do_user_name_check(user_id) == 1:
  38. return re_error('/error/8')
  39. if admin != 1:
  40. # 이메일 필요시 /register/email로 발송
  41. curs.execute(db_change('select data from other where name = "email_have"'))
  42. sql_data = curs.fetchall()
  43. if sql_data and sql_data[0][0] != '':
  44. # 임시로 세션에 저장
  45. flask.session['reg_id'] = user_id
  46. flask.session['reg_pw'] = user_pw
  47. return redirect('/register/email')
  48. # 가입 승인 필요시 /register/submit으로 발송
  49. curs.execute(db_change('select data from other where name = "requires_approval"'))
  50. sql_data = curs.fetchall()
  51. if sql_data and sql_data[0][0] != '':
  52. flask.session['submit_id'] = user_id
  53. flask.session['submit_pw'] = user_pw
  54. return redirect('/register/submit')
  55. # 전부 아니면 바로 가입 후 /login으로 발송
  56. add_user(user_id, user_pw)
  57. conn.commit()
  58. return redirect('/login')
  59. else:
  60. curs.execute(db_change('select data from other where name = "contract"'))
  61. data = curs.fetchall()
  62. contract = (data[0][0] + '<hr class="main_hr">') if data and data[0][0] != '' else ''
  63. curs.execute(db_change("select data from other where name = 'password_min_length'"))
  64. db_data = curs.fetchall()
  65. if db_data and db_data[0][0] != '':
  66. password_min_length = ' (' + load_lang('password_min_length') + ' : ' + db_data[0][0] + ')'
  67. else:
  68. password_min_length = ''
  69. return easy_minify(flask.render_template(skin_check(),
  70. imp = [load_lang('register'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  71. data = '''
  72. <form method="post">
  73. ''' + contract + '''
  74. <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
  75. <hr class="main_hr">
  76. <input placeholder="''' + load_lang('password') + password_min_length + '''" name="pw" type="password">
  77. <hr class="main_hr">
  78. <input placeholder="''' + load_lang('password_confirm') + '''" name="pw2" type="password">
  79. <hr class="main_hr">
  80. ''' + captcha_get() + '''
  81. <button type="submit">''' + load_lang('save') + '''</button>
  82. ''' + http_warning() + '''
  83. </form>
  84. ''',
  85. menu = [['user', load_lang('return')]]
  86. ))