Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- api.post('/authenticate', passport.authenticate(['local', 'basic'], { session: false }), function (req, res) {
- passport.use(new BasicStrategy({ realm: 'Authentication failed. Wrong username or password.'}, verifyLocalUser));
- passport.use(new LocalStrategy(verifyLocalUser));
- var verifyLocalUser = function (username, password, next) {
- User.findOne({
- username: username
- }).select('fullname admin username password').exec(function (err, user) {
- if (err) {
- return next(err);
- }
- if (user && user.comparePasswords(password)) {
- return next(null, user);
- } else {
- next(null, false, { message: 'Authentication failed. Wrong username or password.' });
- }
- });
- }
- authFactory.signIn = function (username, password) {
- return $http.post('/api/authenticate', {
- username: username,
- password: password
- }).then(function (res) {
- AuthToken.setToken(res.data.token);
- return res.data;
- }, function (res) {
- console.warn(res);
- });
- };
- next(null, false, { message: 'Authentication failed. Wrong username or password.' });
- cb(new YourCustomError())
- class HttpError extends Error {
- constructor (msg = 'Invalid Request', status = 400) {
- super(msg)
- this.status = status
- }
- }
- class Forbidden extends HttpError {
- constructor (msg = 'Forbidden') {
- super(msg, 403)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement