Skip to content

Commit a22babe

Browse files
committed
basic setup
1 parent 8dcc251 commit a22babe

6 files changed

Lines changed: 69 additions & 1 deletion

File tree

app/initializers/init-shared.js

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+
};

app/initializers/user-in-route.js

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+
};

app/routes/.gitkeep

Whitespace-only changes.

app/routes/login.js

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+
var loginRoute = Ember.Route.extend(authMixin, {
4+
redirect: function(){
5+
if(this.get('session.isAuthenticated')){
6+
this.transitionTo('/');
7+
}
8+
},
9+
10+
renderTemplate: function(){
11+
this.render('login', {outlet: 'login'});
12+
}
13+
});
14+
export default loginRoute;

app/templates/login.hbs

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>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cli-admin-auth",
3-
"version": "0.0.0",
3+
"version": "0.0.1",
44
"description": "The default blueprint for ember-cli addons.",
55
"directories": {
66
"doc": "doc",

0 commit comments

Comments
 (0)