This commit is contained in:
syuilo
2020-02-01 07:16:52 +09:00
parent d355f3f77c
commit 7ed3448e13
19 changed files with 152 additions and 216 deletions

View File

@ -35,7 +35,7 @@ export default define(meta, async (ps, user) => {
throw new Error('not verified');
}
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
twoFactorSecret: profile.twoFactorTempSecret,
twoFactorEnabled: true
});

View File

@ -34,7 +34,7 @@ export default define(meta, async (ps, user) => {
length: 32
});
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
twoFactorTempSecret: secret.base32
});

View File

@ -26,7 +26,7 @@ export default define(meta, async (ps, user) => {
throw new Error('incorrect password');
}
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
twoFactorSecret: null,
twoFactorEnabled: false
});

View File

@ -34,7 +34,7 @@ export default define(meta, async (ps, user) => {
const salt = await bcrypt.genSalt(8);
const hash = await bcrypt.hash(ps.newPassword, salt);
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
password: hash
});
});

View File

@ -49,7 +49,7 @@ export default define(meta, async (ps, user) => {
throw new ApiError(meta.errors.incorrectPassword);
}
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
email: ps.email,
emailVerified: false,
emailVerifyCode: null
@ -66,7 +66,7 @@ export default define(meta, async (ps, user) => {
if (ps.email != null) {
const code = rndstr('a-z0-9', 16);
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
emailVerifyCode: code
});

View File

@ -268,7 +268,7 @@ export default define(meta, async (ps, user, app) => {
//#endregion
if (Object.keys(updates).length > 0) await Users.update(user.id, updates);
if (Object.keys(profileUpdates).length > 0) await UserProfiles.update({ userId: user.id }, profileUpdates);
if (Object.keys(profileUpdates).length > 0) await UserProfiles.update(user.id, profileUpdates);
const iObj = await Users.pack(user.id, user, {
detail: true,

View File

@ -54,7 +54,7 @@ export default define(meta, async (ps, me) => {
const profile = await UserProfiles.findOne(user.id).then(ensure);
if (profile.room.furnitures == null) {
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
room: {
furnitures: [],
...profile.room
@ -66,7 +66,7 @@ export default define(meta, async (ps, me) => {
if (profile.room.roomType == null) {
const initialType = 'default';
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
room: {
roomType: initialType as any,
...profile.room
@ -78,7 +78,7 @@ export default define(meta, async (ps, me) => {
if (profile.room.carpetColor == null) {
const initialColor = '#85CAF0';
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
room: {
carpetColor: initialColor as any,
...profile.room

View File

@ -32,7 +32,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
await UserProfiles.update({ userId: user.id }, {
await UserProfiles.update(user.id, {
room: ps.room as any
});

View File

@ -46,16 +46,12 @@ router.get('/disconnect/discord', async ctx => {
token: userToken
}).then(ensure);
await UserProfiles.update({
userId: user.id
}, {
discord: false,
discordAccessToken: null,
discordRefreshToken: null,
discordExpiresDate: null,
discordId: null,
discordUsername: null,
discordDiscriminator: null,
const profile = await UserProfiles.findOne(user.id).then(ensure);
delete profile.integrations.discord;
await UserProfiles.update(user.id, {
integrations: profile.integrations,
});
ctx.body = `Discordの連携を解除しました :v:`;
@ -203,7 +199,7 @@ router.get('/dc/cb', async ctx => {
}
const profile = await UserProfiles.createQueryBuilder()
.where('"discordId" = :id', { id: id })
.where('"integrations"->"discord"->"id" = :id', { id: id })
.andWhere('"userHost" IS NULL')
.getOne();
@ -212,13 +208,17 @@ router.get('/dc/cb', async ctx => {
return;
}
await UserProfiles.update({ userId: profile.userId }, {
discord: true,
discordAccessToken: accessToken,
discordRefreshToken: refreshToken,
discordExpiresDate: expiresDate,
discordUsername: username,
discordDiscriminator: discriminator
await UserProfiles.update(profile.userId, {
integrations: {
...profile.integrations,
discord: {
accessToken: accessToken,
refreshToken: refreshToken,
expiresDate: expiresDate,
username: username,
discriminator: discriminator
}
},
});
signin(ctx, await Users.findOne(profile.userId) as ILocalUser, true);
@ -284,14 +284,20 @@ router.get('/dc/cb', async ctx => {
token: userToken
}).then(ensure);
await UserProfiles.update({ userId: user.id }, {
discord: true,
discordAccessToken: accessToken,
discordRefreshToken: refreshToken,
discordExpiresDate: expiresDate,
discordId: id,
discordUsername: username,
discordDiscriminator: discriminator
const profile = await UserProfiles.findOne(user.id).then(ensure);
await UserProfiles.update(user.id, {
integrations: {
...profile.integrations,
discord: {
accessToken: accessToken,
refreshToken: refreshToken,
expiresDate: expiresDate,
id: id,
username: username,
discriminator: discriminator
}
}
});
ctx.body = `Discord: @${username}#${discriminator} を、Misskey: @${user.username} に接続しました!`;

View File

@ -46,13 +46,12 @@ router.get('/disconnect/github', async ctx => {
token: userToken
}).then(ensure);
await UserProfiles.update({
userId: user.id
}, {
github: false,
githubAccessToken: null,
githubId: null,
githubLogin: null,
const profile = await UserProfiles.findOne(user.id).then(ensure);
delete profile.integrations.github;
await UserProfiles.update(user.id, {
integrations: profile.integrations,
});
ctx.body = `GitHubの連携を解除しました :v:`;
@ -193,7 +192,7 @@ router.get('/gh/cb', async ctx => {
}
const link = await UserProfiles.createQueryBuilder()
.where('"githubId" = :id', { id: id })
.where('"integrations"->"github"->"id" = :id', { id: id })
.andWhere('"userHost" IS NULL')
.getOne();
@ -260,11 +259,17 @@ router.get('/gh/cb', async ctx => {
token: userToken
}).then(ensure);
await UserProfiles.update({ userId: user.id }, {
github: true,
githubAccessToken: accessToken,
githubId: id,
githubLogin: login,
const profile = await UserProfiles.findOne(user.id).then(ensure);
await UserProfiles.update(user.id, {
integrations: {
...profile.integrations,
github: {
accessToken: accessToken,
id: id,
login: login,
}
}
});
ctx.body = `GitHub: @${login} を、Misskey: @${user.username} に接続しました!`;

View File

@ -45,14 +45,12 @@ router.get('/disconnect/twitter', async ctx => {
token: userToken
}).then(ensure);
await UserProfiles.update({
userId: user.id
}, {
twitter: false,
twitterAccessToken: null,
twitterAccessTokenSecret: null,
twitterUserId: null,
twitterScreenName: null,
const profile = await UserProfiles.findOne(user.id).then(ensure);
delete profile.integrations.twitter;
await UserProfiles.update(user.id, {
integrations: profile.integrations,
});
ctx.body = `Twitterの連携を解除しました :v:`;
@ -141,7 +139,7 @@ router.get('/tw/cb', async ctx => {
const result = await twAuth!.done(JSON.parse(twCtx), ctx.query.oauth_verifier);
const link = await UserProfiles.createQueryBuilder()
.where('"twitterUserId" = :id', { id: result.userId })
.where('"integrations"->"twitter"->"userId" = :id', { id: result.userId })
.andWhere('"userHost" IS NULL')
.getOne();
@ -174,12 +172,18 @@ router.get('/tw/cb', async ctx => {
token: userToken
}).then(ensure);
await UserProfiles.update({ userId: user.id }, {
twitter: true,
twitterAccessToken: result.accessToken,
twitterAccessTokenSecret: result.accessTokenSecret,
twitterUserId: result.userId,
twitterScreenName: result.screenName,
const profile = await UserProfiles.findOne(user.id).then(ensure);
await UserProfiles.update(user.id, {
integrations: {
...profile.integrations,
twitter: {
accessToken: result.accessToken,
accessTokenSecret: result.accessTokenSecret,
userId: result.userId,
screenName: result.screenName,
}
},
});
ctx.body = `Twitter: @${result.screenName} を、Misskey: @${user.username} に接続しました!`;