Auth chain: - auth.proto: add needs_starter_deck to Login/Register/ValidateToken responses - auth.proto: add RevokeAllSessions RPC - AuthGrpcHandler: populate NeedsStarterDeck from Account.StarterDeckSelectedAt - AuthGrpcHandler: track tokens in UserSessions Redis SET on create/logout - AuthGrpcHandler: implement RevokeAllSessions (Redis + Postgres) - IGatewayAuthValidator / GatewayAuthValidator: thread NeedsStarterDeck through tuples - ConnectionLoop: include needsStarterDeck in auth ack payload Client: - Auth.gd: store needs_starter_deck from auth reply; clear on logout - login_screen.gd: route to StarterDeckScreen when needs_starter_deck = true - scenes/starter_deck/: new StarterDeckScreen (fetch decks → pick → confirm → InitScreen) Admin panel: - AccountDetail.razor: Force Logout All Sessions card (Redis + Postgres revoke) - AccountDetail.razor: Change Display Name form with uniqueness check - SOR.Admin: add StackExchange.Redis package + DI registration - PrebuiltDeckEditor.razor: split into IsStarterDeck + IsAvailableInShop checkboxes - PrebuiltDeck.cs: add IsAvailableInShop field - Migration: AddPrebuiltDeckShopFlag Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
124 lines
4.9 KiB
GDScript
124 lines
4.9 KiB
GDScript
extends Control
|
|
## Login / Register screen.
|
|
##
|
|
## Shown as the entry point before authentication. Uses two tabs:
|
|
## "Login" — email + password → auth.login
|
|
## "Register" — email + password + display name → auth.register
|
|
##
|
|
## Listens to Auth.auth_success and Auth.auth_failed.
|
|
## On success: transitions to InitScreen (which runs version check + content sync,
|
|
## then proceeds to MainScreen).
|
|
## On failure: shows an error message and re-enables the form.
|
|
|
|
# ── Node references (unique names set in the .tscn) ──────────────────────────
|
|
|
|
@onready var email_input : LineEdit = %EmailInput
|
|
@onready var password_input : LineEdit = %PasswordInput
|
|
@onready var login_btn : Button = %LoginBtn
|
|
|
|
@onready var reg_email_input : LineEdit = %RegEmailInput
|
|
@onready var reg_password_input : LineEdit = %RegPasswordInput
|
|
@onready var reg_name_input : LineEdit = %RegNameInput
|
|
@onready var register_btn : Button = %RegisterBtn
|
|
|
|
@onready var status_label : Label = %StatusLabel
|
|
|
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
|
|
|
func _ready() -> void:
|
|
# If already authenticated (e.g. scene reloaded), skip straight to main.
|
|
if not Auth.user_id.is_empty():
|
|
_go_to_main()
|
|
return
|
|
|
|
Auth.auth_success.connect(_on_auth_success)
|
|
Auth.auth_failed.connect(_on_auth_failed)
|
|
|
|
login_btn.pressed.connect(_on_login_pressed)
|
|
register_btn.pressed.connect(_on_register_pressed)
|
|
|
|
# Allow pressing Enter to submit the login form.
|
|
password_input.text_submitted.connect(func(_t): _on_login_pressed())
|
|
reg_name_input.text_submitted.connect(func(_t): _on_register_pressed())
|
|
|
|
# Show connection / session-resume status on first open.
|
|
if not Auth.session_token.is_empty():
|
|
_set_status("Resuming session…", false)
|
|
_set_enabled(false)
|
|
elif not Network.is_online():
|
|
_set_status("Connecting…", false)
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
if Auth.auth_success.is_connected(_on_auth_success):
|
|
Auth.auth_success.disconnect(_on_auth_success)
|
|
if Auth.auth_failed.is_connected(_on_auth_failed):
|
|
Auth.auth_failed.disconnect(_on_auth_failed)
|
|
|
|
# ── Button handlers ───────────────────────────────────────────────────────────
|
|
|
|
func _on_login_pressed() -> void:
|
|
var email := email_input.text.strip_edges()
|
|
var pass_ := password_input.text
|
|
if email.is_empty() or pass_.is_empty():
|
|
_set_status("Please enter your email and password.", true)
|
|
return
|
|
_set_status("Signing in…", false)
|
|
_set_enabled(false)
|
|
Auth.login(email, pass_)
|
|
|
|
|
|
func _on_register_pressed() -> void:
|
|
var email := reg_email_input.text.strip_edges()
|
|
var pass_ := reg_password_input.text
|
|
var name_ := reg_name_input.text.strip_edges()
|
|
if email.is_empty() or pass_.is_empty() or name_.is_empty():
|
|
_set_status("Please fill in all fields.", true)
|
|
return
|
|
_set_status("Creating account…", false)
|
|
_set_enabled(false)
|
|
Auth.register(email, pass_, name_)
|
|
|
|
# ── Auth signal handlers ──────────────────────────────────────────────────────
|
|
|
|
func _on_auth_success(_user_id: String, _display_name: String) -> void:
|
|
_go_to_main()
|
|
|
|
|
|
func _on_auth_failed(error_code: String, message: String) -> void:
|
|
if error_code == "DISCONNECTED":
|
|
_set_status("Connection lost. Retrying…", false)
|
|
else:
|
|
_set_status(_friendly_error(error_code, message), true)
|
|
_set_enabled(true)
|
|
|
|
# ── Helpers ───────────────────────────────────────────────────────────────────
|
|
|
|
func _go_to_main() -> void:
|
|
if Auth.needs_starter_deck:
|
|
get_tree().change_scene_to_file("res://scenes/starter_deck/StarterDeckScreen.tscn")
|
|
else:
|
|
get_tree().change_scene_to_file("res://scenes/init/InitScreen.tscn")
|
|
|
|
|
|
func _set_status(text: String, is_error: bool) -> void:
|
|
status_label.text = text
|
|
status_label.modulate = Color(1.0, 0.4, 0.4) if is_error else Color(0.8, 0.8, 0.8)
|
|
|
|
|
|
func _set_enabled(enabled: bool) -> void:
|
|
login_btn.disabled = not enabled
|
|
register_btn.disabled = not enabled
|
|
|
|
|
|
func _friendly_error(code: String, message: String) -> String:
|
|
match code:
|
|
"INVALID_CREDENTIALS": return "Wrong email or password."
|
|
"EMAIL_TAKEN": return "That email is already in use."
|
|
"WEAK_PASSWORD": return "Password must be at least 8 characters."
|
|
"INVALID_EMAIL": return "Please enter a valid email address."
|
|
"AUTH_FAILED": return "Authentication failed. Please try again."
|
|
_:
|
|
return message if not message.is_empty() \
|
|
else "Something went wrong (%s)." % code
|