import { createUserAccountAndChannelAndPlaylist } from './user'
import { UserRole } from '@shared/models/users/user-role'
import { PluginManager } from '@server/lib/plugins/plugin-manager'
+import { ActorModel } from '@server/models/activitypub/actor'
type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date }
let user = await UserModel.loadByEmail(obj.user.email)
if (!user) user = await createUserFromExternal(obj.pluginName, obj.user)
+ // Cannot create a user
+ if (!user) throw new AccessDeniedError('Cannot create such user: an actor with that name already exists.')
+
// If the user does not belongs to a plugin, it was created before its installation
// Then we just go through a regular login process
if (user.pluginAuth !== null) {
const user = await UserModel.loadByUsernameOrEmail(usernameOrEmail)
// If we don't find the user, or if the user belongs to a plugin
- if (!user || user.pluginAuth !== null) return null
+ if (!user || user.pluginAuth !== null || !password) return null
const passwordMatch = await user.isPasswordMatch(password)
if (passwordMatch !== true) return null
}
const tokenCreated = await OAuthTokenModel.create(tokenToCreate)
+
+ user.lastLoginDate = new Date()
+ await user.save()
+
return Object.assign(tokenCreated, { client, user })
}
role: UserRole
displayName: string
}) {
+ // Check an actor does not already exists with that name (removed user)
+ const actor = await ActorModel.loadLocalByName(options.username)
+ if (actor) return null
+
const userToCreate = new UserModel({
username: options.username,
password: null,