diff --git a/config.ts b/config.ts index 4e4eff83..17a0e418 100644 --- a/config.ts +++ b/config.ts @@ -10,6 +10,7 @@ export class Config { export class Security { public static isAutheticationEnabled = "disabled";//allowed values: "disabled","enabledWithoutAuthorization","enabledWithAuthorization" public static authenticationType = "passwordBased";//allowed values: "passwordBased","TokenBased" + public static useFaceBookAuth = false; } export class facebookAuth { diff --git a/core/dynamic/dynamic-controller.ts b/core/dynamic/dynamic-controller.ts index 2f97b239..7d9ba4cb 100644 --- a/core/dynamic/dynamic-controller.ts +++ b/core/dynamic/dynamic-controller.ts @@ -104,7 +104,7 @@ export class DynamicController { Enumerable.from(association).forEach(x => { this.getHalModel1(x, resourceName + '/' + x['_id'], req, repo); }); - association = this.getHalModels(association, resourceName); + //association = this.getHalModels(association, resourceName); } else { this.getHalModel1(association, resourceName + '/' + association['_id'], req, repo); @@ -128,7 +128,7 @@ export class DynamicController { this.getHalModel1(x, resourceName + '/' + x['_id'], req, repo); }); - result = this.getHalModels(result, resourceName); + //result = this.getHalModels(result, resourceName); } else { result = result[0]; @@ -582,19 +582,21 @@ export class DynamicController { relUrl["href"] = resourceName + "/" + relation.propertyKey; model["_links"][relation.propertyKey] = relUrl; var repo = GetRepositoryForName(relation.params.rel); - var param = relation.params; - if (!param.embedded && !param.eagerLoading) { return model }; - if (model[relation.propertyKey] instanceof Array) { - if (model[relation.propertyKey] && model[relation.propertyKey].length) { - model[relation.propertyKey].forEach(key => { - var url = this.getFullBaseUrlUsingRepo(req, repo.modelName()); - this.getHalModel1(key, url + '/' + key['_id'], req, repo); - }); - } - } else { - if (model[relation.propertyKey]) { + if (repo) { + var param = relation.params; + if (!param.embedded && !param.eagerLoading) { return model }; + if (model[relation.propertyKey] instanceof Array) { + if (model[relation.propertyKey] && model[relation.propertyKey].length) { + model[relation.propertyKey].forEach(key => { + var url = this.getFullBaseUrlUsingRepo(req, repo.modelName()); + this.getHalModel1(key, url + '/' + key['_id'], req, repo); + }); + } + } else { + if (model[relation.propertyKey]) { var url = this.getFullBaseUrlUsingRepo(req, repo.modelName()); this.getHalModel1(model[relation.propertyKey], url + '/' + model[relation.propertyKey]['_id'], req, repo); + } } } }); diff --git a/mongoose/mongoose-model.ts b/mongoose/mongoose-model.ts index 7bbb1e19..22a4190d 100644 --- a/mongoose/mongoose-model.ts +++ b/mongoose/mongoose-model.ts @@ -21,7 +21,7 @@ export function bulkPost(model: Mongoose.Model, objArr: Array): Q.Prom Enumerable.from(objArr).forEach(obj => { var cloneObj = removeTransientProperties(model, obj); clonedModels.push(cloneObj); - addChildModel.push(addChildModelToParent(model, cloneObj)); + addChildModel.push(addChildModelToParent(model, cloneObj, null)); }); return Q.allSettled(addChildModel) @@ -129,7 +129,7 @@ export function findChild(model: Mongoose.Model, id, prop): Q.Promise */ export function post(model: Mongoose.Model, obj: any): Q.Promise { let clonedObj = removeTransientProperties(model, obj); - return addChildModelToParent(model, clonedObj) + return addChildModelToParent(model, clonedObj, null) .then(result => { try { autogenerateIdsForAutoFields(model, clonedObj); @@ -167,7 +167,7 @@ export function del(model: Mongoose.Model, id: any): Q.Promise { export function put(model: Mongoose.Model, id: any, obj: any): Q.Promise { let clonedObj = removeTransientProperties(model, obj); // First update the any embedded property and then update the model - return addChildModelToParent(model, clonedObj).then(result => { + return addChildModelToParent(model, clonedObj, id).then(result => { var updatedProps = getUpdatedProps(clonedObj); return Q.nbind(model.findOneAndUpdate, model)({ '_id': id }, clonedObj, { upsert: true, new: true }) .then(result => { @@ -187,7 +187,7 @@ export function put(model: Mongoose.Model, id: any, obj: any): Q.Promise, id: any, obj): Q.Promise { let clonedObj = removeTransientProperties(model, obj); // First update the any embedded property and then update the model - return addChildModelToParent(model, clonedObj).then(result => { + return addChildModelToParent(model, clonedObj, id).then(result => { var updatedProps = getUpdatedProps(clonedObj); return Q.nbind(model.findOneAndUpdate, model)({ '_id': id }, updatedProps, { new: true }) .then(result => { @@ -605,7 +605,7 @@ function updateEntity(targetModel: Object, propKey: string, targetPropArray: boo * @param model * @param obj */ -function addChildModelToParent(model: Mongoose.Model, obj: any) { +function addChildModelToParent(model: Mongoose.Model, obj: any, id: any) { var asyncCalls = []; for (var prop in obj) { var metaArr = MetaUtils.getMetaDataForPropKey(getEntity(model.modelName), prop); @@ -623,7 +623,7 @@ function addChildModelToParent(model: Mongoose.Model, obj: any) { asyncCalls.push(embedChild(obj, prop, relationDecoratorMeta[0])); } return Q.all(asyncCalls).then(x => { - return isDataValid(model, obj, null); + return isDataValid(model, obj, id); }); } diff --git a/security/auth/auth-service.ts b/security/auth/auth-service.ts index b0f73273..a86049e4 100644 --- a/security/auth/auth-service.ts +++ b/security/auth/auth-service.ts @@ -19,39 +19,43 @@ export class AuthService { private userDetailService: UserDetailService; constructor() { - this.addRoutes(); + if (configUtil.config().Security.useFaceBookAuth == true) { + this.addRoutes(); + } } authenticate() { this.authenticateByPasswordorToken(); - this.facebookAuthentication(); + if (configUtil.config().Security.useFaceBookAuth == true) { + this.facebookAuthentication(); + } } private authenticateByPasswordorToken() { - passport.use(new LocalStrategy( - (username, password, done) => { - this.userDetailService.loadUserByUsername(username).then( - (user) => { - if (!user) { - return done(null, false, { message: 'Incorrect username.' }); - } - if (user.getPassword() != password) { - return done(null, false, { message: 'Incorrect password.' }); - } - - return done(null, user.getUserObject()); - - }, - (error) => { - return done(error); - }); + passport.use(new LocalStrategy( + (username, password, done) => { + this.userDetailService.loadUserByUsername(username).then( + (user) => { + if (!user) { + return done(null, false, { message: 'Incorrect username.' }); + } + if (user.getPassword() != password) { + return done(null, false, { message: 'Incorrect password.' }); + } - } + return done(null, user.getUserObject()); + + }, + (error) => { + return done(error); + }); + + } )); - this.serializeDeserialize(); + // this.serializeDeserialize(); + - } private serializeDeserialize() {