Skip to content

Commit

Permalink
disable submit button when the email does not match with any connection
Browse files Browse the repository at this point in the history
  • Loading branch information
glena committed Jan 12, 2017
1 parent f0ae02a commit 70d2fe6
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 24 deletions.
24 changes: 24 additions & 0 deletions src/connection/enterprise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ import { dataFns } from '../utils/data_utils';
import { emailDomain, emailLocalPart } from '../field/email';
import { setUsername } from '../field/username';
import { getFieldValue } from '../field/index';
import { isEmail } from '../field/email';
import { isSSOEnabled, matchesEnterpriseConnection } from '../engine/classic';
import { databaseUsernameValue } from './database/index';
import * as i18n from '../i18n';

import { swap, updateEntity } from '../store/index';

const { get, initNS, tget, tremove, tset } = dataFns(["enterprise"]);
const { tremove: tremoveCore, tset: tsetCore, tget: tgetCore } = dataFns(["core"]);

// TODO: Android version also has "google-opendid" in the list, but we
// consider it to be a social connection. See
Expand Down Expand Up @@ -147,3 +154,20 @@ export function toggleHRD(m, email) {
export function isHRDActive(m) {
return tget(m, "hrd", isSingleHRDConnection(m));
}

export function verifyHRDEmail(m, str) {
if(isEmail(str)
&& !l.hasSomeConnections(m, "database")
&& !findADConnectionWithoutDomain(m)
&& !matchesEnterpriseConnection(m, str) ) {

m = tsetCore(m, 'hrdEmailError', true);
const errorMessage = i18n.str(m, ["error", "login", "hrd.not_matching_email"]);
return tsetCore(m, 'globalError', errorMessage);
} else if (databaseUsernameValue(m) !== "" && tgetCore(m, 'hrdEmailError')) {
m = tsetCore(m, 'hrdEmailError', false);
return tremoveCore(m, 'globalError');
}

return m;
}
4 changes: 1 addition & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
setupLock,
updateLock
} from './core/actions';
import { termsAccepted } from './connection/database/index';
import * as l from './core/index';
import * as c from './field/index';
import * as idu from './utils/id_utils';
Expand Down Expand Up @@ -80,8 +79,7 @@ export default class Base extends EventEmitter {
if (l.rendering(m)) {
const screen = this.engine.render(m);

const disableSubmitButton = screen.name === "main.signUp"
&& !termsAccepted(m);
const disableSubmitButton = screen.isSubmitDisabled(m);

const i18nProp = {
group: keyPath => i18n.group(m, keyPath),
Expand Down
4 changes: 4 additions & 0 deletions src/core/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default class Screen {
return null;
}

isSubmitDisabled(m) {
return false;
}

renderAuxiliaryPane() {
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/engine/classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ import { getFieldValue } from '../field/index';
import { swap, updateEntity } from '../store/index';

export function isSSOEnabled(m) {
return isEnterpriseDomain(m, databaseUsernameValue(m));
return matchesEnterpriseConnection(m, databaseUsernameValue(m));
}

export function matchesEnterpriseConnection(m, usernameValue) {
return isEnterpriseDomain(m, usernameValue);
}

export function usernameStyle(m) {
Expand Down
12 changes: 10 additions & 2 deletions src/engine/classic/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import LoginPane from '../../connection/database/login_pane';
import PaneSeparator from '../../core/pane_separator';
import {
databaseConnection,
databaseUsernameValue,
databaseUsernameStyle,
databaseUsernameValue,
defaultDatabaseConnection,
hasInitialScreen,
hasScreen,
Expand Down Expand Up @@ -37,7 +37,6 @@ import {
} from '../classic';
import * as i18n from '../../i18n';


function shouldRenderTabs(m) {
if (isSSOEnabled(m)) return false;
if (l.hasSomeConnections(m, "database")) return hasScreen(m, "signUp");
Expand Down Expand Up @@ -132,6 +131,15 @@ export default class Login extends Screen {
return i18n.str(m, ["loginSubmitLabel"]);
}

isSubmitDisabled(m) {
// it should disable the submit button if there is any connection that
// requires username/password and there is no enterprise with domain
// that matches with the email domain entered for HRD
return !l.hasSomeConnections(m, "database") // no database connection
&& !findADConnectionWithoutDomain(m) // no enterprise without domain
&& !isSSOEnabled(m); // no matching domain
}

submitHandler(model) {
if (hasOnlyClassicConnections(model, "social")) {
return null;
Expand Down
4 changes: 4 additions & 0 deletions src/engine/classic/sign_up_screen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export default class SignUp extends Screen {
return signUp;
}

isSubmitDisabled(m) {
return !termsAccepted(m)
}

renderAuxiliaryPane(lock) {
return renderSignedInConfirmation(lock)
|| renderSignedUpConfirmation(lock)
Expand Down
6 changes: 6 additions & 0 deletions src/field/email.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import trim from 'trim';
import { setField } from './index';
import { endsWith } from '../utils/string_utils';
import { verifyHRDEmail } from '../connection/enterprise';

const regExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

export function validateEmail(str) {
return isEmail(str);
}

export function isEmail(str) {
const result = regExp.exec(trim(str.toLowerCase()));
return result && result[0];
}

export function setEmail(m, str) {
m = verifyHRDEmail(m, str);
return setField(m, "email", str, validateEmail);
}

Expand Down
3 changes: 2 additions & 1 deletion src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default {
"password_change_required": "You need to update your password because this is the first time you are logging in, or because your password has expired.", // TODO: verify error code
"password_leaked": "This login has been blocked because your password has been leaked in another website. We’ve sent you an email with instructions on how to unblock it.",
"too_many_attempts": "Your account has been blocked after multiple consecutive login attempts.",
"session_missing": "Couldn't complete your authentication request. Please try again after closing all open dialogs"
"session_missing": "Couldn't complete your authentication request. Please try again after closing all open dialogs",
"hrd.not_matching_email": "Please, use your corporate email to login."
},
passwordless: {
"bad.email": "The email is invalid",
Expand Down
11 changes: 2 additions & 9 deletions support/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
const cid = "ixeOHFhD7NSPxEQK6CFcswjUsa5YkcXS";
const domain = "auth0-tests-lock.auth0.com";
const options = {
auth: {
responseType: 'id_token'
},
oidcConformant: true
rememberLastLogin:false
};

const lock = new Auth0Lock(cid, domain, options);
Expand All @@ -38,11 +35,7 @@
console.log('authorization_error', error);
});

lock.show({
languageDictionary: {
title: "sarlanga"
}
});
lock.show();

</script>
</body>
Expand Down
16 changes: 8 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var path = require('path');
module.exports = {
entry: './src/browser.js',
output: {
path: path.join(__dirname, "../build"),
path: path.join(__dirname, '../build'),
filename: 'lock.js'
},
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".js", ".jsx", ".styl"]
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', '.styl']
},
progress: true,
watch: true,
Expand All @@ -25,23 +25,23 @@ module.exports = {
reasons: true
},
stylus: {
preferPathResolver: 'webpack',
preferPathResolver: 'webpack'
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: __dirname + './node_modules',
exclude: path.join(__dirname, 'node_modules'),
query: {
plugins: ["version-inline", "transform-css-import-to-string"],
presets: ["es2015-loose", "stage-0", "react"]
plugins: ['version-inline', 'transform-css-import-to-string'],
presets: ['es2015-loose', 'stage-0', 'react']
}
},
{
test: /\.styl$/,
loader: 'css-loader!stylus-loader?paths=node_modules/bootstrap-stylus/stylus/'
}
]
},
};
}
};

0 comments on commit 70d2fe6

Please sign in to comment.