summaryrefslogtreecommitdiff
path: root/api/auth
diff options
context:
space:
mode:
Diffstat (limited to 'api/auth')
-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 {