Parcourir la source

Add files via upload

hoparkgo9ma il y a 7 ans
Parent
commit
ec021562a7
3 fichiers modifiés avec 43 ajouts et 0 suppressions
  1. 21 0
      app.py
  2. 7 0
      func.py
  3. 15 0
      oauthsettings.json

+ 21 - 0
app.py

@@ -2764,6 +2764,27 @@ def login():
                     ''',
             menu = [['user', load_lang('user')]]
         ))
+
+@app.route('/oauth/<regex("naver|facebook"):platform>/<regex("init|callback"):func>')
+def login_oauth(platform = None, func = None):
+    publish_url = load_oauth('publish_url')
+    oauth_data = load_oauth(platform)
+    if func == 'init':
+        if oauth_data['client_id'] == '' or oauth_data['client_secret'] == '':
+            return '관리자가 이 기능을 비활성화시켰습니다.'
+        elif publish_url == 'https://':
+            return '관리자가 이 기능을 사용하는데 대한 정보를 제공하지 않았습니다.'
+    
+        data = {
+            'client_id' : oauth_data['client_id'],
+            'redirect_uri' : publish_url + '/oauth/' + platform + '/callback',
+            'state' : 'RAMDOMVALUE'
+        }
+        return redirect('https://www.facebook.com/v3.1/dialog/oauth?client_id={}&redirect_uri={}&state={}'.format(
+            data['client_id'], data['redirect_uri'], data['state']
+        ))
+
+    return str(load_oauth(platform))
                 
 @app.route('/change', methods=['POST', 'GET'])
 def change_password():

+ 7 - 0
func.py

@@ -257,6 +257,13 @@ def load_lang(data, num = 2):
         else:
             return load_lang(data, 1)
 
+# oauth settings #
+def load_oauth(provider):
+    oauth_native = open('oauthsettings.json', encoding='utf-8').read()
+    oauth = json.loads(oauth_native)
+    return oauth[provider]
+# end #
+
 def ip_or_user(data):
     if re.search('(\.|:)', data):
         return 1

+ 15 - 0
oauthsettings.json

@@ -0,0 +1,15 @@
+{
+    "_information" : {
+        "ko" : "oauth 로그인 기능을 사용하려면 'publish_url'값을 https 프로토콜을 포함한 도메인 주소로 설정하고, 실제로 https 연결을 지원해야합니다.",
+        "en" : "To use the oauth login feature, you must set the 'publish_url' value to a domain address that includes the https protocol, and actually support https connections."
+    },
+    "publish_url" : "https://",
+    "facebook" : {
+        "client_id" : "",
+        "client_secret" : ""
+    },
+    "naver" : {
+        "client_id" : "",
+        "client_secret" : ""
+    }
+}