mirror of
https://git.cloudron.io/cloudron/mastodon-app.git
synced 2024-12-22 22:26:27 +00:00
migrateUsers.js updated to use username instead of email
This commit is contained in:
parent
e556c856f1
commit
a08af787d7
1 changed files with 6 additions and 6 deletions
|
@ -26,20 +26,20 @@ const users = {};
|
|||
|
||||
let userId;
|
||||
for (let line of ldapSearchOutput.split('\n')) {
|
||||
if (line.startsWith('mail:')) userId = line.split(':')[1].trim();
|
||||
if (line.startsWith('uid:')) userId = line.split(':')[1].trim();
|
||||
if (line.startsWith('username:')) users[userId] = line.split(':')[1].trim();
|
||||
}
|
||||
|
||||
console.log('Found usermapping:', users);
|
||||
|
||||
for (let email in users) {
|
||||
let uid = execSync(`${postgresCmd} -AXqtc "SELECT id FROM users WHERE email='${email}'"`).toString().trim();
|
||||
for (let id in users) {
|
||||
let uid = execSync(`${postgresCmd} -AXqtc "SELECT u.id FROM users u JOIN accounts a ON a.id=u.account_id WHERE a.username='${users[id]}'"`).toString().trim();
|
||||
if (!uid)
|
||||
continue;
|
||||
|
||||
console.log(`Migrate ${email}/${users[email]} to OIDC`);
|
||||
execSync(`${postgresCmd} -c "INSERT INTO identities (provider, uid, user_id, created_at, updated_at) VALUES ('openid_connect', '${users[email]}', ${uid}, NOW(), NOW())"`);
|
||||
console.log(`"INSERT INTO identities (provider, uid, user_id, created_at, updated_at) VALUES ('openid_connect', '${users[email]}', ${uid}, NOW(), NOW())"`);
|
||||
console.log(`Migrate ${users[id]} to OIDC`);
|
||||
execSync(`${postgresCmd} -c "INSERT INTO identities (provider, uid, user_id, created_at, updated_at) VALUES ('openid_connect', '${users[id]}', ${uid}, NOW(), NOW())"`);
|
||||
console.log(`"INSERT INTO identities (provider, uid, user_id, created_at, updated_at) VALUES ('openid_connect', '${users[id]}', ${uid}, NOW(), NOW())"`);
|
||||
}
|
||||
|
||||
console.log('Done');
|
||||
|
|
Loading…
Reference in a new issue