Add last login tracking, batch date auto-fill, and bug fixes

- Track last_login_at on User model, updated on every successful login
- Show last login date in admin panel user table
- Fix admin/garden date display (datetime strings already contain T separator)
- Fix My Garden Internal Server Error (MySQL does not support NULLS LAST syntax)
- Fix Log Batch infinite loop when user has zero varieties
- Auto-fill batch dates from today when creating a new batch, calculated
  from selected variety's week offsets (germination, greenhouse, garden)
- Update README with new features and batch date auto-fill formula table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 00:48:04 -07:00
parent bd2bd43395
commit 84e7b13575
8 changed files with 78 additions and 14 deletions

View File

@@ -1,3 +1,5 @@
from datetime import datetime, timezone
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
@@ -48,6 +50,8 @@ def login(data: UserLogin, db: Session = Depends(get_db)):
raise HTTPException(status_code=401, detail="Invalid email or password")
if user.is_disabled:
raise HTTPException(status_code=403, detail="Account has been disabled")
user.last_login_at = datetime.now(timezone.utc)
db.commit()
return {"access_token": create_access_token(user.id), "token_type": "bearer"}