Skip to content

Commit

Permalink
NOD-128
Browse files Browse the repository at this point in the history
  • Loading branch information
mynkgrwl committed May 12, 2016
1 parent f22666b commit 44cda7d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 41 deletions.
1 change: 1 addition & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 15 additions & 13 deletions core/dynamic/dynamic-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
Expand Down Expand Up @@ -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);
}
}
}
});
Expand Down
12 changes: 6 additions & 6 deletions mongoose/mongoose-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function bulkPost(model: Mongoose.Model<any>, objArr: Array<any>): 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)
Expand Down Expand Up @@ -129,7 +129,7 @@ export function findChild(model: Mongoose.Model<any>, id, prop): Q.Promise<any>
*/
export function post(model: Mongoose.Model<any>, obj: any): Q.Promise<any> {
let clonedObj = removeTransientProperties(model, obj);
return addChildModelToParent(model, clonedObj)
return addChildModelToParent(model, clonedObj, null)
.then(result => {
try {
autogenerateIdsForAutoFields(model, clonedObj);
Expand Down Expand Up @@ -167,7 +167,7 @@ export function del(model: Mongoose.Model<any>, id: any): Q.Promise<any> {
export function put(model: Mongoose.Model<any>, id: any, obj: any): Q.Promise<any> {
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 => {
Expand All @@ -187,7 +187,7 @@ export function put(model: Mongoose.Model<any>, id: any, obj: any): Q.Promise<an
export function patch(model: Mongoose.Model<any>, id: any, obj): Q.Promise<any> {
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 => {
Expand Down Expand Up @@ -605,7 +605,7 @@ function updateEntity(targetModel: Object, propKey: string, targetPropArray: boo
* @param model
* @param obj
*/
function addChildModelToParent(model: Mongoose.Model<any>, obj: any) {
function addChildModelToParent(model: Mongoose.Model<any>, obj: any, id: any) {
var asyncCalls = [];
for (var prop in obj) {
var metaArr = MetaUtils.getMetaDataForPropKey(getEntity(model.modelName), prop);
Expand All @@ -623,7 +623,7 @@ function addChildModelToParent(model: Mongoose.Model<any>, 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);
});
}

Expand Down
48 changes: 26 additions & 22 deletions security/auth/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 44cda7d

Please sign in to comment.