2
0

login_register.py 4.6 KB

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