mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
* Start adding google login * fix local js issue * implement syntax suggestions * fix delete social tests * Add service for authentication alerts * fix social login tests * make suggested google sign in changes * fix accidentally deleted code * refactor social network sign in * fix incorrect find * implement suggested google sign in changes * fix(tests): Inject fake Auth module for auth controller * fix(test): prevent social service from causing page reload * fix loading user info * Use lodash's implimentation of find for IE compatibility * chore: increase test coverage around deletion route * chore: clean up social auth test * chore: Fix social login tests * remove profile from login scope * fix(api): Allow social accounts to deregister as user has auth backup * temporarily disable google login button
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
(function(){
|
|
angular
|
|
.module('habitrpg')
|
|
.factory('Social', socialFactory);
|
|
|
|
socialFactory.$inject = [
|
|
'$http','ApiUrl', 'Alert', 'Auth'
|
|
];
|
|
|
|
function socialFactory($http, ApiUrl, Alert, Auth) {
|
|
|
|
function loadWidgets() {
|
|
// Facebook
|
|
if (typeof FB === 'undefined') {
|
|
(function(d, s, id) {
|
|
var js, fjs = d.getElementsByTagName(s)[0];
|
|
if (d.getElementById(id)) return;
|
|
js = d.createElement(s); js.id = id;
|
|
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
|
|
fjs.parentNode.insertBefore(js, fjs);
|
|
}(document, 'script', 'facebook-jssdk'));
|
|
} else {
|
|
FB.XFBML.parse(); // http://stackoverflow.com/questions/29133563/
|
|
}
|
|
|
|
// Tumblr
|
|
$.getScript('https://assets.tumblr.com/share-button.js');
|
|
|
|
// Twitter
|
|
if (typeof twttr === 'undefined') {
|
|
$.getScript('https://platform.twitter.com/widgets.js');
|
|
} else {
|
|
twttr.widgets.load();
|
|
}
|
|
}
|
|
|
|
hello.init({
|
|
facebook : window.env.FACEBOOK_KEY,
|
|
google : window.env.GOOGLE_CLIENT_ID
|
|
});
|
|
|
|
function socialLogin(network){
|
|
hello(network).login({scope:['email']}).then(function(auth){
|
|
$http.post(ApiUrl.get() + "/api/v3/user/auth/social", auth)
|
|
.success(function(res, status, headers, config) {
|
|
Auth.runAuth(res.data.id, res.data.apiToken);
|
|
}).error(Alert.authErrorAlert);
|
|
}, function( err ){
|
|
alert("Signin error: " + err.message );
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
loadWidgets: loadWidgets,
|
|
socialLogin: socialLogin
|
|
}
|
|
}
|
|
}());
|