mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Add Google Signin (#7969)
* 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
This commit is contained in:
committed by
Matteo Pagliazzi
parent
941000d737
commit
e3b484b29a
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
|
||||
angular.module('habitrpg')
|
||||
.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','ApiUrl', '$modal', 'Analytics',
|
||||
function($scope, $rootScope, User, $http, $location, $window, ApiUrl, $modal, Analytics) {
|
||||
.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','ApiUrl', '$modal', 'Alert', 'Analytics', 'Auth',
|
||||
function($scope, $rootScope, User, $http, $location, $window, ApiUrl, $modal, Alert, Analytics, Auth) {
|
||||
$scope.Analytics = Analytics;
|
||||
|
||||
$scope.logout = function() {
|
||||
@@ -14,30 +14,6 @@ angular.module('habitrpg')
|
||||
$window.location.href = '/logout';
|
||||
};
|
||||
|
||||
var runAuth = function(id, token) {
|
||||
User.authenticate(id, token, function(err) {
|
||||
if(!err) $scope.registrationInProgress = false;
|
||||
Analytics.login();
|
||||
Analytics.updateUser();
|
||||
$window.location.href = ('/' + window.location.hash);
|
||||
});
|
||||
};
|
||||
|
||||
function errorAlert(data, status, headers, config) {
|
||||
$scope.registrationInProgress = false;
|
||||
if (status === 0) {
|
||||
$window.alert(window.env.t('noReachServer'));
|
||||
} else if (status === 400 && data.errors && _.isArray(data.errors)) { // bad requests
|
||||
data.errors.forEach(function (err) {
|
||||
$window.alert(err.message);
|
||||
});
|
||||
} else if (!!data && !!data.error) {
|
||||
$window.alert(data.message);
|
||||
} else {
|
||||
$window.alert(window.env.t('errorUpCase') + ' ' + status);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.registrationInProgress = false;
|
||||
|
||||
$scope.register = function() {
|
||||
@@ -60,9 +36,12 @@ angular.module('habitrpg')
|
||||
}
|
||||
|
||||
$http.post(url, scope.registerVals).success(function(res, status, headers, config) {
|
||||
runAuth(res.data._id, res.data.apiToken);
|
||||
Auth.runAuth(res.data._id, res.data.apiToken);
|
||||
Analytics.register();
|
||||
}).error(errorAlert);
|
||||
}).error(function(data, status, headers, config) {
|
||||
$scope.registrationInProgress = false;
|
||||
Alert.authErrorAlert(data, status, headers, config)
|
||||
});
|
||||
};
|
||||
|
||||
$scope.auth = function() {
|
||||
@@ -73,8 +52,8 @@ angular.module('habitrpg')
|
||||
//@TODO: Move all the $http methods to a service
|
||||
$http.post(ApiUrl.get() + "/api/v3/user/auth/local/login", data)
|
||||
.success(function(res, status, headers, config) {
|
||||
runAuth(res.data.id, res.data.apiToken);
|
||||
}).error(errorAlert);
|
||||
Auth.runAuth(res.data.id, res.data.apiToken);
|
||||
}).error(Alert.authErrorAlert);
|
||||
};
|
||||
|
||||
$scope.playButtonClick = function() {
|
||||
@@ -113,8 +92,8 @@ angular.module('habitrpg')
|
||||
hello(network).login({scope:'email'}).then(function(auth){
|
||||
$http.post(ApiUrl.get() + "/api/v3/user/auth/social", auth)
|
||||
.success(function(res, status, headers, config) {
|
||||
runAuth(res.data.id, res.data.apiToken);
|
||||
}).error(errorAlert);
|
||||
Auth.runAuth(res.data.id, res.data.apiToken);
|
||||
}).error(Alert.authErrorAlert);
|
||||
}, function( e ){
|
||||
alert("Signin error: " + e.message );
|
||||
});
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
// Make user and settings available for everyone through root scope.
|
||||
habitrpg.controller('SettingsCtrl',
|
||||
['$scope', 'User', '$rootScope', '$http', 'ApiUrl', 'Guide', '$location', '$timeout', 'Content', 'Notification', 'Shared', '$compile',
|
||||
function($scope, User, $rootScope, $http, ApiUrl, Guide, $location, $timeout, Content, Notification, Shared, $compile) {
|
||||
['$scope', 'User', '$rootScope', '$http', 'ApiUrl', 'Guide', '$location', '$timeout', 'Content', 'Notification', 'Shared', 'Social', '$compile',
|
||||
function($scope, User, $rootScope, $http, ApiUrl, Guide, $location, $timeout, Content, Notification, Shared, Social, $compile) {
|
||||
var RELEASE_ANIMAL_TYPES = {
|
||||
pets: 'releasePets',
|
||||
mounts: 'releaseMounts',
|
||||
both: 'releaseBoth',
|
||||
};
|
||||
|
||||
var SOCIAL_AUTH_NETWORKS = Shared.constants.SUPPORTED_SOCIAL_NETWORKS;
|
||||
$scope.SOCIAL_AUTH_NETWORKS = SOCIAL_AUTH_NETWORKS;
|
||||
|
||||
// FIXME we have this re-declared everywhere, figure which is the canonical version and delete the rest
|
||||
// $scope.auth = function (id, token) {
|
||||
// User.authenticate(id, token, function (err) {
|
||||
@@ -287,6 +290,40 @@ habitrpg.controller('SettingsCtrl',
|
||||
return Math.floor(numberOfHourglasses);
|
||||
};
|
||||
|
||||
$scope.hasBackupAuthOption = function(user, checkedNetworkKey) {
|
||||
if (user.auth.local.username) {
|
||||
return true;
|
||||
}
|
||||
return _.find(SOCIAL_AUTH_NETWORKS, function (network) {
|
||||
if (network.key !== checkedNetworkKey) {
|
||||
if (user.auth.hasOwnProperty(network.key)) {
|
||||
return user.auth[network.key].id;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.hasSocialAuth = function (user) {
|
||||
return _.find(SOCIAL_AUTH_NETWORKS, function (network) {
|
||||
if (user.auth.hasOwnProperty(network.key)) {
|
||||
return user.auth[network.key].id;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteSocialAuth = function (networkKey) {
|
||||
var network = _.find(SOCIAL_AUTH_NETWORKS, function (network) {
|
||||
return network.key === networkKey;
|
||||
});
|
||||
|
||||
$http.delete(ApiUrl.get() + "/api/v3/user/auth/social/"+networkKey).success(function(){
|
||||
Notification.text(env.t("detachedSocial", {network: network.name}));
|
||||
User.sync();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.socialLogin = Social.socialLogin;
|
||||
|
||||
function _calculateNextCron() {
|
||||
$scope.dayStart;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user