Reputation: 636
I'm working on a Loopback application that has two types of users — a "Supervisor" that can self-register within the app and a "Subordinate" that can only be registered by Supervisors (and is tied to that person). Supervisors use an email and password to log in like the base User model in loopback, but Subordinates use a generated email and password based on a date hash. This is to ensure that the Subordinate records are not tied to personally identifiable data, and is a requirement of the app. Subordinates can log into the system with the generated credentials, but keeping track of the pseudo-random info is not feasible.
Is there any way for a user in Loopback to get an access token (or even better, a generated memorable passphrase) that can be used instead of a username and password to log in the Subordinate user type? It seems like this is similar functionality to logging in with a token to reset a password, but I'm not sure how to do this with a reusable passphrase.
Upvotes: 3
Views: 638
Reputation: 5062
As far as i understand your post, the 'Supervisor' user type has specific email and password, the other user type 'subordinate' does not have specific email password.
There is similar scenario in the UserIdentity model's login method. If a user logs in the system with an social network account, UserIdentity model creates an account for this anonymous user.
For example, if the user logs in with google account. Then the model uses user's google id (external id in the model), creates a username based on user id.
Check profileToUser method in the model. Login method uses profileToUser method. You can find useful things for your scenario.
function profileToUser(provider, profile) {
// Let's create a user for that
var email = profile.emails && profile.emails[0] && profile.emails[0].value;
if (!email) {
// Fake an e-mail
email = (profile.username || profile.id) + '@loopback.' +
(profile.provider || provider) + '.com';
}
var username = provider + '.' + (profile.username || profile.id);
var password = utils.generateKey('password');
var userObj = {
username: username,
password: password,
email: email
};
return userObj;
}
Upvotes: 1