UNPKG

1.29 kBJavaScriptView Raw
1/**
2 * joola.io
3 *
4 * Copyright Joola Smart Solutions, Ltd. <info@joo.la>
5 *
6 * Licensed under GNU General Public License 3.0 or later.
7 * Some rights reserved. See LICENSE, AUTHORS.
8 *
9 * @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
10 */
11
12var
13 _datatables = require('../objects/datatables'),
14 connector = require('../connectors/connector');
15
16exports.login = function (username, password, next) {
17 var auth = joola.config.auth;
18 var orgs = auth.organizations;
19 var user;
20
21 joola.logger.silly('Joola login attempt [' + username + ']...');
22
23 _.each(orgs, function (org) {
24 if (!user) {
25 user = _.find(org.users, function (u) {
26 return u._username == username;
27 });
28 }
29 });
30
31 if (user) {
32 if (user._password == password) {
33 joola.logger.silly('Joola authentication success [' + username + ']...');
34 return next(null, user);
35 }
36 else {
37 var message = 'Failed to authenticate with Joola [' + username + ']: wrong password';
38 joola.logger.warn(message);
39 return next(new Error(message));
40 }
41 }
42 else {
43 var message = 'Failed to authenticate with Joola [' + username + ']: user not found';
44 joola.logger.warn(message);
45 return next(new Error(message));
46 }
47}
\No newline at end of file