-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
363 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ COPY package*.json ./ | |
|
||
# install dependencies | ||
RUN npm install | ||
RUN npm postinstall | ||
|
||
COPY . . | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
const MESSAGES = { | ||
auth_400: { message: 'Authentication / Registration failed' }, | ||
auth_422: { message: 'Email password pair incorrect' }, | ||
verify_200: { message: 'Account is verify' }, | ||
verify_400: { message: 'Failed to verify account' }, | ||
remind_pass_422: { message: 'No such user' }, | ||
remind_pass_200: { message: 'Letter to the specified address sent' }, | ||
set_pass_400: { message: 'Failed to save password' }, | ||
auth_400: 'Authentication / Registration failed', | ||
auth_422:'Email password pair incorrect', | ||
verify_200: 'Account is verify', | ||
verify_400: 'Failed to verify account', | ||
remind_pass_422: 'No such user', | ||
remind_pass_200: 'Letter to the specified address sent', | ||
set_pass_400: 'Failed to save password', | ||
set_pass_200: 'Password changed successfully', | ||
validation_no_user: 'There is no such user', | ||
validation_social: 'You used to go through a social network', | ||
validation_password_invalid: 'Password is invalid', | ||
}; | ||
|
||
export default MESSAGES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,68 @@ | ||
import passport from 'passport'; | ||
import LocalStrategy from 'passport-local'; | ||
import FacebookStrategy from 'passport-facebook'; | ||
|
||
import config from './config'; | ||
|
||
import User from '../models/user'; | ||
|
||
const VKontakteStrategy = require('passport-vkontakte').Strategy; | ||
|
||
|
||
// For standard authentication | ||
const local = new LocalStrategy({ | ||
usernameField: 'user[usermail]', | ||
passwordField: 'user[password]', | ||
}, (usermail, password, done) => { | ||
User.findOne({ usermail }) | ||
.then((user) => { | ||
if (!user || !user.validatePassword(password)) { | ||
return done(null, false, { errors: { 'email or password': 'is invalid' } }); | ||
if (!user) { | ||
return done(null, false, { message: config.MESSAGES.validation_no_user }); | ||
} | ||
if (user && !user.password) { | ||
return done(null, user, { message: config.MESSAGES.validation_social }); | ||
} | ||
if (user && !user.validatePassword(password)) { | ||
return done(null, user, { message: config.MESSAGES.validation_password_invalid }); | ||
} | ||
|
||
return done(null, user); | ||
}).catch(done); | ||
}); | ||
|
||
passport.use(local); | ||
|
||
|
||
// For authentication via Facebook | ||
const facebook = new FacebookStrategy({ | ||
clientID: config.PASS.FACEBOOK.id, | ||
clientSecret: config.PASS.FACEBOOK.secret, | ||
callbackURL: `${config.HOST}/api/user/facebook/callback`, | ||
profileFields: [ 'email' ], | ||
}, (accessToken, refreshToken, profile, done) => { | ||
const usermail = String(profile._json.email); | ||
User.findOne({ usermail }) | ||
.then((user) => { | ||
return done(null, user, usermail); | ||
}).catch(done, false, usermail); | ||
}); | ||
|
||
passport.use(facebook); | ||
|
||
// For authentication via VKontakte | ||
const vkontakte = new VKontakteStrategy({ | ||
clientID: config.PASS.VKONTAKTE.id, | ||
clientSecret: config.PASS.VKONTAKTE.secret, | ||
callbackURL: `${config.HOST}/api/user/vkontakte/callback`, | ||
profileFields: [ 'email' ], | ||
}, (accessToken, refreshToken, params, profile, done) => { | ||
let usermail = params.email; | ||
User.findOne({ usermail }) | ||
.then((user) => { | ||
return done(null, user, usermail); | ||
}).catch(done, false, usermail); | ||
}); | ||
|
||
passport.use(vkontakte); | ||
|
||
|
||
export default passport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.