diff --git a/app/account/account.routes.js b/app/account/account.routes.js index 84e263a4e..16e602e4e 100644 --- a/app/account/account.routes.js +++ b/app/account/account.routes.js @@ -14,103 +14,6 @@ import angular from 'angular' abstract: true, data: { authRequired: false - }, - onEnter: ['$state', '$location', '$stateParams', 'TcAuthService', 'logger', - function($state, $location, $stateParams, TcAuthService, logger) { - logger.debug('Checking for authentication...') - if (TcAuthService.isAuthenticated()) { - // redirect to next if exists else dashboard - if ($stateParams.next) { - logger.debug('Redirecting: ' + $stateParams.next) - window.location.href = decodeURIComponent($stateParams.next) - } else { - $state.go('dashboard') - } - } - }] - }, - 'login': { - parent: 'auth', - url: '/login/?next&code&state&status&userJWTToken&utm_source&utm_medium&utm_campaign', - params: { 'notifyReset': false }, - data: { - title: 'Login' - }, - views: { - 'header@': { - template: require('../layout/header/account-header')() - }, - 'container@': { - template: require('./login/login')(), - controller: 'LoginController', - controllerAs: 'vm' - }, - 'footer@': { - controller: 'FooterController as vm', - template: require('../layout/footer/account-footer')() - } - }, - controller: 'LoginController' - }, - 'register': { - parent: 'auth', - url: '/register/?next&utm_source&utm_medium&utm_campaign', - data: { - title: 'Join' - }, - views: { - 'header@': { - template: require('../layout/header/account-header')() - }, - 'container@': { - template: require('./register/register')(), - controller: 'RegisterController', - controllerAs: 'vm' - }, - 'footer@': { - controller: 'FooterController as vm', - template: require('../layout/footer/account-footer')() - } - } - }, - 'registeredSuccessfully': { - url: '/registered-successfully/', - data: { - title: 'Registered', - authRequired: false - }, - views: { - 'header@': { - template: require('../layout/header/account-header')() - }, - 'container@': { - template: require('./register/registered-successfully')() - }, - 'footer@': { - controller: 'FooterController as vm', - template: require('../layout/footer/account-footer')() - } - } - }, - 'resetPassword': { - parent: 'auth', - url: '/reset-password/?token&handle', - data: { - title: 'Reset Password' - }, - views: { - 'header@': { - template: require('../layout/header/account-header')() - }, - 'container@': { - template: require('./reset-password/reset-password')(), - controller: 'ResetPasswordController', - controllerAs: 'vm' - }, - 'footer@': { - controller: 'FooterController as vm', - template: require('../layout/footer/account-footer')() - } } }, logout: { diff --git a/app/account/login/login.controller.js b/app/account/login/login.controller.js deleted file mode 100644 index 27dd59aa6..000000000 --- a/app/account/login/login.controller.js +++ /dev/null @@ -1,39 +0,0 @@ -import angular from 'angular' -import { getCurrentUser, loadUser } from '../../services/userv3.service.js' - -(function() { - 'use strict' - - angular.module('tc.account').controller('LoginController', LoginController) - - LoginController.$inject = ['logger', '$state', '$stateParams', '$window', '$rootScope', 'Helpers', 'CONSTANTS'] - - function LoginController(logger, $state, $stateParams, $window, $rootScope, Helpers, CONSTANTS) { - var vm = this - vm.$stateParams = $stateParams - - activate() - - function activate() { - var currentUser = getCurrentUser() - logger.debug('checking for logged in user...' + currentUser) - if (!currentUser) { - logger.debug('loading user...') - var next = $stateParams.next ? $stateParams.next : 'dashboard' - loadUser().then(function(token) { - logger.debug('successful login with token ' + token) - $rootScope.$broadcast(CONSTANTS.EVENT_USER_LOGGED_IN) - logger.debug('reidrecting to ' + next) - Helpers.redirectPostLogin(next) - }, function() { - logger.debug('State requires authentication, and user is not logged in, redirecting') - // setup redirect for post login - var retUrl = $state.href(next, {}, {absolute: true}) - logger.debug('redirecting to accounts app for login...') - $window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(retUrl) - }) - } - } - } - -})() diff --git a/app/account/login/login.jade b/app/account/login/login.jade deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/account/login/login.spec.js b/app/account/login/login.spec.js deleted file mode 100644 index 8bd5b5c3c..000000000 --- a/app/account/login/login.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -/*eslint no-undef:0*/ -describe('Login Controller', function() { - var controller - var scope - - beforeEach(function() { - bard.appModule('topcoder') - bard.inject('$controller', '$rootScope') - }) - - beforeEach(function() { - scope = $rootScope.$new() - controller = $controller('LoginController', { - $scope : scope - }) - $rootScope.$apply() - }) - - bard.verifyNoOutstandingHttpRequests() - - it('should be created successfully', function() { - expect(controller).to.be.defined - }) -}) diff --git a/app/account/register/register.controller.js b/app/account/register/register.controller.js deleted file mode 100644 index a08b1d86d..000000000 --- a/app/account/register/register.controller.js +++ /dev/null @@ -1,143 +0,0 @@ -import angular from 'angular' -import _ from 'lodash' - -(function() { - 'use strict' - - angular.module('tc.account').controller('RegisterController', RegisterController) - - RegisterController.$inject = ['logger', 'CONSTANTS', '$state', '$stateParams', 'TcAuthService', 'UserService', 'ISO3166', 'Helpers'] - - function RegisterController(logger, CONSTANTS, $state, $stateParams, TcAuthService, UserService, ISO3166, Helpers) { - var vm = this - vm.registering = false - // prepares utm params, if available - var utm = { - source : $stateParams && $stateParams.utm_source ? $stateParams.utm_source : '', - medium : $stateParams && $stateParams.utm_medium ? $stateParams.utm_medium : '', - campaign : $stateParams && $stateParams.utm_campaign ? $stateParams.utm_campaign : '' - } - - // Set default for toggle password directive - vm.defaultPlaceholder = 'Create Password' - vm.busyMessage = CONSTANTS.BUSY_PROGRESS_MESSAGE - - vm.countries = ISO3166.getAllCountryObjects() - - vm.updateCountry = function (angucompleteCountryObj) { - var countryCode = _.get(angucompleteCountryObj, 'originalObject.code', undefined) - - var isValidCountry = _.isUndefined(countryCode) ? false : true - vm.registerForm.country.$setValidity('required', isValidCountry) - vm.isValidCountry = isValidCountry - if (isValidCountry) { - vm.country = angucompleteCountryObj.originalObject - } - } - - vm.register = function() { - vm.registering = true - var userInfo = { - handle: vm.username, - firstName: vm.firstname, - lastName: vm.lastname, - email: vm.email, - country: { - code: Helpers.npad(vm.country.code, 3), - isoAlpha3Code: vm.country.alpha3, - isoAlpha2Code: vm.country.alpha2 - }, - utmSource: utm.source, - utmMedium: utm.medium, - utmCampaign: utm.campaign - } - - if (!vm.isSocialRegistration) { - userInfo.credential = { password: vm.password } - } else { - userInfo.profile = { - userId: vm.socialUserId, - name: vm.firstname + ' ' + vm.lastname, - email: vm.socialProfile.email, - emailVerified: vm.socialProfile.email_verified, - providerType: vm.socialProvider, - context: { - handle: vm.username, - accessToken: vm.socialContext.accessToken - } - } - } - - var body = { - param: userInfo, - options: { - afterActivationURL: $state.href('skillPicker', {}, {absolute: true}) - } - } - - TcAuthService.register(body) - .then(function(data) { - vm.registering = false - logger.debug('Registered successfully') - - // In the future, go to dashboard - $state.go('registeredSuccessfully') - }) - .catch(function(err) { - vm.registering = false - - logger.error('Error in registering new user', err) - }) - } - - vm.socialRegister = function(provider) { - TcAuthService.socialRegistration(provider, null) - .then(function(resp) { - if (resp.status === 'SUCCESS') { - var socialData = resp.data - vm.socialUserId = socialData.socialUserId - vm.username = socialData.username - if (socialData.username) { - vm.registerForm.username.$setDirty() - } - vm.firstname = socialData.firstname - if (socialData.firstname) { - vm.registerForm.firstname.$setDirty() - } - vm.lastname = socialData.lastname - if (socialData.lastname) { - vm.registerForm.lastname.$setDirty() - } - if (socialData.email) { - vm.registerForm.email.$setDirty() - } - vm.email = socialData.email - vm.socialProfile = socialData.socialProfile - vm.socialProvider = socialData.socialProvider - vm.socialContext= {'accessToken': socialData.accessToken} - vm.isSocialRegistration = true - } else { - vm.isSocialRegistration = false - } - }) - .catch(function(err) { - switch (err.status) { - case 'SOCIAL_PROFILE_ALREADY_EXISTS': - vm.errMsg = 'An account with that profile already exists. Please login to access your account.' - - logger.error('Error registering user with social account', err) - - break - - default: - vm.errMsg = 'Whoops! Something went wrong. Please try again later.' - - logger.error('Error registering user with social account', err) - } - vm.isSocialRegistration = false - }) - } - - vm.$stateParams = $stateParams - } -})() diff --git a/app/account/register/register.jade b/app/account/register/register.jade deleted file mode 100644 index b850e94e4..000000000 --- a/app/account/register/register.jade +++ /dev/null @@ -1,123 +0,0 @@ -.register-container - header - a.logo-link(href="/") - img(src=require("../../../assets/images/logo_mobile.svg"), alt="Topcoder Logo") - .arrow - //- h1 Join the Topcoder technology community to earn, learn, and connect - h1 Join Topcoder - - form(name="vm.registerForm", role="form", ng-submit="vm.registerForm.$valid && vm.register()", novalidate, autocomplete="off") - - // Stops Chrome from autofilling and autocompleting (along with autocomplete="off" on the form) - input(autocomplete="false", name="hidden", type="text", style="display:none;") - - p.form-error(ng-show="vm.errMsg") {{vm.errMsg}} - - .first-last-names - input-sticky-placeholder(sticky-placeholder="First", ng-model="vm.firstname") - input(ng-model="vm.firstname", maxlength="64", name="firstname", placeholder="First Name", type="text", required) - - input-sticky-placeholder(sticky-placeholder="Last", ng-model="vm.lastname") - input(ng-model="vm.lastname", maxlength="64", name="lastname", placeholder="Last Name", type="text", required) - - .country-dropdown - angucomplete-alt( - input-name="country", - placeholder="Country", - pause="100", - selected-object="vm.updateCountry", - local-data="vm.countries", - initial-value="vm.countryObj", - search-fields="name", - title-field="name", - match-class="angucomplete-highlight", - - minlength="1" - ) - - .form-input-error(ng-show="vm.registerForm.country.$dirty && !vm.isValidCountry") - p.form-error(ng-show="!vm.isValidCountry") Please choose a country from the list - - .section-break - hr - - .validation-bar(ng-class="{ 'error-bar': (vm.registerForm.username.$error.usernameIsFree || vm.registerForm.username.$error.minlength || vm.registerForm.username.$error.maxlength), 'success-bar': (vm.registerForm.username.$valid && !vm.registerForm.username.$error.usernameIsFree) }") - input-sticky-placeholder(sticky-placeholder="Username", ng-model="vm.username") - input(ng-model="vm.username", ng-model-options="{ debounce: {'default': 500} }", ng-focus="vm.usernameTips = true", ng-blur="vm.usernameTips = false", ng-minlength="2", ng-maxlength="15", name="username", placeholder="Username", type="text", username-is-free, required) - - .tips.username-tips(ng-show="vm.usernameTips") - .arrow - h3 Username Tips: - - p Your username will be public - - p Please choose one that is between 2 and 15 characters - - p It can contain letters, numbers, and these characters: -_.{}[] - - .form-input-error(ng-if="vm.registerForm.username.$dirty && vm.registerForm.username.$invalid", ng-messages="vm.registerForm.username.$error") - p.form-error(ng-message="required") Please enter a username. - p.form-error(ng-message="usernameIsFree") {{vm.usernameErrorMessage}} - - p.form-error(ng-message="minlength") That username is not the correct length or format. - - p.form-error(ng-message="maxlength") That username is not the correct length or format. - - .validation-bar(ng-class="{ 'error-bar': (vm.registerForm.email.$dirty && vm.registerForm.email.$invalid), 'success-bar': (vm.registerForm.email.$valid) }") - input-sticky-placeholder.email(sticky-placeholder="Email", ng-model="vm.email") - input(ng-model="vm.email", ng-model-options="{ debounce: {'default': 500} }", ng-focus="vm.emailTips = true", ng-blur="vm.emailTips = false", name="email", placeholder="Enter Your Email", type="email", valid-email, email-is-available, required) - - .tips.email-tips(ng-show="vm.emailTips") - .arrow - h3 Email Tips: - - p Your email address will be private and not shared with anyone. - - p We'll occasionally send you emails related to your activities or interests. - - .form-input-error(ng-show="vm.registerForm.email.$dirty && vm.registerForm.email.$invalid", ng-messages="vm.registerForm.email.$error") - p.form-error(ng-message="emailIsAvailable") {{vm.emailErrorMessage}} - - p.form-error(ng-message="validEmail") {{vm.emailErrorMessage}} - - p.form-error(ng-message="required") Please enter an email address. - - .validation-bar(ng-class="{ 'success-bar': (vm.registerForm.password.$valid) }") - toggle-password-with-tips(ng-if="!vm.isSocialRegistration", placeholder="Create Password") - - .tips.password-tips(ng-show="vm.passwordFocus") - .arrow - //- h3 Password Tips: - - H3 Your password must have: - - p(ng-class="{ 'has-length-between-range': (vm.registerForm.password.$dirty && !vm.registerForm.password.$error.minlength && !vm.registerForm.password.$error.maxlength && !vm.registerForm.password.$error.required) }") At least 8 characters - - p(ng-class="{ 'has-letter': (vm.registerForm.password.$dirty && !vm.registerForm.password.$error.hasLetter) }") At least one letter - - p(ng-class="{ 'has-symbol-or-number': (vm.registerForm.password.$dirty && !vm.registerForm.password.$error.hasSymbolOrNumber) }") At least one number or symbol - - section.terms - p By clicking "Join" you agree to Topcoder's #[a(href="http://www.topcoder.com/community/how-it-works/terms/", target="_blank") Terms] and #[a(href="http://www.topcoder.com/community/how-it-works/privacy-policy/", target="_blank") Privacy Policy] - - button.tc-btn.tc-btn-large(type="submit", tc-busy-button, tc-busy-when="vm.registering", ng-disabled="vm.registerForm.$invalid", ng-show="vm.isValidCountry") Join - button.tc-btn.tc-btn-large.disabled(type="submit", ng-show="!vm.isValidCountry", disabled="disabled") Join - - section.login-options - p.tc-separator - span Or Register With - - ul.networks - li.network.github - a.ico(ng-click="vm.socialRegister('github')") - span Github - li.network.google-plus - a.ico(ng-click="vm.socialRegister('google-oauth2')") - span Google - li.network.facebook - a.ico(ng-click="vm.socialRegister('facebook')") - span Facebook - -.join-topcoder - span Have an account?   - a(ui-sref="login(vm.$stateParams)") Log in diff --git a/app/account/register/register.spec.js b/app/account/register/register.spec.js deleted file mode 100644 index c7b7a8a0e..000000000 --- a/app/account/register/register.spec.js +++ /dev/null @@ -1,36 +0,0 @@ -/*eslint no-undef:0*/ -describe('Register Controller', function() { - var controller - - beforeEach(function() { - bard.appModule('topcoder') - bard.inject('$controller', '$rootScope', '$q') - }) - - var state = { - href: function() { - return 'http://topcoder-dev.com/register/' - } - } - - beforeEach(function() { - var helperService = { - getCountyObjFromIP: function() { - return $q.when({name: 'United States', alpha2: 'US', alpha3: 'USA', code: '840'}) - } - } - - controller = $controller('RegisterController', { - $state: state, - Helpers: helperService - }) - - $rootScope.$apply() - }) - - bard.verifyNoOutstandingHttpRequests() - - it('should be created successfully', function() { - expect(controller).to.be.defined - }) -}) diff --git a/app/account/register/registered-successfully.jade b/app/account/register/registered-successfully.jade deleted file mode 100644 index 2fb567201..000000000 --- a/app/account/register/registered-successfully.jade +++ /dev/null @@ -1,7 +0,0 @@ -.registered-successfully-container - header - a.logo-link(href="/") - img(src=require("../../../assets/images/logo_mobile.svg"), alt="Topcoder Logo") - .arrow - - p.message Thanks for joining Topcoder.
We've sent you a confirmation link. Please check your email and click the link to activate your account. If you can't find the message, please email #[a(href="mailto:support@topcoder.com") support@topcoder.com]. diff --git a/app/account/reset-password/reset-password.controller.js b/app/account/reset-password/reset-password.controller.js deleted file mode 100644 index a396b2fc7..000000000 --- a/app/account/reset-password/reset-password.controller.js +++ /dev/null @@ -1,68 +0,0 @@ -import angular from 'angular' - -(function() { - 'use strict' - - angular.module('tc.account').controller('ResetPasswordController', ResetPasswordController) - - ResetPasswordController.$inject = ['$state', '$stateParams', 'UserService', 'TcAuthService'] - - function ResetPasswordController($state, $stateParams, UserService, TcAuthService) { - var vm = this - vm.token = $stateParams.token - vm.handle = $stateParams.handle - vm.defaultPlaceholder = 'Enter New Password' - - vm.clearState = function() { - vm.resetTokenSent = false - vm.resetTokenFailed = false - vm.alreadySent = false - vm.emailNotFound = false - vm.resetError = false - } - vm.clearState() - - vm.sendLink = function() { - if (vm.generateTokenForm.$valid) { - vm.loading = true - UserService.generateResetToken(vm.email).then( - function() { - vm.resetTokenSent = true - vm.loading = false - }, - function(err) { - if (err.status == 400) - vm.alreadySent = true - else if (err.status == 404) - vm.emailNotFound = true - - vm.resetTokenFailed = true - vm.loading = false - } - ) - } - } - - vm.resetPassword = function() { - vm.loading = true - if (vm.resetPasswordForm.$valid) { - UserService.resetPassword(vm.handle, vm.password, vm.token).then( - function() { - TcAuthService.login(vm.handle, vm.password).then( - function() { - $state.go('dashboard', { 'notifyReset': true }) - }, - function(err) { - $state.go('login', { 'notifyReset': true }) - } - ) - }, - function(err) { - vm.resetFailed = true - vm.loading = false - } - ) - } - } - } -})() diff --git a/app/account/reset-password/reset-password.jade b/app/account/reset-password/reset-password.jade deleted file mode 100644 index 4e82c86f0..000000000 --- a/app/account/reset-password/reset-password.jade +++ /dev/null @@ -1,83 +0,0 @@ -.reset-password-container(ng-show="!vm.resetTokenSent && !vm.token") - - header - a.logo-link(href="/") - img(src=require("../../../assets/images/logo_mobile.svg"), alt="Topcoder Logo") - - .arrow - - h1(class="header") PASSWORD RESET - - form.reset-form(name='vm.generateTokenForm', role="form", ng-submit="vm.generateTokenForm.$valid && vm.sendLink()", novalidate) - p.email-label Please enter your email address, and we'll send you a link to reset your password - - .validation-bar(ng-class="{ 'error-bar': (vm.generateTokenForm.email.$dirty && vm.generateTokenForm.email.$invalid), 'success-bar': (vm.generateTokenForm.email.$valid) }") - input-sticky-placeholder(sticky-placeholder="Email", ng-model="vm.email") - input(ng-model="vm.email", ng-focus="vm.emailTips = true", ng-blur="vm.emailTips = false", name="email", placeholder="EMAIL ADDRESS", type="email", valid-email, required) - - .tips.email-tips(ng-show="vm.emailTips") - .arrow - - h3 Email Tips: - - p Enter your email address and we'll get back to you with a reset link - - .form-errors - p.form-error(ng-show="vm.generateTokenForm.email.$dirty && vm.generateTokenForm.email.$invalid") Please enter a valid email address. - - p.form-error(ng-show="vm.alreadySent") You already requested a reset link recently. Please check your inbox or spam folder. If you have any trouble, please contact - a(href="mailto:support@topcoder.com?Subject=Unable%20to%20reset%20my%20password" target="_top") support@topcoder.com - - p.form-error(ng-show="vm.emailNotFound") We couldn't find a member with that email address. Please check that you entered it correctly. If you continue to have trouble, please contact - a(href="mailto:support@topcoder.com?Subject=Unable%20to%20reset%20my%20password" target="_top") support@topcoder.com - - p.form-error(ng-show="vm.unkownError") We were unable to send you a reset link because of a temporary problem. Please try again. If you continue to have trouble, please contact - a(href="mailto:support@topcoder.com?Subject=Unable%20to%20reset%20my%20password" target="_top") support@topcoder.com - - button.tc-btn(type="submit", ng-disabled='vm.generateTokenForm.email.$invalid || vm.loading', ng-class="{'enabled-button': vm.generateTokenForm.$valid && !vm.loading}") Get Reset Link - - a.link(ui-sref="login") Back to Login - -.reset-password-container(ng-show="vm.resetTokenSent") - header - a.logo-link(href="/") - img(src=require("../../../assets/images/logo_mobile.svg"), alt="Topcoder Logo") - - .arrow - - h1(class="header") Back on Track! - - p(class="m-b-lg") We have sent you an email with a link to reset your password. - - a.link(ui-sref="login") Back to Login - -.reset-password-container(ng-show="vm.token") - header - img(src=require("../../../assets/images/logo_mobile.svg"), alt="Topcoder Logo") - - .arrow - - h1(class="header") CREATE NEW PASSWORD - - form.reset-form(name='vm.resetPasswordForm', role="form", ng-submit="vm.resetPasswordForm.$valid && vm.resetPassword()", novalidate) - .validation-bar(ng-class="{ 'success-bar': (vm.resetPasswordForm.password.$valid) }") - toggle-password-with-tips - - .tips.password-tips(ng-show="vm.passwordFocus") - .arrow - - h3 Password Tips: - - p(ng-class="{ 'has-length-between-range': (vm.resetPasswordForm.password.$dirty && !vm.resetPasswordForm.password.$error.minlength && !vm.resetPasswordForm.password.$error.maxlength && !vm.resetPasswordForm.password.$error.required) }") Must be between 8 and 64 characters - - p(ng-class="{ 'has-letter': (vm.resetPasswordForm.password.$dirty && !vm.resetPasswordForm.password.$error.hasLetter) }") At least one letter - - p(ng-class="{ 'has-symbol-or-number': (vm.resetPasswordForm.password.$dirty && !vm.resetPasswordForm.password.$error.hasSymbolOrNumber) }") At least one number or symbol - - .form-errors - p.form-error(ng-show="vm.resetFailed") We were unable to reset your password. Please request another reset link. If you continue to have trouble, please contact - a(href="mailto:support@topcoder.com?Subject=Unable%20to%20reset%20my%20password" target="_top") support@topcoder.com - - button.tc-btn(type="submit", ng-disabled='vm.resetPasswordForm.password.$invalid || vm.loading', ng-class="{'enabled-button': vm.resetPasswordForm.$valid && !vm.loading}") Set Password - - a.link(ui-sref="login") Back to Login diff --git a/app/account/reset-password/reset-password.spec.js b/app/account/reset-password/reset-password.spec.js deleted file mode 100644 index 4e6377ff7..000000000 --- a/app/account/reset-password/reset-password.spec.js +++ /dev/null @@ -1,28 +0,0 @@ -/*eslint no-undef:0*/ -describe('Reset Password Controller', function() { - var controller - - beforeEach(function() { - bard.appModule('topcoder') - bard.appModule('tc.profile') - bard.inject(this, '$controller') - - controller = $controller('ResetPasswordController', { - $scope: {}, - $state: { - href: function() { - return 'http://topcoder-dev.com/reset-password/' - } - }, - handle: 'rakesh', - token: 'doesntmatter' - }) - }) - - bard.verifyNoOutstandingHttpRequests() - - it('should be created successfully', function() { - expect(controller).to.be.defined - }) - -}) diff --git a/app/services/tcAuth.service.js b/app/services/tcAuth.service.js index db642c8ed..ed73bcf6e 100644 --- a/app/services/tcAuth.service.js +++ b/app/services/tcAuth.service.js @@ -6,73 +6,15 @@ import { getCurrentUser, logout as doLogout } from './userv3.service.js' angular.module('tc.services').factory('TcAuthService', TcAuthService) - TcAuthService.$inject = ['CONSTANTS', 'auth', '$rootScope', '$q', 'logger', '$timeout', 'UserService', 'AuthTokenService', 'Helpers', 'ApiService', 'store', '$http'] + TcAuthService.$inject = ['CONSTANTS', '$rootScope', '$q', 'logger', '$timeout', 'UserService', 'AuthTokenService', 'Helpers', 'ApiService', 'store', '$http'] - function TcAuthService(CONSTANTS, auth, $rootScope, $q, logger, $timeout, UserService, AuthTokenService, Helpers, ApiService, store, $http) { - var auth0 = auth + function TcAuthService(CONSTANTS, $rootScope, $q, logger, $timeout, UserService, AuthTokenService, Helpers, ApiService, store, $http) { var service = { - socialRegistration: socialRegistration, logout: logout, - register: register, isAuthenticated: isAuthenticated } return service - function socialRegistration(provider, state) { - return $q(function(resolve, reject) { - // supported backends - var providers = ['facebook', 'google-oauth2', 'twitter', 'github'] - if (providers.indexOf(provider) > -1) { - auth0.signin({ - popup: true, - connection: provider, - scope: 'openid profile offline_access', - state: state - }, - function(profile, idToken, accessToken, state, refreshToken) { - var socialData = Helpers.getSocialUserData(profile, accessToken) - - UserService.validateSocialProfile(socialData.socialUserId, socialData.socialProvider) - .then(function(resp) { - logger.debug(JSON.stringify(resp)) - if (resp.valid) { - // success - var result = { - status: 'SUCCESS', - data: socialData - } - logger.debug('socialRegister Result: ' + JSON.stringify(result)) - resolve(result) - } else { - if (resp.reasonCode === 'ALREADY_IN_USE') { - logger.error('Social handle already exists') - reject({ - status: 'SOCIAL_PROFILE_ALREADY_EXISTS' - }) - } - } - - }) - .catch(function(err) { - logger.debug(JSON.stringify(err)) - }) - }, - function(error) { - logger.warning('onSocialLoginFailure ' + JSON.stringify(error)) - reject(error) - } - ) - } else { - logger.error('Unsupported social login provider', provider) - - reject({ - status: 'FAILED', - 'error': 'Unsupported social login provider \'' + provider + '\'' - }) - } - }) - } - function logout() { // logout of all browsers return doLogout().then(function() { @@ -80,13 +22,6 @@ import { getCurrentUser, logout as doLogout } from './userv3.service.js' }) } - function register(userInfo) { - // api params - // required: ["firstName", "lastName", "handle", "country", "email"], - // optional: ["password", "socialProviderId", "socialUserName", "socialEmail", "socialEmailVerified", "regSource", "socialUserId", "utm_source", "utm_medium", "utm_campaign"] - return UserService.createUser(userInfo) - } - function isAuthenticated() { logger.debug('AuthTokenService.getV2Token(): ' + AuthTokenService.getV2Token()) logger.debug('AuthTokenService.getTCSSOToken(): ' + AuthTokenService.getTCSSOToken()) diff --git a/app/services/userv3.service.js b/app/services/userv3.service.js index 1e4362e65..cfb0f8c3d 100644 --- a/app/services/userv3.service.js +++ b/app/services/userv3.service.js @@ -3,9 +3,6 @@ import angular from 'angular' require('./authv3.module.js') -// import includes from 'lodash/includes' -// import merge from 'lodash/merge' -// TODO: Move registration to accounts.topcoder.com import { registerUser} from 'tc-accounts/core/auth.js' import { decodeToken, getFreshToken, logout as doLogout } from 'tc-accounts'