summaryrefslogtreecommitdiff
path: root/api/auth/auth.go
diff options
context:
space:
mode:
authorAlexander Hunt <me@liz.coffee>2026-06-21 12:43:31 -0700
committerAlexander Hunt <me@liz.coffee>2026-06-21 12:43:31 -0700
commitcfc0d34a584254a9ed76620951c810771aff6f3b (patch)
tree7fba034f7347ce0003e7a3a56adcaf862c834907 /api/auth/auth.go
parentfb653292612eddca5b088ed88466c546d1597107 (diff)
downloadpenguins.lan-cfc0d34a584254a9ed76620951c810771aff6f3b.tar.gz
penguins.lan-cfc0d34a584254a9ed76620951c810771aff6f3b.zip
STUFF
Diffstat (limited to 'api/auth/auth.go')
-rw-r--r--api/auth/auth.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/api/auth/auth.go b/api/auth/auth.go
index a70af32..78123a6 100644
--- a/api/auth/auth.go
+++ b/api/auth/auth.go
@@ -141,11 +141,20 @@ func RenameContinuation(context *types.RequestContext, req *http.Request, resp h
return renameError("something broke, try again")
}
+ oldName := context.User.Username
if err := database.RenameUser(context.DBConn, context.User.ID, newName); err != nil {
log.Println("rename failed:", err)
return renameError("couldn't rename, try again")
}
+ // Device records are synthesized from the current username and follow
+ // the rename for free; stored records have the old name baked in, so
+ // move them to the new subdomain to keep the user's setup working.
+ zone := context.Args.DnsZone
+ if err := database.RenameUserDNSDomain(context.DBConn, context.User.ID, oldName+"."+zone, newName+"."+zone); err != nil {
+ log.Println("rename dns records failed:", err)
+ }
+
context.User.Username = newName
context.Nick = newName
http.Redirect(resp, req, "/", http.StatusSeeOther)
@@ -272,6 +281,12 @@ func bindAndFinish(context *types.RequestContext, resp http.ResponseWriter, user
if err := database.AssociateMAC(context.DBConn, mac, user.ID); err != nil {
log.Println("associate mac failed:", err)
}
+ // First device a user binds becomes their primary automatically. The
+ // conditional update is atomic, so this stays correct even if two
+ // devices bind concurrently.
+ if err := database.SetPrimaryMACIfUnset(context.DBConn, user.ID, mac); err != nil {
+ log.Println("set primary mac failed:", err)
+ }
}
_ = database.TouchUser(context.DBConn, user.ID)
if err := LoginUser(context, resp, user); err != nil {