mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-08 03:36:37 +00:00
Prefix usernames
This commit is contained in:
@@ -176,7 +176,7 @@ export async function signSshKey(
|
|||||||
} else if (req.user?.username) {
|
} else if (req.user?.username) {
|
||||||
usernameToUse = req.user.username;
|
usernameToUse = req.user.username;
|
||||||
// We need to clean out any spaces or special characters from the username to ensure it's valid for SSH certificates
|
// We need to clean out any spaces or special characters from the username to ensure it's valid for SSH certificates
|
||||||
usernameToUse = usernameToUse.replace(/[^a-zA-Z0-9_-]/g, "");
|
usernameToUse = usernameToUse.replace(/[^a-zA-Z0-9_-]/g, "-");
|
||||||
if (!usernameToUse) {
|
if (!usernameToUse) {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
@@ -185,17 +185,6 @@ export async function signSshKey(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// save it to the database for future use so we dont have to keep doing this
|
|
||||||
await db
|
|
||||||
.update(userOrgs)
|
|
||||||
.set({ pamUsername: usernameToUse })
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(userOrgs.orgId, orgId),
|
|
||||||
eq(userOrgs.userId, userId)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
@@ -205,6 +194,9 @@ export async function signSshKey(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prefix with p-
|
||||||
|
usernameToUse = `p-${usernameToUse}`;
|
||||||
|
|
||||||
// check if we have a existing user in this org with the same
|
// check if we have a existing user in this org with the same
|
||||||
const [existingUserWithSameName] = await db
|
const [existingUserWithSameName] = await db
|
||||||
.select()
|
.select()
|
||||||
@@ -250,6 +242,16 @@ export async function signSshKey(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.update(userOrgs)
|
||||||
|
.set({ pamUsername: usernameToUse })
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userOrgs.orgId, orgId),
|
||||||
|
eq(userOrgs.userId, userId)
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
usernameToUse = userOrg.pamUsername;
|
usernameToUse = userOrg.pamUsername;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user