Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unction validateInput(data, otherValidation) {
- let { errors } = otherValidation(data);
- console.log(errors);
- console.log('sprawdzam');
- const {
- username,
- firstName,
- lastName,
- email,
- password,
- passwordConfirmation,
- } = data;
- return User.find({
- $or: [
- {
- userName: username,
- },
- {
- email: email,
- },
- ],
- }).then(user => {
- console.log(user);
- if (user.length) {
- if (user[0].userName === username) {
- errors.username = 'Przepraszamy, Login jest już zajęty.';
- console.log('Login zajety');
- }
- if (user[0].email === email) {
- errors.email = 'E-mail został juz wykorzystany';
- console.log('email zajety');
- }
- }
- console.log('nie ma takiego usera');
- return {
- errors,
- isValid: isEmpty(errors),
- };
- });
- }
- passport.use(
- 'local-signup',
- new LocalStrategy(
- {
- usernameField: 'email',
- passwordField: 'password',
- passReqToCallback: true,
- },
- function(req, email, password, done) {
- process.nextTick(function() {
- validateInput(req.body, validator.validateInput).then(
- ({ errors, isValid }) => {
- //tu mi nie wchodzi w ogóle
- console.log(isValid);
- if (isValid) {
- const {
- username,
- firstName,
- lastName,
- email,
- password,
- passwordConfirmation,
- } = req.body;
- const user = new User({
- email: email,
- password: user.generateHash(password),
- firstName: firstName,
- lastName: lastName,
- userName: username,
- role: 'student',
- });
- user.save(function(err) {
- if (err) {
- console.log(err);
- }
- return done(null, user);
- });
- } else {
- return done(errors);
- }
- }
- );
- });
- }
- )
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement