EN-80: Fixing public endpoints
EN-83: Removing company_type from register process
This commit is contained in:
@@ -119,14 +119,13 @@ There is no timeout to confirm the email, but it is expected that the Fron End r
|
|||||||
|
|
||||||
If the checksum matches but the user is already registered, then this request will be rejected.
|
If the checksum matches but the user is already registered, then this request will be rejected.
|
||||||
|
|
||||||
Expects a body with the same data as the POST request, but adding the OTP received in the email, the company type decided by the user and the checksum generated by the POST request. It is important to noticed that company_type is case sensitive, the only options are either `Shipper` or `Carrier`. Here is an example:
|
Expects a body with the same data as the POST request, but adding the OTP received in the email, the company type decided by the user and the checksum generated by the POST request. Here is an example:
|
||||||
|
|
||||||
```{.json}
|
```{.json}
|
||||||
{
|
{
|
||||||
"email":"testing@etaviaporte.com",
|
"email":"testing@etaviaporte.com",
|
||||||
"password":"PasswordExample",
|
"password":"PasswordExample",
|
||||||
"otp":"OTP string",
|
"otp":"OTP string",
|
||||||
"company_type":"Shipper or Carrier",
|
|
||||||
"checksum":"Checksum generated in the POST request"
|
"checksum":"Checksum generated in the POST request"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ const create_account_schema = {
|
|||||||
email : { type : 'string' , maxLength : 256 },
|
email : { type : 'string' , maxLength : 256 },
|
||||||
password : { type : 'string', maxLength : 256},
|
password : { type : 'string', maxLength : 256},
|
||||||
otp : { type : 'string', maxLength : 6 },
|
otp : { type : 'string', maxLength : 6 },
|
||||||
company_type : { type : 'string', enum : ["Shipper" , "Carrier"] },
|
|
||||||
checksum : { type : 'string', maxLength : 32 }
|
checksum : { type : 'string', maxLength : 32 }
|
||||||
},
|
},
|
||||||
required : [ 'email', 'password' ]
|
required : [ 'email', 'password' ]
|
||||||
@@ -28,7 +27,7 @@ const create_account_schema = {
|
|||||||
const confirm_account_schema = {
|
const confirm_account_schema = {
|
||||||
type : 'object',
|
type : 'object',
|
||||||
properties : create_account_schema.properties,//Same properties
|
properties : create_account_schema.properties,//Same properties
|
||||||
required : [ 'email', 'password', 'otp', 'company_type', 'checksum' ]//Different requirements
|
required : [ 'email', 'password', 'otp', 'checksum' ]//Different requirements
|
||||||
};
|
};
|
||||||
|
|
||||||
const login_account_schema = {
|
const login_account_schema = {
|
||||||
@@ -168,7 +167,7 @@ const TryCreateAccount = async(req, res) => {
|
|||||||
const ConfirmAccount = async(req, res) => {
|
const ConfirmAccount = async(req, res) => {
|
||||||
try{
|
try{
|
||||||
if( validator.validate( req.body , confirm_account_schema ).valid ){
|
if( validator.validate( req.body , confirm_account_schema ).valid ){
|
||||||
const { email, password, otp, company_type, checksum } = req.body;
|
const { email, password, otp, checksum } = req.body;
|
||||||
|
|
||||||
const it_exists = await already_exists( email );
|
const it_exists = await already_exists( email );
|
||||||
if( it_exists ){
|
if( it_exists ){
|
||||||
@@ -181,7 +180,7 @@ const ConfirmAccount = async(req, res) => {
|
|||||||
return res.status(400).send({ error : "Wrong OTP" });
|
return res.status(400).send({ error : "Wrong OTP" });
|
||||||
}
|
}
|
||||||
|
|
||||||
await create_account( email, password, company_type );
|
await create_account( email, password );
|
||||||
|
|
||||||
const content = { user_name : email };
|
const content = { user_name : email };
|
||||||
const receiver = email;
|
const receiver = email;
|
||||||
|
|||||||
@@ -6,18 +6,11 @@ const UserModel = require( `${ROOT_PATH}/${MODELS_PATH}/users.model.js` );
|
|||||||
|
|
||||||
const pwd_secret = apiConfig.authentication.pwdSecret;
|
const pwd_secret = apiConfig.authentication.pwdSecret;
|
||||||
|
|
||||||
async function create_account( email, password, company_type ){
|
async function create_account( email, password ){
|
||||||
let permissions;
|
|
||||||
if( company_type === "Shipper"){
|
|
||||||
permissions = "role_shipper";
|
|
||||||
}else{
|
|
||||||
permissions = "role_carrier";
|
|
||||||
}
|
|
||||||
let safe_password = toSha256( password + pwd_secret );
|
let safe_password = toSha256( password + pwd_secret );
|
||||||
const user = new UserModel({
|
const user = new UserModel({
|
||||||
email,
|
email,
|
||||||
password : safe_password,
|
password : safe_password
|
||||||
permissions
|
|
||||||
});
|
});
|
||||||
await user.save();
|
await user.save();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,51 @@ function genKey( len = 6 , key="" ){
|
|||||||
return complete_string.substr(0 , len );
|
return complete_string.substr(0 , len );
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { genKey , toSha256 };
|
function getPagination( query ){
|
||||||
|
let limit = {
|
||||||
|
page : 0,
|
||||||
|
elements : 10
|
||||||
|
};
|
||||||
|
|
||||||
|
if( query.page ){
|
||||||
|
limit.page = parseInt( query.page ) || 0;
|
||||||
|
if( limit.page < 0 ){
|
||||||
|
limit.page = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( query.elements ){
|
||||||
|
limit.elements = parseInt( query.elements ) || 10;
|
||||||
|
/** Safe pagination limit */
|
||||||
|
if( limit.elements > 1000 ){
|
||||||
|
limit.elements = 1000;
|
||||||
|
}
|
||||||
|
else if( limit.elements < 0 ){
|
||||||
|
limit.elements = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getPage( page, elements, model, filter=null, projection=null){
|
||||||
|
const skip = elements * page;
|
||||||
|
const total = await model.count( filter );
|
||||||
|
const list = await model.find( filter , projection, { skip : skip , limit : elements } );
|
||||||
|
return {
|
||||||
|
total : total,
|
||||||
|
limit : elements,
|
||||||
|
skip : skip,
|
||||||
|
data : list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function queryPage(page, elements, model, filter=null, projection=null){
|
||||||
|
const skip = elements * page;
|
||||||
|
const total = await model.count( filter );
|
||||||
|
return {
|
||||||
|
query : model.find( filter , projection, { skip : skip , limit : elements } ),
|
||||||
|
total : total,
|
||||||
|
skip : skip
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { genKey , toSha256, getPagination, getPage, queryPage };
|
||||||
@@ -21,7 +21,7 @@ const schema = new Schema({
|
|||||||
password: { type: String , maxLength : 256 },
|
password: { type: String , maxLength : 256 },
|
||||||
phone: { type: String },
|
phone: { type: String },
|
||||||
phone2: { type: String },
|
phone2: { type: String },
|
||||||
permissions: [{ type: String, default: 'role_admin', enum : ['role_admin', 'role_shipper', 'role_carrier', 'role_driver' ] }],
|
permissions: [{ type: String, default: 'role_admin', enum : [ 'admin', 'role_admin', 'role_shipper', 'role_carrier', 'role_driver' ] }],
|
||||||
gender: { type: String },
|
gender: { type: String },
|
||||||
address: { type: String },
|
address: { type: String },
|
||||||
dob: { type: String },
|
dob: { type: String },
|
||||||
|
|||||||
Reference in New Issue
Block a user