From 9eeafed26356f7665bd7c4c430a100d96519ffd0 Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Mon, 2 Apr 2018 17:53:35 -0700 Subject: [PATCH] new ad login component --- .../addon/components/login-ad/component.js | 110 ++++++++++++++++++ .../addon/components/login-ad/template.hbs | 42 +++++++ lib/login/addon/login/template.hbs | 2 +- 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 lib/login/addon/components/login-ad/component.js create mode 100644 lib/login/addon/components/login-ad/template.hbs diff --git a/lib/login/addon/components/login-ad/component.js b/lib/login/addon/components/login-ad/component.js new file mode 100644 index 000000000..5c9f78d90 --- /dev/null +++ b/lib/login/addon/components/login-ad/component.js @@ -0,0 +1,110 @@ +import { get, set, computed } from '@ember/object'; +import { next } from '@ember/runloop'; +import { inject as service } from '@ember/service'; +import Component from '@ember/component'; +import C from 'ui/utils/constants'; + +export default Component.extend({ + access: service(), + cookies: service(), + isCaas: computed('app.mode', function() { + return this.get('app.mode') === 'caas' ? true : false; + }), + waiting: null, + + username: null, + rememberUsername: false, + password: null, + shown: false, + provider: null, + readableProvider: null, + + actions: { + showLocal() { + this.toggleProperty('shown'); + next(this, 'focusSomething'); + }, + authenticate: function() { + const username = get(this, 'username'); + let password = get(this, 'password'); + const remember = get(this, 'rememberUsername'); + + if (password && get(this, 'provider') === 'local') { + password = password.trim(); + } + + const code = { + username: username, + password: password, + }; + + if ( remember ) { + if (get(this, 'provider') === 'local') { + get(this, 'cookies').setWithOptions(C.COOKIE.USERNAME, username, {expire: 365, secure: 'auto'}); + } else { + get(this, 'cookies').setWithOptions(`${get(this, 'provider').toUpperCase()}-USERNAME`, username, {expire: 365, secure: 'auto'}); + } + } else { + get(this, 'cookies').remove(C.COOKIE.USERNAME); + } + + set(this, 'password', ''); + if ( get(this,'access.providers') ) { + this.sendAction('action', get(this, 'provider'), code); + } + } + }, + + init() { + this._super(...arguments); + + var username = null; + if (get(this, 'provider') === 'local') { + username = get(this, `cookies.${C.COOKIE.USERNAME}`); + } else { + username = get(this, `cookies.${get(this, 'provider').toUpperCase()}-USERNAME`); + } + + if ( username ) { + set(this, 'username', username); + set(this, 'rememberUsername', true); + } + + if (get(this, 'provider')) { + let pv = null; + switch(get(this, 'provider')) { + case 'activedirectory': + pv = 'Active Directory'; + break; + case 'local': + default: + pv = 'Local Auth'; + break; + } + + set(this, 'readableProvider', pv); + + // console.log(this.get('provider')); + } + + }, + + focusSomething() { + if ( this.isDestroyed || this.isDestroying ) { + return; + } + + let elem = this.$('#login-username-ad'); + if ( get(this, 'username') ) { + elem = this.$('#login-password-ad'); + } + + if ( elem && elem[0] ) { + elem[0].focus(); + } + }, + + didInsertElement() { + next(this, 'focusSomething'); + }, +}); diff --git a/lib/login/addon/components/login-ad/template.hbs b/lib/login/addon/components/login-ad/template.hbs new file mode 100644 index 000000000..524078407 --- /dev/null +++ b/lib/login/addon/components/login-ad/template.hbs @@ -0,0 +1,42 @@ +{{#if shown}} +
+
+
+ {{#if isCaas}} + + {{else}} + + {{/if}} +
+ +
+
+
+ {{input type="text" id="login-username-ad" autocomplete="username" class="form-control login-user" value=username placeholder=(t 'loginUserPass.userPlaceholder')}} +
+
+ +
+ +
+ {{input id="login-password-ad" autocomplete="password" type="password" class="form-control login-pass" value=password}} +
+
+ +

+ +

+
+{{else}} + {{#if (eq provider 'local')}} + {{t 'loginUserPass.local'}} + {{else}} + {{t 'loginUserPass.provider' kind=readableProvider}} + {{/if}} +{{/if}} diff --git a/lib/login/addon/login/template.hbs b/lib/login/addon/login/template.hbs index 3487a68a5..3d5fe578d 100644 --- a/lib/login/addon/login/template.hbs +++ b/lib/login/addon/login/template.hbs @@ -25,7 +25,7 @@ {{/if}} {{#if isActiveDirectory}} - {{login-user-pass + {{login-ad classNames="row" action="authenticate" waiting=waiting