return this.authHttp.post(UserService.BASE_USERS_URL, body)
.map(this.restExtractor.extractDataBool)
- .catch((res) => this.restExtractor.handleError(res));
+ .catch(this.restExtractor.handleError);
}
getUsers() {
this.userService.addUser(this.username, this.password).subscribe(
ok => this.router.navigate([ '/admin/users/list' ]),
- err => this.error = err
+ err => this.error = err.text
);
}
}
this.totalUsers = totalUsers;
},
- err => alert(err)
+ err => alert(err.text)
);
}
this.userService.removeUser(user).subscribe(
() => this.getUsers(),
- err => alert(err)
+ err => alert(err.text)
);
}
}
handleError(res: Response) {
let text = 'Server error: ';
text += res.text();
- let json = res.json();
+ let json = '';
+
+ try {
+ json = res.json();
+ } catch (err) { ; }
const error = {
json,
text
};
+ console.error(error);
+
return Observable.throw(error);
}
}
this.loading.next(false);
},
- error => alert(error)
+ error => alert(error.text)
);
}
this.video = video;
this.loadVideo();
},
- error => alert(error)
+ error => alert(error.text)
);
});
}
"src/app/shared/form-validators/url.validator.ts",
"src/app/shared/index.ts",
"src/app/shared/rest/index.ts",
- "src/app/shared/rest/mock-rest-table.ts",
"src/app/shared/rest/rest-extractor.service.ts",
- "src/app/shared/rest/rest-filter.model.ts",
"src/app/shared/rest/rest-pagination.ts",
- "src/app/shared/rest/rest-sort.ts",
- "src/app/shared/rest/rest-table-page.ts",
- "src/app/shared/rest/rest-table.spec.ts",
- "src/app/shared/rest/rest-table.ts",
"src/app/shared/rest/rest.service.ts",
"src/app/shared/search/index.ts",
"src/app/shared/search/search-field.type.ts",
"src/app/videos/shared/index.ts",
"src/app/videos/shared/loader/index.ts",
"src/app/videos/shared/loader/loader.component.ts",
- "src/app/videos/shared/pagination.model.ts",
"src/app/videos/shared/sort-field.type.ts",
"src/app/videos/shared/video.model.ts",
"src/app/videos/shared/video.service.ts",
req.checkBody('username', 'Should have a valid username').isUserUsernameValid()
req.checkBody('password', 'Should have a valid password').isUserPasswordValid()
- // TODO: check we don't have already the same username
-
logger.debug('Checking usersAdd parameters', { parameters: req.body })
- checkErrors(req, res, next)
+ checkErrors(req, res, function () {
+ User.loadByUsername(req.body.username, function (err, user) {
+ if (err) {
+ logger.error('Error in usersAdd request validator.', { error: err })
+ return res.sendStatus(500)
+ }
+
+ if (user) return res.status(409).send('User already exists.')
+
+ next()
+ })
+ })
}
function usersRemove (req, res, next) {
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204)
})
+ it('Should fail if we add a user with the same username', function (done) {
+ it('Should succeed with the correct params', function (done) {
+ const data = {
+ username: 'user1',
+ password: 'my super password'
+ }
+
+ requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409)
+ })
+ })
+
it('Should fail with a non admin user', function (done) {
server.user = {
username: 'user1',