Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions user-accounts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,12 @@ seneca.use('user')


// the auth plugin handles HTTP authentication
seneca.use('auth',{
// redirects after login are needed for traditional multi-page web apps
redirect:{
login: {
win: '/account',
fail: '/login#failed'
},
register: {
win: '/account',
fail: '/#failed'
}
}
})
seneca.use('auth', options.auth)

// the local-auth handles local auth strategy
seneca.use('local-auth')
seneca.use('facebook-auth', options.facebook || {})
seneca.use('twitter-auth', options.twitter || {})


// use the express module in the normal way
Expand Down
44 changes: 33 additions & 11 deletions user-accounts/config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,40 @@ module.exports = {
main: {
port: 3000
},

auth: {
service: {
twitter: {
key: "TWITTER_KEY",
secret: "TWITTER_SECRET",
urlhost: "http://localhost:3000"
"facebook" : {
"appId" : "FB_ID",
"appSecret" : "FB_SECRET",
"urlhost" : "http://localhost:3000",
"serviceParams": {
"scope" : [
"email"
]
}
},
"twitter" : {
"apiKey" : "TWITTER_KEY",
"apiSecret" : "TWITTER_SECRET",
"urlhost" : "http://localhost:3000"
},
"auth": {
// redirects after login are needed for traditional multi-page web apps
redirect:{
// * when using multi-page web apps always should be true to allow redirects
// * when using single-page web apps always should be false to disable redirects
// except for register - when callback is called from external auth sources - facebook/twitter/others
always: true,
login: {
win: '/account',
fail: '/login#failed'
},
logout: {
win: '/',
fail: '/'
},
facebook: {
key: "FACEBOOK_ID",
secret: "FACEBOOK_SECRET",
urlhost: "http://localhost:3000"
register: {
always: true,
win: '/account',
fail: '/#failed'
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions user-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@
"author": "Richard Rodger",
"license": "MIT",
"dependencies": {
"express": "~4.9.5",
"body-parser": "~1.9.0",
"cookie-parser": "~1.3.2",
"method-override": "~2.2.0",
"express-session": "~1.8.2",
"serve-static": "~1.6.3",
"optimist": "~0.6.1",
"ejs": "~1.0.0",
"ejs-locals": "~1.0.2",
"express": "~4.9.5",
"express-session": "~1.8.2",
"method-override": "~2.2.0",
"optimist": "~0.6.1",
"seneca": "plugin",
"seneca-user": "~0.2.10",
"seneca-auth": "~0.4.0",
"seneca-admin": "~0.2.0",
"seneca-auth": "~0.4.0",
"seneca-data-editor": "~0.2.0",
"seneca-facebook-auth": "^0.1.0",
"seneca-jsonrest-api": "~0.3.1",
"seneca-local-auth": "~0.0.3",
"seneca-perm": "~0.4.0",
"seneca-data-editor": "~0.2.0"
"seneca-user": "~0.2.10",
"serve-static": "~1.6.3"
}
}
6 changes: 4 additions & 2 deletions user-accounts/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
</head>
<body>

<a href="/login">Multi-page App Login</a><br />
<a href="/single.html">Single-page App Login</a><br />
<a href="/login">Multi-page App Login</a> (make sure that redirect.always is true - to automatically redirect to desired page)
<br />
<a href="/single.html">Single-page App Login</a> (make sure that redirect.always is false - no redirect is required)
<br />

<br />
<a href="/auth/twitter">Twitter Login</a><br />
Expand Down
14 changes: 7 additions & 7 deletions user-accounts/public/js/user-accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ $(function(){
username: $('#username').val(),
password: $('#password').val()
}
http.post('/auth/login',data,showAccount)
$.post('/auth/login',data,showAccount)
return false
})

$('#logout').click(function(){
http.post('/auth/logout',{},showLogin)
$.post('/auth/logout',{},showLogin)
})


http.get('/auth/instance',showAccount)
$.get('/auth/user',showAccount)
})


function showAccount(err,instance) {
if( err ) return console.log(err);
function showAccount(instance) {
if( !instance.ok ) return console.log(instance.why);

if( instance.user ) {
$('#user_name').text(instance.user.name)
Expand All @@ -30,8 +30,8 @@ function showAccount(err,instance) {
}
}

function showLogin(err) {
if( err ) return console.log(err);
function showLogin(data) {
if( !data.ok ) return console.log(data.why);

$('#content_login').slideDown()
$('#content_account').slideUp()
Expand Down