Page MenuHomeSealhub

No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/app/base-chips/field-types/hashed-text.js b/lib/app/base-chips/field-types/hashed-text.js
index 3272e588..d8acc015 100644
--- a/lib/app/base-chips/field-types/hashed-text.js
+++ b/lib/app/base-chips/field-types/hashed-text.js
@@ -1,76 +1,77 @@
"use strict";
const Promise = require("bluebird");
const crypto = require("crypto");
module.exports = {
name: "hashed-text",
extends: "text",
get_description: function(context, params){
let message = "Hash text with chosen algorithm (default md5)";
if (params && Object.keys(params).length > 0){
message += " with ";
if (params.digits){
message += `required digits: ${params.digits} `;
}
if (params.capitals){
message += `required capitals: ${params.capitals} `;
}
}
return message;
},
is_proper_value: function(context, params, new_value){
const pattern_array = [];
if (params){
if (params.digits){
pattern_array.push(new RegExp(`(.*[0-9]+.*){${params.digits}}`));
}
if (params.capitals){
pattern_array.push(new RegExp(`(.*[A-Z]+.*){${params.capitals}}`));
}
const isAccepted = pattern_array.map(n => n.test(new_value)).reduce((a,b) => a && b, true);
if (isAccepted){
return Promise.resolve();
} else {
const digits = params.digits || "0";
const capitals = params.capitals || "0";
return Promise.reject(`It didn't fulfill the requirements: required digits - ${digits} , required capitals ${capitals}`);
}
} else {
return Promise.resolve();
}
},
encode: function(context, params, value_in_code){
let salt = "", algorithm = "md5";
if (params){
if (params.salt){
salt = params.salt;
}
else if (params.algorithm){
algorithm = params.algorithm;
}
}
return new Promise(function(resolve, reject){
crypto.pbkdf2(value_in_code, salt, 4096, 64, algorithm, function(err, key){
if (err){
reject(err);
} else {
resolve(key.toString("hex"));
}
});
});
},
+ get_aggregation_stages: require("./../../../chip-types/field-type-default-methods.js").get_aggregation_stages,
decode: function(context, params, value_in_db){
if (params && params.hide_hash){
return null;
} else {
return value_in_db;
}
},
};
diff --git a/lib/subject/predefined-subjects/sessions-subject.js b/lib/subject/predefined-subjects/sessions-subject.js
index 0066a2ad..e30a62f8 100644
--- a/lib/subject/predefined-subjects/sessions-subject.js
+++ b/lib/subject/predefined-subjects/sessions-subject.js
@@ -1,101 +1,101 @@
"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const CurrentSessionSubject = require("../subject-types/current-session-subject.js");
const SuperContext = locreq("lib/super-context.js");
const Errors = locreq("lib/response/error.js");
const Responses = locreq("lib/response/responses.js");
const Subject = locreq("lib/subject/subject.js");
function is_auth_data_valid (app, username, password){
return app.run_action(
new SuperContext(),
["collections", "users"],
"show",
{filter:{username: username, password: password}}
).then(function(results){
- if (results.length === 1){
+ if (results.length !== 0){
return results[0];
} else {
throw new Errors.InvalidCredentials("User/password mismatch");
}
});
}
function user_exists (username){
return new SuperContext()
.run_action(
["users", username],
"show"
);
}
function attemp_login (app, context, params){
let username, password;
let user;
let session;
return Promise.try(function(){
username = params.username;
password = params.password;
if (!username){
throw new Errors.InvalidCredentials("Missing username!");
}
if (!password){
throw new Errors.InvalidCredentials("Missing password!");
}
})
.then(function(){
return is_auth_data_valid(app, username, password)
.catch({type: "not_found"}, function(e){
return user_exists(username)
.then(function(){
throw new Errors.InvalidCredentials("Bad password");
})
.catch(Errors.Error, function(e){
throw new Errors.InvalidCredentials("Bad username");
});
});
})
.then(function(user_arg){
user = user_arg;
return app.run_action(new SuperContext(), ["collections", "sessions"], "create", {user: user.id, "session-id": null});
})
.then(function(session_arg){
session = session_arg;
return app.run_action(new SuperContext(), ["collections", "users", user.id], "edit", {last_login_context: context});
})
.then(function(){
return new Responses.NewSession(session.body["session-id"]);
});
}
const SessionsSubject = function(app){
this.perform_action = function(context, action_name, params){
params = params || {};
switch (action_name){
case "create":
return attemp_login(app, context, params);
default:
throw new Errors.DeveloperError(`Unknown/unsupported action '${action_name}' for Session Subject.`);
}
};
this.get_child_subject = function(key){
switch (key){
case "current":
return new CurrentSessionSubject(app);
default:
throw new Errors.BadSubjectPath(`No child subject with key '${key}' in SessionSubject`);
}
};
};
SessionsSubject.prototype = Object.create(Subject.prototype);
SessionsSubject.subject_name = "sessions";
module.exports = SessionsSubject;

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 28, 03:15 (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1218073
Default Alt Text
(5 KB)

Event Timeline