From 8807be021dea186dd7a971136b94e26a239e8e89 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 28 Nov 2023 19:56:53 +0300 Subject: [PATCH 1/5] feat: dev users --- server/app/dev.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 server/app/dev.py diff --git a/server/app/dev.py b/server/app/dev.py new file mode 100644 index 0000000..38679ce --- /dev/null +++ b/server/app/dev.py @@ -0,0 +1,31 @@ +from werkzeug.local import LocalProxy +from flask import current_app as app +from app.db import get_db + +db = LocalProxy(get_db) + + +def get_admin(): + admin = db.users.find_one({"login": app.config.get('INIT_ADMIN_LOGIN')}) + if not admin: + result = db.users.insert_one({ + 'login': app.config.get('INIT_ADMIN_LOGIN'), + 'password': app.config.get('INIT_ADMIN_PASSWORD'), + 'name': 'root', + 'role': 'admin' + }) + admin = db.users.find_one(result.inserted_id) + return admin + + +def get_test_user(): + user = db.users.find_one({"login": 'user'}) + if not user: + result = db.users.insert_one({ + 'login': 'user', + 'password': '1234', + 'name': 'Ivan', + 'role': 'user' + }) + user = db.users.find_one(result.inserted_id) + return user From 3c44a8cf52817a5c1f52831927a3eb7ec1ae036b Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 28 Nov 2023 19:57:04 +0300 Subject: [PATCH 2/5] feat: dev users add on startup --- server/app/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/app/__init__.py b/server/app/__init__.py index 53030a9..bdbab28 100644 --- a/server/app/__init__.py +++ b/server/app/__init__.py @@ -23,3 +23,14 @@ scheduler = BackgroundScheduler() scheduler.add_job(send_queue, 'interval', seconds=1) scheduler.start() + +from .dev import get_admin, get_test_user + + +def add_init_users(): + get_admin() + get_test_user() + + +with app.app_context(): + add_init_users() From b6cab7801769a7058718ebfcdab8ce401972e117 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 28 Nov 2023 19:57:18 +0300 Subject: [PATCH 3/5] fix(auth): dev/get_admin using --- server/app/routes/auth.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/server/app/routes/auth.py b/server/app/routes/auth.py index e7ea716..3af8811 100644 --- a/server/app/routes/auth.py +++ b/server/app/routes/auth.py @@ -5,6 +5,7 @@ from flask import current_app as app from app.auth.User import User from app.db import get_db +from app.dev import get_admin from app.services.user import get_user_by_id from app.utils import parse_json @@ -48,14 +49,6 @@ def delete(self): @api.route('/login/dev') class Login(Resource): def get(self): - admin = db.users.find_one({"login": app.config.get('INIT_ADMIN_LOGIN')}) - if not admin: - result = db.users.insert_one({ - 'login': app.config.get('INIT_ADMIN_LOGIN'), - 'password': app.config.get('INIT_ADMIN_PASSWORD'), - 'name': 'root', - 'role': 'admin' - }) - admin = db.users.find_one(result.inserted_id) + admin = get_admin() login_user(User(admin), remember=True) return parse_json(get_user_by_id(current_user.get_id())) From 92250cd7711a7be4c7cb1f74035a4ab445c1f6e9 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 28 Nov 2023 21:13:27 +0300 Subject: [PATCH 4/5] fix(AuthComponent): real login --- .../components/routes/auth/AuthComponent.vue | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/client/src/components/routes/auth/AuthComponent.vue b/client/src/components/routes/auth/AuthComponent.vue index 6d00f30..8cff68f 100644 --- a/client/src/components/routes/auth/AuthComponent.vue +++ b/client/src/components/routes/auth/AuthComponent.vue @@ -39,12 +39,23 @@ const login = ref(""), password = ref(""); async function doLogin() { - // await devLogin(); - toaster.addToast({ - title: "Выполнено", - body: "Вы вошли в аккаунт", - type: ToastTypes.primary, - }); + try { + await userStore.login(login.value, login.password); + toaster.addToast({ + title: "Выполнено", + body: "Вы вошли в аккаунт", + type: ToastTypes.primary, + }); + router.push({ name: routeNames.Home }); + } + catch (err) { + toaster.addToast({ + title: "Ошибка", + body: "Неверные данные", + type: ToastTypes.danger, + }); + } + } async function devLogin() { From 2f8e9d15b71ac49078f1c99f2da14b4f704a77c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=B2=D1=8B=D0=B4=D0=BE=D0=B2=20=D0=9C=D0=B8?= =?UTF-8?q?=D1=85=D0=B0=D0=B8=D0=BB?= <71800457+dart-mih@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:17:11 +0300 Subject: [PATCH 5/5] fix: fixed type --- client/src/components/routes/auth/AuthComponent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/routes/auth/AuthComponent.vue b/client/src/components/routes/auth/AuthComponent.vue index 8cff68f..8f4681a 100644 --- a/client/src/components/routes/auth/AuthComponent.vue +++ b/client/src/components/routes/auth/AuthComponent.vue @@ -40,7 +40,7 @@ const login = ref(""), async function doLogin() { try { - await userStore.login(login.value, login.password); + await userStore.login(login.value, password.value); toaster.addToast({ title: "Выполнено", body: "Вы вошли в аккаунт",