Skip to content

Commit de6e3b8

Browse files
committed
add blueprint
1 parent 8be31f9 commit de6e3b8

10 files changed

Lines changed: 117 additions & 22 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
2+
import Ember from 'ember';
3+
4+
export default Ember.Controller.extend(LoginControllerMixin, {
5+
authenticator: 'simple-auth-authenticator:devise'
6+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Ember from 'ember';
2+
3+
export default {
4+
name: 'init-shared',
5+
after: 'simple-auth',
6+
initialize: function(container) {
7+
var sharedStore = Ember.Object.create({});
8+
container.optionsForType('globals', {instantiate: false, singleton: true});
9+
container.register('globals:shared', sharedStore);
10+
container.typeInjection('controller', 'shared', 'globals:shared');
11+
container.typeInjection('route', 'shared', 'globals:shared');
12+
}
13+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Ember from 'ember';
2+
3+
export default {
4+
name: 'user-in-route',
5+
after: 'store',
6+
initialize: function(container) {
7+
var session = container.lookup('simple-auth-session:main');
8+
9+
var observer = Ember.Object.extend({
10+
observerForSession: function(){
11+
var self = this;
12+
if(this.get('session.user_email')){
13+
container.lookup('store:main').find('user', 'admin').then(function(user){
14+
container.lookup('globals:shared').set('currentUser', user);
15+
}, function(){
16+
self.get('session').invalidate().then(function(){
17+
localStorage.removeItem('ember_simple_auth:session');
18+
});
19+
});
20+
}
21+
}.observes('session.user_email').on('init')
22+
});
23+
observer.create({session: session});
24+
}
25+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Ember from 'ember';
2+
import authMixin from 'simple-auth/mixins/application-route-mixin';
3+
4+
export default Ember.Route.extend(authMixin, {
5+
redirect: function(){
6+
if(this.get('session.isAuthenticated')){
7+
this.transitionTo('/');
8+
}
9+
},
10+
11+
renderTemplate: function(){
12+
this.render('login', {outlet: 'login'});
13+
}
14+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<nav class="navbar navbar-inverse navbar-fixed-top">
2+
<div class="container-fluid">
3+
<a class="navbar-brand" {{bind-attr href="controller.titleLinksTo"}}>{{controller.siteTitle}}</a>
4+
<div class="collapse navbar-collapse">
5+
<ul class="nav navbar-nav">
6+
{{#each navigation in controller}}
7+
{{partial "admin/navigation/item"}}
8+
{{/each}}
9+
</ul>
10+
{{#if session.isAuthenticated}}
11+
{{signout-link signoutAction='invalidateSession' currentUser=shared.currentUser nameAttribute='name' avatarAttribute='avatar'}}
12+
{{/if}}
13+
</div>
14+
</div>
15+
</div>
16+
</nav>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="container main">
2+
<div class="col-md-4 col-md-offset-3">
3+
<h1>Login</h1>
4+
<form {{action 'authenticate' on='submit'}} class="form-horizontal" role="form">
5+
<div class="form-group">
6+
<label for="identification">Login</label>
7+
{{input value=identification placeholder='Enter Login' class="form-control"}}
8+
</div>
9+
<div class="form-group">
10+
<label for="password">Password</label>
11+
{{input value=password placeholder='Enter Password' type='password' class="form-control"}}
12+
</div>
13+
<button type="submit" class="btn btn-success form-control">Login</button>
14+
</form>
15+
</div>
16+
</div>

blueprints/ember-cli-admin-auth/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
var processTextContent = require('node_modules/ember-cli-admin/lib/proccess-text-content').processTextContent;
2+
13
module.exports = {
4+
description: 'Generates ember-simple-auth components and settings',
25
normalizeEntityName: function() {},
36
afterInstall: function() {
47
this.addBowerPackagesToProject([
@@ -9,5 +12,26 @@ module.exports = {
912
{name: "ember-cli-simple-auth", target: "^0.7.2"},
1013
{name: "ember-cli-simple-auth-devise", target: "^0.7.2"}
1114
]);
15+
},
16+
beforeInstall: function(options) {
17+
var process = processTextContent.bind(this);
18+
process('app/templates/application.hbs',
19+
{
20+
replace: {
21+
"{{partial 'admin/index'}}": "{{#if session.isAuthenticated}}\n\t{{partial 'admin/index'}}\n{{else}}\n\t{{outlet 'login'}}\n{{/if}}"
22+
}
23+
});
24+
process('app/router.js',
25+
{
26+
replace: {
27+
"Router.map(function() {": "Router.map(function() {\n\treturn this.route(\"login\"});\n"
28+
}
29+
});
30+
process('config/environment.js',
31+
{
32+
insert: {
33+
"\t};": "\n\tENV['simple-auth'] = {\n\t\tauthorizer: 'simple-auth-authorizer:devise',\n\t\trouteAfterAuthentication: '/'\n\t};\n"
34+
}
35+
});
1236
}
1337
};

tests/dummy/app/routes/login.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Ember from 'ember';
22
import authMixin from 'simple-auth/mixins/application-route-mixin';
3-
var loginRoute = Ember.Route.extend(authMixin, {
3+
4+
export default Ember.Route.extend(authMixin, {
45
redirect: function(){
56
if(this.get('session.isAuthenticated')){
67
this.transitionTo('/');
@@ -10,5 +11,4 @@ var loginRoute = Ember.Route.extend(authMixin, {
1011
renderTemplate: function(){
1112
this.render('login', {outlet: 'login'});
1213
}
13-
});
14-
export default loginRoute;
14+
});

tests/unit/.gitkeep

Whitespace-only changes.

tests/unit/components/signout-link-test.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)