Created
July 25, 2017 11:30
-
-
Save SippieCup/9560a4ee3b89ca882dd2b22f941218e7 to your computer and use it in GitHub Desktop.
Loopback MultiUser Example
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
module.exports = function (ExtendedUserModel) { | |
ExtendedUserModel.afterRemote('create', function(context, user, next) { | |
createDriver(user) | |
.then(createCustomer(user) | |
.then(sendVerificationEmail(user) | |
.then( () => next()))); | |
function createDriver(user) { | |
if (user.realm==="driver") { | |
return user.driver.create({Licensed: true}); | |
} else { | |
return Promise.resolve(); | |
} | |
} | |
function createCustomer(user) { | |
if (user.realm==="customer") { | |
return user.customer.create({hasMoney: true}); | |
} else { | |
return Promise.resolve(); | |
} | |
} | |
function sendVerificationEmail(user) { | |
var options = { | |
type: 'email', | |
to: user.email, | |
from: 'noreply@uberclone.com', | |
subject: 'Thanks for registering.', | |
user: user | |
}; | |
return user.verify(options); | |
} | |
)}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment