Skip to content

Commit

Permalink
using the prefill options in the model
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Deschamps Rudge authored and Luis Deschamps Rudge committed Feb 3, 2017
1 parent 2c26a4e commit 2d7442f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ export function setup(id, clientID, domain, options, hookRunner, emitEventFn) {
hashCleanup: options.hashCleanup === false ? false : true,
allowedConnections: Immutable.fromJS(options.allowedConnections || []),
ui: extractUIOptions(id, options),
defaultADUsernameFromEmailPrefix: options.defaultADUsernameFromEmailPrefix === false ? false : true
defaultADUsernameFromEmailPrefix: options.defaultADUsernameFromEmailPrefix === false ? false : true,
prefill: Immutable.fromJS(options.prefill || {})
}));

m = i18n.initI18n(m);

return m;
}

Expand Down Expand Up @@ -365,6 +366,10 @@ export function defaultADUsernameFromEmailPrefix(m) {
return get(m, "defaultADUsernameFromEmailPrefix", true);
}

export function prefill(m) {
return get(m, "prefill", {});
}

export function warn(x, str) {
const shouldOutput = Map.isMap(x)
? !ui.disableWarnings(x)
Expand Down
16 changes: 10 additions & 6 deletions src/engine/classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ function validateAllowedConnections(m) {
return m;
}

const setPrefill = m => {
const { email, username } = l.prefill(m).toJS();
if (typeof email === "string") m = setEmail(m, email);
if (typeof username === "string") m = setUsername(m, username, "username", false);
return m;
}

class Classic {

static SCREENS = {
Expand All @@ -110,17 +117,14 @@ class Classic {
model = initSocial(model, options);
model = initDatabase(model, options);
model = initEnterprise(model, options);
this.prefill = options.prefill;

return model;
}

didReceiveClientSettings(m) {
const { email, username } = this.prefill || {};
if (typeof email === "string") m = setEmail(m, email);
if (typeof username === "string") m = setUsername(m, username, "username", false);

return validateAllowedConnections(m);
m = validateAllowedConnections(m);
m = setPrefill(m);
return m;
}

willShow(m, opts) {
Expand Down
1 change: 1 addition & 0 deletions support/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
};

const lock = new Auth0Lock(cid, domain, options);
window.lock = lock;

lock.on("authenticated", function(authResult) {
console.log(authResult);
Expand Down

0 comments on commit 2d7442f

Please sign in to comment.