login_register.py 4.4 KB

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