Skip to content

Commit

Permalink
#17 Starting to create new user. Need to add role select box.
Browse files Browse the repository at this point in the history
  • Loading branch information
nadnoslen committed Jan 27, 2019
1 parent 9df4774 commit a434546
Show file tree
Hide file tree
Showing 22 changed files with 212 additions and 44 deletions.
8 changes: 7 additions & 1 deletion app/controllers/forgot-password.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import Controller from '@ember/controller';

export default Controller.extend({});
export default Controller.extend({
email: '',

queryParams: [
{ email: { type: 'string' } }
]
});
15 changes: 12 additions & 3 deletions app/models/user.js
Original file line number Diff line number Diff line change
@@ -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?')
});
2 changes: 2 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Router.map(function () {
this.route('sessions', function () {
});
});
this.route('new', function () {
});
});
});
this.route('profile', function () {
Expand Down
9 changes: 7 additions & 2 deletions app/routes/forgot-password.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { hash } from 'rsvp';
import { getWithDefault } from '@ember/object';
import Route from '@ember/routing/route';

export default Route.extend({
Expand All @@ -17,9 +18,13 @@ export default Route.extend({
}
},

model() {
model(params) {
return hash({
username: ''
username: getWithDefault(params, 'email', '')
});
},

queryParams: {
email: { refreshModel: true }
}
});
10 changes: 10 additions & 0 deletions app/routes/protected/configuration/users/new.js
Original file line number Diff line number Diff line change
@@ -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' })
})
}
});
26 changes: 26 additions & 0 deletions app/routes/protected/configuration/users/new/index.js
Original file line number Diff line number Diff line change
@@ -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')
});
}
});
8 changes: 8 additions & 0 deletions app/serializers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import DS from 'ember-data';

export default DS.JSONAPISerializer.extend({
attrs: {
createdAt: { serialize: false },
updatedAt: { serialize: false }
}
});
2 changes: 1 addition & 1 deletion app/templates/forgot-password.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<legend>Reset My Password</legend>
<form class="form" onsubmit={{action (route-action "forgotPassword" session model.username)}}>
<div class="form-group">
<label for="js-username" class="control-label">Email Address</label>
<label for="js-username">Email Address</label>
{{input-text
aria-describedby="js-username-help"
autocomplete="email"
Expand Down
18 changes: 10 additions & 8 deletions app/templates/login.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<form class="form"
onsubmit={{action (route-action "confirmSignIn" model.authenticationState model.mfaCode)}}>
<div class="form-group">
<label for="js-mfa-code" class="control-label">
<label for="js-mfa-code">
{{model.authenticationState.mfaChallengeDevice}} Code
</label>
{{input-text
Expand Down Expand Up @@ -48,7 +48,7 @@
onsubmit={{action
(route-action "completePassword" model.authenticationState model.newPassword model.additionalAttributes)}}>
<div class="form-group d-none">
<label for="js-username-new-password" class="control-label">Email Address</label>
<label for="js-username-new-password">Email Address</label>
{{input-text
aria-describedby="js-username-new-password-help"
autocomplete="email"
Expand All @@ -62,7 +62,7 @@
<small id="js-username-new-password-help" class="form-text text-muted">Your email address.</small>
</div>
<div class="form-group">
<label for="js-password-new-password" class="control-label">New Password</label>
<label for="js-password-new-password">New Password</label>
{{input-text
aria-describedby="js-password-new-password-help"
autocomplete="new-password"
Expand All @@ -77,7 +77,7 @@
</small>
</div>
<div class="form-group">
<label for="js-given-name" class="control-label">Given Name</label>
<label for="js-given-name">Given Name</label>
{{input-text
aria-describedby="js-given-name-help"
class="form-control"
Expand All @@ -92,7 +92,7 @@
</small>
</div>
<div class="form-group">
<label for="js-family-name" class="control-label">Family Name</label>
<label for="js-family-name">Family Name</label>
{{input-text
aria-describedby="js-family-name-help"
class="form-control"
Expand All @@ -117,7 +117,7 @@
{{!-- ------------------------------------------------------------------------------------ Sign In Form --}}
<form class="form" onsubmit={{action (route-action "signIn" model.username model.password)}}>
<div class="form-group">
<label for="js-username" class="control-label">Email Address</label>
<label for="js-username">Email Address</label>
{{input-text
aria-describedby="js-username-help"
autocomplete="email"
Expand All @@ -131,7 +131,7 @@
<small id="js-username-help" class="form-text text-muted">Your email address.</small>
</div>
<div class="form-group">
<label for="js-password" class="control-label">Password</label>
<label for="js-password">Password</label>
{{input-text
aria-describedby="js-password-help"
autocomplete="current-password"
Expand All @@ -143,7 +143,9 @@
<small id="js-password-help" class="form-text text-muted">Your password.</small>
</div>
<div class="form-group text-right">
{{#link-to "forgot-password" class="btn btn-link text-danger"}}Forgot Password{{/link-to}}
{{#link-to "forgot-password" (query-params email="") class="btn btn-link text-danger"}}
Forgot Password
{{/link-to}}
<button class="btn btn-outline-primary" type="submit">
Submit
</button>
Expand Down
12 changes: 9 additions & 3 deletions app/templates/protected/configuration/users/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
Users
</h1>
<div class="align-self-center btn-group">
<button class="btn btn-outline-secondary" disabled="disabled" type="button">
{{#link-to "protected.configuration.users.new.index" class="btn btn-outline-secondary"}}
{{fa-icon "plus"}}
</button>
{{/link-to}}
<button class="btn btn-outline-secondary" disabled="disabled" type="button">
{{fa-icon "question"}}
</button>
Expand All @@ -30,7 +30,13 @@
{{#link-to "protected.configuration.users.user.index" user.id
class="align-items-center d-flex justify-content-between list-group-item list-group-item-action"
}}
{{user.email}}
<div>
{{user.email}}
{{#if user.notInCognito?}}
-
<small class="text-muted">Not In Cognito</small>
{{/if}}
</div>
<small class="text-muted text-right">
{{date-short-llll user.updatedAt}}
</small>
Expand Down
1 change: 1 addition & 0 deletions app/templates/protected/configuration/users/new.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{outlet}}
46 changes: 46 additions & 0 deletions app/templates/protected/configuration/users/new/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<section class="my-3">
<div class="container">
<div class="align-items-center d-flex my-3">
<h1 class="flex-fill h5">
{{#link-to "protected.configuration.index"}}
Configuration
{{/link-to}}
{{fa-icon "caret-right" fixedWidth=true}}
{{#link-to "protected.configuration.users.index"}}
Users
{{/link-to}}
{{fa-icon "caret-right" fixedWidth=true}}
New User
</h1>
<div class="align-self-center btn-group">
<button class="btn btn-outline-secondary" disabled="disabled" type="button">
{{fa-icon "question"}}
</button>
</div>
</div>
<form class="form" onsubmit={{action (route-action "save" model.user)}}>
<div class="form-group">
<label for="js-username">Email Address</label>
{{input
aria-describedby="js-username-help"
autocomplete="off"
class="form-control"
placeholder="Email Address"
type="email"
value=model.email
}}
<small id="js-username-help" class="form-text text-muted">
What is the new user's email address?
</small>
</div>
<div class="form-group text-right">
<div class="btn-group">
<button class="btn btn-outline-primary" type="submit">Create</button>
{{#link-to "protected.configuration.users.index" class="btn btn-outline-secondary"}}
Cancel
{{/link-to}}
</div>
</div>
</form>
</div>
</section>
4 changes: 2 additions & 2 deletions app/templates/protected/profile/address.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<legend>Update Profile</legend>
<form class="form" onsubmit={{action (route-action "update" session model)}}>
<div class="form-group">
<label for="js-address" class="control-label">Address</label>
<label for="js-address">Address</label>
{{text-area
aria-describedby="js-address"
autofocus=true
Expand All @@ -17,7 +17,7 @@
</small>
</div>
<div class="form-group">
<label for="js-phone-number" class="control-label">Phone Number</label>
<label for="js-phone-number">Phone Number</label>
{{input-text
aria-describedby="js-phone-number-help"
class="form-control"
Expand Down
18 changes: 9 additions & 9 deletions app/templates/protected/profile/attributes.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<legend>Update Profile</legend>
<form class="form" onsubmit={{action (route-action "update" session model)}}>
<div class="form-group">
<label for="js-given-name" class="control-label">Given Name</label>
<label for="js-given-name">Given Name</label>
{{input-text
aria-describedby="js-given-name-help"
autofocus=true
Expand All @@ -17,7 +17,7 @@
</small>
</div>
<div class="form-group">
<label for="js-middle-name" class="control-label">Middle Name</label>
<label for="js-middle-name">Middle Name</label>
{{input-text
aria-describedby="js-middle-name-help"
class="form-control"
Expand All @@ -31,7 +31,7 @@
</small>
</div>
<div class="form-group">
<label for="js-family-name" class="control-label">Family Name</label>
<label for="js-family-name">Family Name</label>
{{input-text
aria-describedby="js-family-name-help"
class="form-control"
Expand All @@ -45,7 +45,7 @@
</small>
</div>
<div class="form-group">
<label for="js-nickname" class="control-label">Nickname</label>
<label for="js-nickname">Nickname</label>
{{input-text
aria-describedby="js-nickname-help"
class="form-control"
Expand All @@ -59,7 +59,7 @@
</small>
</div>
<div class="form-group">
<label for="js-address" class="control-label">Address</label>
<label for="js-address">Address</label>
{{text-area
aria-describedby="js-address"
class="form-control"
Expand All @@ -73,7 +73,7 @@
</small>
</div>
<div class="form-group">
<label for="js-phone-number" class="control-label">Phone Number</label>
<label for="js-phone-number">Phone Number</label>
{{input-text
aria-describedby="js-phone-number-help"
class="form-control"
Expand All @@ -88,7 +88,7 @@
</small>
</div>
<div class="form-group">
<label for="js-locale" class="control-label">Locale</label>
<label for="js-locale">Locale</label>
{{input-text
aria-describedby="js-locale-help"
class="form-control"
Expand All @@ -102,7 +102,7 @@
</small>
</div>
<div class="form-group">
<label for="js-zoneinfo" class="control-label">Timezone</label>
<label for="js-zoneinfo">Timezone</label>
{{input-text
aria-describedby="js-zoneinfo-help"
class="form-control"
Expand All @@ -116,7 +116,7 @@
</small>
</div>
<div class="form-group">
<label for="js-website" class="control-label">Website</label>
<label for="js-website">Website</label>
{{input-text
aria-describedby="js-website-help"
class="form-control"
Expand Down
Loading

0 comments on commit a434546

Please sign in to comment.