2
0

login.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from .tool.func import *
  2. from flask import request
  3. def login_2(conn):
  4. curs = conn.cursor()
  5. if custom()[2] != 0:
  6. return redirect('/user')
  7. if ban_check(tool = 'login') == 1:
  8. return re_error('/ban')
  9. if flask.request.method == 'POST':
  10. if captcha_post(flask.request.form.get('g-recaptcha-response', '')) == 1:
  11. return re_error('/error/13')
  12. else:
  13. captcha_post('', 0)
  14. ip = ip_check()
  15. agent = flask.request.headers.get('User-Agent')
  16. curs.execute("select pw, encode from user where id = ?", [flask.request.form.get('id', None)])
  17. user = curs.fetchall()
  18. if not user:
  19. return re_error('/error/2')
  20. pw_check_d = pw_check(
  21. flask.request.form.get('pw', ''),
  22. user[0][0],
  23. user[0][1],
  24. flask.request.form.get('id', None)
  25. )
  26. if pw_check_d != 1:
  27. return re_error('/error/10')
  28. flask.session['state'] = 1
  29. flask.session['id'] = flask.request.form.get('id', None)
  30. curs.execute("select css from custom where user = ?", [flask.request.form.get('id', None)])
  31. css_data = curs.fetchall()
  32. if css_data:
  33. flask.session['head'] = css_data[0][0]
  34. else:
  35. flask.session['head'] = ''
  36. curs.execute("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')", [flask.request.form.get('id', None), ip_check(1), agent, get_time()])
  37. conn.commit()
  38. return redirect('/user')
  39. else:
  40. oauth_check = 0
  41. oauth_content = '<link rel="stylesheet" href="/views/main_css/oauth.css"><hr class=\"main_hr\"><div class="oauth-wrapper"><ul class="oauth-list">'
  42. oauth_supported = load_oauth('_README')['support']
  43. for i in range(len(oauth_supported)):
  44. oauth_data = load_oauth(oauth_supported[i])
  45. if oauth_data['client_id'] != '' and oauth_data['client_secret'] != '':
  46. oauth_content += '''
  47. <li>
  48. <a href="/oauth/{}/init">
  49. <div class="oauth-btn oauth-btn-{}">
  50. <div class="oauth-btn-logo oauth-btn-{}"></div>
  51. {}
  52. </div>
  53. </a>
  54. </li>
  55. '''.format(
  56. oauth_supported[i],
  57. oauth_supported[i],
  58. oauth_supported[i],
  59. load_lang('oauth_signin_' + oauth_supported[i])
  60. )
  61. oauth_check = 1
  62. oauth_content += '</ul></div>'
  63. if oauth_check == 0:
  64. oauth_content = ''
  65. print(request.headers.get('X-Forwarded-Proto', 'http'))
  66. if request.headers.get('X-Forwarded-Proto', 'http') != 'https':
  67. http_warring = '<hr class=\"main_hr\"><span>' + load_lang('http_warring') + '</span>'
  68. else:
  69. http_warring = ''
  70. return easy_minify(flask.render_template(skin_check(),
  71. imp = [load_lang('login'), wiki_set(), custom(), other2([0, 0])],
  72. data = '''
  73. <form method="post">
  74. <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
  75. <hr class=\"main_hr\">
  76. <input placeholder="''' + load_lang('password') + '''" name="pw" type="password">
  77. <hr class=\"main_hr\">
  78. ''' + captcha_get() + '''
  79. <button type="submit">''' + load_lang('login') + '''</button>
  80. ''' + oauth_content + '''
  81. ''' + http_warring + '''
  82. </form>
  83. ''',
  84. menu = [['user', load_lang('return')]]
  85. ))