Menu "Ganti password" menjadi "Pengaturan" + panduan menghubungkan akun Google

- Menu profil kini "Pengaturan" (ikon settings); halaman berjudul Pengaturan dengan
  kartu Akun Google di atas kartu Ganti password.
- Masuk dengan Google yang belum terhubung tidak lagi berupa galat merah: halaman login
  menampilkan pengumuman langkah (masuk NIP/NPM → Pengaturan → Hubungkan akun Google),
  dan masuk NIP/NPM dari halaman itu langsung diteruskan ke Pengaturan #akun-google.
- Uji: pengumuman, penerusan ke Pengaturan, label menu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Power BI Dev
2026-10-18 08:44:23 +07:00
co-authored by Claude Opus 5.5
parent 080f6bf9ab
commit 602a9c98b9
5 changed files with 59 additions and 28 deletions
+15 -6
View File
@@ -198,11 +198,12 @@ async def setup_simpan(request: Request):
@app.get("/login", response_class=HTMLResponse)
def login_form(request: Request, pesan: str = ""):
def login_form(request: Request, pesan: str = "", info: str = ""):
if not db.ada_pengguna():
return RedirectResponse("/setup", status_code=303)
return render(request, "login.html",
{"mode": "login", "pesan": pesan[:300], "tahun": db.tahun_aktif()})
{"mode": "login", "pesan": pesan[:300], "tahun": db.tahun_aktif(),
"info": "hubung" if info == "hubung" else ""})
@app.post("/login")
@@ -224,8 +225,14 @@ async def login_proses(request: Request):
if not p:
return render(request, "login.html",
{"mode": "login", "tahun": db.tahun_aktif(),
"info": "hubung" if form.get("lanjut") == "pengaturan" else "",
"pesan": "NIP/NPM atau password salah."})
return _masuk(p["id"])
r = _masuk(p["id"])
if form.get("lanjut") == "pengaturan": # datang dari "akun Google belum terhubung"
r.headers["location"] = ("/akun?pesan=" + quote_plus("Anda sudah masuk. Klik Hubungkan akun Google di bawah, "
"lalu berikutnya cukup Masuk dengan Google UNTAN.")
+ "#akun-google")
return r
@app.post("/peran")
@@ -265,7 +272,7 @@ async def akun_simpan(request: Request):
# ═════════════════════════ LOGIN GOOGLE (app/google_auth.py) ═════════════════════════
# Satu alur OAuth untuk dua tujuan: "masuk" (halaman login) dan "hubung" (menu Akun, pengguna
# Satu alur OAuth untuk dua tujuan: "masuk" (halaman login) dan "hubung" (menu Pengaturan, pengguna
# sudah login). state & nonce disimpan di cookie singkat HttpOnly dan dicocokkan saat callback.
_COOKIE_G = "g_oauth"
@@ -332,8 +339,10 @@ def google_kembali(request: Request, code: str = "", state: str = "", error: str
if p:
db.hubungkan_google(p["id"], g["sub"], g["email"])
if not p:
return gagal(f"Akun Google {g['email']} belum terhubung ke akun aplikasi. Masuk dengan NIP/NPM, "
"lalu hubungkan di menu Akun — atau minta kaprodi mendaftarkan email Anda.")
r = RedirectResponse("/login?info=hubung&pesan=" + quote_plus(
f"{g['email']} belum terhubung ke akun aplikasi (atau email ini belum terdaftar)."), status_code=303)
r.delete_cookie(_COOKIE_G)
return r
r = _masuk(p["id"])
r.delete_cookie(_COOKIE_G)
return r