mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-02-02 04:29:25 +01:00
56 lines
2.0 KiB
JavaScript
56 lines
2.0 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('users')
|
|
.controller('SocialAccountsController', SocialAccountsController);
|
|
|
|
SocialAccountsController.$inject = ['$state', '$window', 'UsersService', 'Authentication', 'Notification'];
|
|
|
|
function SocialAccountsController($state, $window, UsersService, Authentication, Notification) {
|
|
var vm = this;
|
|
|
|
vm.user = Authentication.user;
|
|
vm.hasConnectedAdditionalSocialAccounts = hasConnectedAdditionalSocialAccounts;
|
|
vm.isConnectedSocialAccount = isConnectedSocialAccount;
|
|
vm.removeUserSocialAccount = removeUserSocialAccount;
|
|
vm.callOauthProvider = callOauthProvider;
|
|
|
|
// Check if there are additional accounts
|
|
function hasConnectedAdditionalSocialAccounts() {
|
|
return (vm.user.additionalProvidersData && Object.keys(vm.user.additionalProvidersData).length);
|
|
}
|
|
|
|
// Check if provider is already in use with current user
|
|
function isConnectedSocialAccount(provider) {
|
|
return vm.user.provider === provider || (vm.user.additionalProvidersData && vm.user.additionalProvidersData[provider]);
|
|
}
|
|
|
|
// Remove a user social account
|
|
function removeUserSocialAccount(provider) {
|
|
|
|
UsersService.removeSocialAccount(provider)
|
|
.then(onRemoveSocialAccountSuccess)
|
|
.catch(onRemoveSocialAccountError);
|
|
}
|
|
|
|
function onRemoveSocialAccountSuccess(response) {
|
|
// If successful show success message and clear form
|
|
Notification.success({message: '<i class="glyphicon glyphicon-ok"></i> Removed successfully!'});
|
|
vm.user = Authentication.user = response;
|
|
}
|
|
|
|
function onRemoveSocialAccountError(response) {
|
|
Notification.error({message: response.message, title: '<i class="glyphicon glyphicon-remove"></i> Remove failed!'});
|
|
}
|
|
|
|
// OAuth provider request
|
|
function callOauthProvider(url) {
|
|
url += '?redirect_to=' + encodeURIComponent($state.$current.url.prefix);
|
|
|
|
// Effectively call OAuth authentication route:
|
|
$window.location.href = url;
|
|
}
|
|
}
|
|
}());
|