DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from flask import Flask, request, redirect, session
|
2 |
import requests
|
3 |
import os
|
4 |
|
@@ -29,11 +29,22 @@ def login():
|
|
29 |
if access_token and user_id:
|
30 |
session['access_token'] = access_token
|
31 |
session['user_id'] = user_id
|
32 |
-
return redirect('
|
33 |
else:
|
34 |
return "Ошибка при получении access_token", 400
|
35 |
else:
|
36 |
return "Код авторизации не найден", 400
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
if __name__ == '__main__':
|
39 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
1 |
+
from flask import Flask, request, redirect, session, url_for
|
2 |
import requests
|
3 |
import os
|
4 |
|
|
|
29 |
if access_token and user_id:
|
30 |
session['access_token'] = access_token
|
31 |
session['user_id'] = user_id
|
32 |
+
return redirect(url_for('protected_route'))
|
33 |
else:
|
34 |
return "Ошибка при получении access_token", 400
|
35 |
else:
|
36 |
return "Код авторизации не найден", 400
|
37 |
|
38 |
+
def is_authenticated():
|
39 |
+
return 'access_token' in session and 'user_id' in session
|
40 |
+
|
41 |
+
@app.route('/protected')
|
42 |
+
def protected_route():
|
43 |
+
if is_authenticated():
|
44 |
+
user_id = session['user_id']
|
45 |
+
return f"Добро пожаловать, пользователь с ID {user_id}!"
|
46 |
+
else:
|
47 |
+
return redirect(url_for('login'))
|
48 |
+
|
49 |
if __name__ == '__main__':
|
50 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|