Created
September 11, 2014 23:15
-
-
Save akiva/e4e5f8e2265a549b6d1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var TL = require('timeline-core'); | |
// var LoginView = require('./views/login')(TL); | |
// var CreateStoryView = require('./views/create-story')(TL); | |
// var StoriesView = require('./views/featured-stories')(TL); | |
TL.Router | |
.add('/', function() { | |
var loginPresenter = new TL.core.Presenter({ | |
channel: 'login', | |
events: TL.events, | |
view: new TL.core.View({ | |
template: require('../templates/login.jade') | |
}) | |
.setTargetElement('body') | |
}); | |
loginPresenter.events.subscribe( | |
'login', | |
'app:start', | |
function() { | |
this.view.render(); | |
}.bind(loginPresenter) | |
); | |
loginPresenter.events.subscribe( | |
'login', | |
'submit:login', | |
function() { | |
console.log('inside submit:login'); | |
var userAuthenticator = new UserAuthenticator({ | |
api: TL.api, | |
authToken: TL.authToken | |
}); | |
var userPwd = document.querySelector('.pwd').value; | |
var userEmail = document.querySelector('.email').value; | |
userAuthenticator.authenticate({ | |
email: userEmail, | |
password: userPwd | |
}, function(err) { | |
if(err === null){ | |
console.log('Login Successful.'); | |
page('/stories'); | |
} else { | |
console.log('Login failed: ', err); | |
} | |
}); | |
}.bind(loginPresenter) | |
); | |
loginPresenter.events.publish('login', 'app:start'); | |
loginPresenter.view.addEventListener('click', function() { | |
console.log('clicked button'); | |
loginPresenter.events.publish('login', 'submit:login'); | |
}, '.submit'); | |
}); | |
// .add('/stories', CreateStoryView.create) | |
// .add('/stories/featured', StoriesView.getFeatured); | |
TL.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment