Add manual token entry for Evotor connection
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -186,6 +186,67 @@ def evotor_link(
|
|||||||
return RedirectResponse("/connections", 303)
|
return RedirectResponse("/connections", 303)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/token")
|
||||||
|
async def evotor_token_manual(
|
||||||
|
request: Request,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
user: User | None = Depends(get_current_user),
|
||||||
|
):
|
||||||
|
"""Allow user to manually paste their Evotor token."""
|
||||||
|
if not user:
|
||||||
|
return RedirectResponse("/login", 303)
|
||||||
|
|
||||||
|
form = await request.form()
|
||||||
|
token = (form.get("token") or "").strip()
|
||||||
|
if not token:
|
||||||
|
return RedirectResponse("/evotor?error=empty_token", 303)
|
||||||
|
|
||||||
|
now = datetime.utcnow()
|
||||||
|
|
||||||
|
# Fetch store info
|
||||||
|
store_id = None
|
||||||
|
store_name = None
|
||||||
|
try:
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
stores_response = await client.get(
|
||||||
|
EVOTOR_STORES_URL,
|
||||||
|
headers={"Authorization": f"Bearer {token}"},
|
||||||
|
timeout=15,
|
||||||
|
)
|
||||||
|
if stores_response.status_code == 200:
|
||||||
|
stores = stores_response.json()
|
||||||
|
items = stores.get("items", stores) if isinstance(stores, dict) else stores
|
||||||
|
if items:
|
||||||
|
store_id = items[0].get("uuid") or items[0].get("id")
|
||||||
|
store_name = items[0].get("name")
|
||||||
|
elif stores_response.status_code == 401:
|
||||||
|
return RedirectResponse("/evotor?error=invalid_token", 303)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
connection = db.query(EvotorConnection).filter(EvotorConnection.user_id == user.id).first()
|
||||||
|
if connection:
|
||||||
|
connection.access_token = token
|
||||||
|
connection.store_id = store_id
|
||||||
|
connection.store_name = store_name
|
||||||
|
connection.is_online = True
|
||||||
|
connection.last_checked_at = now
|
||||||
|
connection.updated_at = now
|
||||||
|
else:
|
||||||
|
connection = EvotorConnection(
|
||||||
|
user_id=user.id,
|
||||||
|
access_token=token,
|
||||||
|
store_id=store_id,
|
||||||
|
store_name=store_name,
|
||||||
|
is_online=True,
|
||||||
|
last_checked_at=now,
|
||||||
|
)
|
||||||
|
db.add(connection)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
return RedirectResponse("/connections", 303)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/disconnect")
|
@router.post("/disconnect")
|
||||||
async def evotor_disconnect(
|
async def evotor_disconnect(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
<i class="bi bi-exclamation-triangle me-2"></i>Время ожидания истекло. Попробуйте подключить аккаунт заново.
|
<i class="bi bi-exclamation-triangle me-2"></i>Время ожидания истекло. Попробуйте подключить аккаунт заново.
|
||||||
{% elif error == "session_expired" %}
|
{% elif error == "session_expired" %}
|
||||||
<i class="bi bi-exclamation-triangle me-2"></i>Сессия устарела. Попробуйте подключить аккаунт заново.
|
<i class="bi bi-exclamation-triangle me-2"></i>Сессия устарела. Попробуйте подключить аккаунт заново.
|
||||||
|
{% elif error == "invalid_token" %}
|
||||||
|
<i class="bi bi-exclamation-triangle me-2"></i>Токен недействителен. Проверьте правильность и попробуйте снова.
|
||||||
|
{% elif error == "empty_token" %}
|
||||||
|
<i class="bi bi-exclamation-triangle me-2"></i>Введите токен.
|
||||||
{% else %}
|
{% else %}
|
||||||
<i class="bi bi-exclamation-triangle me-2"></i>Произошла ошибка при подключении: {{ error }}
|
<i class="bi bi-exclamation-triangle me-2"></i>Произошла ошибка при подключении: {{ error }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -54,8 +58,14 @@
|
|||||||
<button type="submit" class="btn btn-outline-danger w-100">Отключить аккаунт Эвотор</button>
|
<button type="submit" class="btn btn-outline-danger w-100">Отключить аккаунт Эвотор</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer text-muted small">
|
<div class="card-footer">
|
||||||
После переподключения нажмите <a href="/evotor/link">Подтвердить подключение</a>.
|
<p class="text-muted small mb-2">Обновить токен вручную (Личный кабинет Эвотор → <strong>Приложения → ЭвоСинк → Настройки</strong>):</p>
|
||||||
|
<form method="post" action="/evotor/token">
|
||||||
|
<div class="input-group input-group-sm">
|
||||||
|
<input type="text" name="token" class="form-control font-monospace" placeholder="Новый токен" required>
|
||||||
|
<button type="submit" class="btn btn-outline-secondary">Обновить</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
@@ -74,6 +84,15 @@
|
|||||||
<a href="/evotor/connect" class="btn btn-primary btn-lg">Подключить Эвотор</a>
|
<a href="/evotor/connect" class="btn btn-primary btn-lg">Подключить Эвотор</a>
|
||||||
<a href="/evotor/link" class="btn btn-outline-secondary">Уже авторизовался — подтвердить подключение</a>
|
<a href="/evotor/link" class="btn btn-outline-secondary">Уже авторизовался — подтвердить подключение</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr class="my-4">
|
||||||
|
<p class="text-muted small mb-2">Если приложение уже установлено, введите токен вручную. Его можно найти в личном кабинете Эвотор: <strong>Приложения → ЭвоСинк → Настройки</strong>.</p>
|
||||||
|
<form method="post" action="/evotor/token">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" name="token" class="form-control font-monospace" placeholder="Вставьте токен Эвотор" required>
|
||||||
|
<button type="submit" class="btn btn-outline-primary">Сохранить</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user