Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
frontend-auth
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
143960ce
authored
2017-06-29 16:25:21 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
API CHANGE: login/logout now return a deferred.
1 parent
a6c22fd0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
11 deletions
src/scripts/Auth.js
src/scripts/Auth.js
View file @
143960c
...
...
@@ -78,6 +78,7 @@ define(function(require) {
}
},
this
);
this
.
login
=
function
()
{
var
deferred
=
$
.
Deferred
();
fbLoaded
.
done
(
function
(
FB
)
{
FB
.
login
(
function
(
response
)
{
self
.
set
({
...
...
@@ -85,11 +86,13 @@ define(function(require) {
'authResponse'
:
response
.
authResponse
,
});
self
.
trigger
(
'provider:logged-in'
);
deferred
.
resolve
();
});
});
return
self
;
return
deferred
.
promise
()
;
};
this
.
logout
=
function
()
{
var
deferred
=
$
.
Deferred
();
fbLoaded
.
done
(
function
(
FB
)
{
if
(
self
.
get
(
'authResponse'
))
{
FB
.
logout
(
function
(
response
)
{
...
...
@@ -98,12 +101,14 @@ define(function(require) {
'authResponse'
:
null
,
});
self
.
trigger
(
'provider:logged-out'
);
deferred
.
resolve
();
});
}
else
{
self
.
trigger
(
'provider:logged-out'
);
deferred
.
resolve
();
}
});
return
self
;
return
deferred
.
promise
()
;
};
this
.
attachProviderData
=
function
(
data
)
{
var
authResponse
=
this
.
get
(
'authResponse'
)
||
{};
...
...
@@ -125,11 +130,11 @@ define(function(require) {
this
.
login
=
function
()
{
// TODO: possibly fetch userName/password from browser.localStorage
this
.
trigger
(
'provider:logged-in'
);
return
this
;
return
$
.
Deferred
().
resolve
().
promise
()
;
};
this
.
logout
=
function
()
{
this
.
trigger
(
'provider:logged-out'
);
return
this
;
return
$
.
Deferred
().
resolve
().
promise
()
;
};
this
.
attachProviderData
=
function
(
data
)
{
_
.
extend
(
data
,
{
...
...
@@ -235,18 +240,18 @@ define(function(require) {
})).
always
(
function
()
{
ready
.
resolve
();
});
var
providers
=
this
.
get
(
'providers'
);
_
.
each
(
providers
.
keys
(),
function
(
providerKey
)
{
providers
.
get
(
providerKey
).
on
(
'provider:logged-in'
,
function
()
{
api
(
'auth:login:'
+
providerKey
,
addProviderData
(
providerKey
));
});
});
},
this
));
this
.
login
=
function
(
how
)
{
var
provider
=
how
?
this
.
get
(
'providers'
).
get
(
how
)
:
null
;
var
result
;
if
(
provider
)
{
provider
.
login
();
result
=
provider
.
login
().
then
(
function
()
{
return
api
(
'auth:login:'
+
how
,
addProviderData
(
how
));
});
}
else
{
result
=
$
.
Deferred
().
resolve
().
promise
();
}
return
result
;
};
this
.
logout
=
function
()
{
_
.
invoke
(
this
.
get
(
'providers'
).
values
(),
'logout'
);
...
...
Please
register
or
sign in
to post a comment