n8n
Version:
n8n Workflow Automation Tool
29 lines • 1.51 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleEmailLogin = void 0;
const password_utility_1 = require("../../services/password.utility");
const typedi_1 = require("typedi");
const InternalHooks_1 = require("../../InternalHooks");
const helpers_1 = require("../../Ldap/helpers");
const user_repository_1 = require("../../databases/repositories/user.repository");
const auth_error_1 = require("../../errors/response-errors/auth.error");
const handleEmailLogin = async (email, password) => {
var _a;
const user = await typedi_1.Container.get(user_repository_1.UserRepository).findOne({
where: { email },
relations: ['authIdentities'],
});
if ((user === null || user === void 0 ? void 0 : user.password) && (await typedi_1.Container.get(password_utility_1.PasswordUtility).compare(password, user.password))) {
return user;
}
const ldapIdentity = (_a = user === null || user === void 0 ? void 0 : user.authIdentities) === null || _a === void 0 ? void 0 : _a.find((i) => i.providerType === 'ldap');
if (user && ldapIdentity && !(0, helpers_1.isLdapLoginEnabled)()) {
void typedi_1.Container.get(InternalHooks_1.InternalHooks).userLoginFailedDueToLdapDisabled({
user_id: user.id,
});
throw new auth_error_1.AuthError('Reset your password to gain access to the instance.');
}
return undefined;
};
exports.handleEmailLogin = handleEmailLogin;
//# sourceMappingURL=email.js.map
;