From a4345469ced40cb1b2ee1c7f4fb71d7983dd5bdb Mon Sep 17 00:00:00 2001 From: Dan Nelson Date: Sat, 26 Jan 2019 21:08:28 -0700 Subject: [PATCH] #17 Starting to create new user. Need to add role select box. --- app/controllers/forgot-password.js | 8 +++- app/models/user.js | 15 ++++-- app/router.js | 2 + app/routes/forgot-password.js | 9 +++- .../protected/configuration/users/new.js | 10 ++++ .../configuration/users/new/index.js | 26 +++++++++++ app/serializers/application.js | 8 ++++ app/templates/forgot-password.hbs | 2 +- app/templates/login.hbs | 18 ++++---- .../protected/configuration/users/index.hbs | 12 +++-- .../protected/configuration/users/new.hbs | 1 + .../configuration/users/new/index.hbs | 46 +++++++++++++++++++ app/templates/protected/profile/address.hbs | 4 +- .../protected/profile/attributes.hbs | 18 ++++---- .../protected/profile/change-password.hbs | 8 ++-- .../protected/profile/configure-mfa.hbs | 4 +- .../protected/profile/locale-timezone.hbs | 4 +- app/templates/protected/profile/name.hbs | 10 ++-- app/templates/reset-password.hbs | 6 +-- .../protected/configuration/users/new-test.js | 11 +++++ .../configuration/users/new/index-test.js | 11 +++++ tests/unit/serializers/application-test.js | 23 ++++++++++ 22 files changed, 212 insertions(+), 44 deletions(-) create mode 100644 app/routes/protected/configuration/users/new.js create mode 100644 app/routes/protected/configuration/users/new/index.js create mode 100644 app/serializers/application.js create mode 100644 app/templates/protected/configuration/users/new.hbs create mode 100644 app/templates/protected/configuration/users/new/index.hbs create mode 100644 tests/unit/routes/protected/configuration/users/new-test.js create mode 100644 tests/unit/routes/protected/configuration/users/new/index-test.js create mode 100644 tests/unit/serializers/application-test.js diff --git a/app/controllers/forgot-password.js b/app/controllers/forgot-password.js index 75ceaae..de1716f 100644 --- a/app/controllers/forgot-password.js +++ b/app/controllers/forgot-password.js @@ -1,3 +1,9 @@ import Controller from '@ember/controller'; -export default Controller.extend({}); +export default Controller.extend({ + email: '', + + queryParams: [ + { email: { type: 'string' } } + ] +}); diff --git a/app/models/user.js b/app/models/user.js index f20acec..0d35c5e 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -1,16 +1,25 @@ +import { not, readOnly } from '@ember/object/computed'; import BaseModel from 'ember-cybertooth-base-model/models/-base'; import DS from 'ember-data'; export default BaseModel.extend({ - /** Attributes + /* Attributes * ---------------------------------------------------------------------------------------------------------------- */ email: DS.attr('string'), + inCognito: DS.attr('boolean'), - /** Relationships + /* Relationships * ---------------------------------------------------------------------------------------------------------------- */ roles: DS.hasMany('role'), - sessions: DS.hasMany('session') + sessions: DS.hasMany('session'), + + /* Computed + * ---------------------------------------------------------------------------------------------------------------- */ + + 'inCognito?': readOnly('inCognito'), + + 'notInCognito?': not('inCognito?') }); diff --git a/app/router.js b/app/router.js index acf14c6..58c792a 100644 --- a/app/router.js +++ b/app/router.js @@ -17,6 +17,8 @@ Router.map(function () { this.route('sessions', function () { }); }); + this.route('new', function () { + }); }); }); this.route('profile', function () { diff --git a/app/routes/forgot-password.js b/app/routes/forgot-password.js index 3c6b242..c9b8265 100644 --- a/app/routes/forgot-password.js +++ b/app/routes/forgot-password.js @@ -1,4 +1,5 @@ import { hash } from 'rsvp'; +import { getWithDefault } from '@ember/object'; import Route from '@ember/routing/route'; export default Route.extend({ @@ -17,9 +18,13 @@ export default Route.extend({ } }, - model() { + model(params) { return hash({ - username: '' + username: getWithDefault(params, 'email', '') }); + }, + + queryParams: { + email: { refreshModel: true } } }); diff --git a/app/routes/protected/configuration/users/new.js b/app/routes/protected/configuration/users/new.js new file mode 100644 index 0000000..daa5148 --- /dev/null +++ b/app/routes/protected/configuration/users/new.js @@ -0,0 +1,10 @@ +import { hash } from 'rsvp'; +import Route from '@ember/routing/route'; + +export default Route.extend({ + model() { + return hash({ + roles: this.get('store').query('role', { sort: 'name' }) + }) + } +}); diff --git a/app/routes/protected/configuration/users/new/index.js b/app/routes/protected/configuration/users/new/index.js new file mode 100644 index 0000000..2273c42 --- /dev/null +++ b/app/routes/protected/configuration/users/new/index.js @@ -0,0 +1,26 @@ +import { hash } from 'rsvp'; +import Route from '@ember/routing/route'; + +export default Route.extend({ + actions: { + save(user) { + user + .save() + .then((/*response*/) => { + this.get('notify').success('Created.'); + }) + .catch((errors) => { + console.error('???', errors); + this.get('notify').error('Check for errors.'); + }); + return false; + } + }, + + model() { + return hash({ + roles: this.modelFor('protected.configuration.users.new'), + user: this.get('store').createRecord('user') + }); + } +}); diff --git a/app/serializers/application.js b/app/serializers/application.js new file mode 100644 index 0000000..f4567ba --- /dev/null +++ b/app/serializers/application.js @@ -0,0 +1,8 @@ +import DS from 'ember-data'; + +export default DS.JSONAPISerializer.extend({ + attrs: { + createdAt: { serialize: false }, + updatedAt: { serialize: false } + } +}); diff --git a/app/templates/forgot-password.hbs b/app/templates/forgot-password.hbs index 727e6cb..7203c25 100644 --- a/app/templates/forgot-password.hbs +++ b/app/templates/forgot-password.hbs @@ -13,7 +13,7 @@ Reset My Password
- + {{input-text aria-describedby="js-username-help" autocomplete="email" diff --git a/app/templates/login.hbs b/app/templates/login.hbs index c69e42f..b1ba0ff 100644 --- a/app/templates/login.hbs +++ b/app/templates/login.hbs @@ -9,7 +9,7 @@
-