Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

integration with accounts app for login/reg flows #819

Merged
merged 42 commits into from
Jun 1, 2016
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
585bcbe
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 19, 2016
03e1f84
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 21, 2016
adae1d1
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 21, 2016
9d6c15c
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 21, 2016
6e192cb
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 21, 2016
907c351
Merge branch 'dev' into feature/sso-accounts-app-integration
Apr 21, 2016
9886af0
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 21, 2016
60996bf
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 21, 2016
26f620f
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
3f70ce7
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
25c2714
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
a84ddb0
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
8be43e2
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
007cbcc
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
79970b8
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
d941da8
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
45312dd
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
344b5f8
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
29e3a27
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 22, 2016
6121e1b
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 25, 2016
9cc28ce
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 25, 2016
1e57be5
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 25, 2016
fa566bc
Merge branch 'dev' into feature/sso-accounts-app-integration
Apr 25, 2016
38d0e2c
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 25, 2016
f221d62
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 25, 2016
bbe1345
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 25, 2016
0489fa7
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 26, 2016
100c6a8
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 26, 2016
892017a
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 26, 2016
863b54a
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 28, 2016
6265f87
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 28, 2016
57036b0
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 28, 2016
22dde37
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 28, 2016
eafa13c
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 28, 2016
5ada072
AS#100297043256582, Move all login to link of Members to accounts.top…
Apr 28, 2016
9e26107
AS#100297043256582, Move all login to link of Members to accounts.top…
May 20, 2016
e8fd49d
AS#100297043256582, Move all login to link of Members to accounts.top…
May 20, 2016
bad9f2d
Merge branch 'dev' into feature/sso-accounts-app-integration
May 26, 2016
c3fbe77
Merge branch 'dev' into feature/sso-accounts-app-integration
May 26, 2016
d51e934
Merge branch 'dev' into feature/sso-accounts-app-integration
May 26, 2016
fb8e6e9
AS#100297043256582, Move all login to link of Members to accounts.top…
May 26, 2016
9fff590
AS#100297043256582, Move all login to link of Members to accounts.top…
Jun 1, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions app/account/account.routes.js
Original file line number Diff line number Diff line change
@@ -15,17 +15,19 @@ import angular from 'angular'
data: {
authRequired: false
},
onEnter: ['$state', '$stateParams', 'TcAuthService', 'logger', function($state, $stateParams, TcAuthService, logger) {
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')
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',
@@ -47,7 +49,8 @@ import angular from 'angular'
controller: 'FooterController as vm',
template: require('../layout/footer/account-footer')()
}
}
},
controller: 'LoginController'
},
'register': {
parent: 'auth',
133 changes: 20 additions & 113 deletions app/account/login/login.controller.js
Original file line number Diff line number Diff line change
@@ -1,131 +1,38 @@
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', '$location', '$scope', 'TcAuthService', 'UserService', 'Helpers', 'CONSTANTS']
LoginController.$inject = ['logger', '$state', '$stateParams', '$window', '$rootScope', 'Helpers', 'CONSTANTS']

function LoginController(logger, $state, $stateParams, $location, $scope, TcAuthService, UserService, Helpers, CONSTANTS) {
function LoginController(logger, $state, $stateParams, $window, $rootScope, Helpers, CONSTANTS) {
var vm = this
vm.$stateParams = $stateParams
vm.passwordReset = false
vm.loginErrors = {
USERNAME_NONEXISTANT: false,
WRONG_PASSWORD: false,
SOCIAL_LOGIN_ERROR: false
}

vm.login = login
vm.socialLogin = socialLogin

// reference for main vm
var mainVm = $scope.$parent.main

activate()

function activate() {}

function login() {
vm.loginErrors.USERNAME_NONEXISTANT = false
vm.loginErrors.WRONG_PASSWORD = false

// TODO ideally it should be done by dedicated directive to handle all outside clicks
mainVm.menuVisible = false

if (Helpers.isEmail(vm.username)) {
// the user is loggin in using email
vm.emailOrUsername = 'email'

// ensure email exists
// uses same validity check as registration
// valid => email isn't already used by someone
UserService.validateUserEmail(vm.username).then(function(data) {
if (data.valid) {
// email doesn't exist
vm.loginErrors.USERNAME_NONEXISTANT = true
} else {
_doLogin(vm.username, vm.currentPassword)
}
}).catch(function(resp) {
// TODO handle error
// assume email exists, login would in any case if it didn't
vm.loginErrors.USERNAME_NONEXISTANT = false
_doLogin(vm.username, vm.currentPassword)
})
} else {
// the user is logging in using a username
vm.emailOrUsername = 'username'

// username - make sure it exists
UserService.validateUserHandle(vm.username).then(function(data) {
if (data.valid) {
// username doesn't exist
vm.loginErrors.USERNAME_NONEXISTANT = true
} else {
_doLogin(vm.username, vm.currentPassword)
}
}).catch(function(resp) {
// TODO handle error
// assume email exists, login would in any case if it didn't
_doLogin(vm.username, vm.currentPassword)
})
}
}

function _doLogin(usernameOrEmail, password) {
return TcAuthService.login(usernameOrEmail, password)
.then(function(data) {
// setup login event for analytics tracking
Helpers.setupLoginEventMetrics(usernameOrEmail)
return Helpers.redirectPostLogin($stateParams.next)

})
.catch(function(err) {
logger.warning(err)

switch (err.status) {
case 'ACCOUNT_INACTIVE':
$state.go('registeredSuccessfully')
// user should already be redirected
break
case 'UNKNOWN_ERROR':
default:
vm.loginErrors.WRONG_PASSWORD = true
vm.password = ''
logger.error('Error logging in: ', err)
}
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)
})
}

function socialLogin(platform) {
// we need to pass on the 'next' param if we have one
var params = {}
if ($stateParams.next) {
params = {next: $stateParams.next}
}

// redirect back to login
var callbackUrl = $state.href('login', params, {absolute: true})

TcAuthService.socialLogin(platform, callbackUrl)
.then(function() {
logger.debug('logged in')
return Helpers.redirectPostLogin($stateParams.next)
})
.catch(function(err) {
/*eslint no-fallthrough:0*/
switch (err.status) {
case 'ACCOUNT_INACTIVE':
window.location.href = 'https://www.' + CONSTANTS.domain + '/account-inactive/'
case 'USER_NOT_REGISTERED':
default:
vm.socialLoginError = 401
vm.loginErrors.SOCIAL_LOGIN_ERROR = true
logger.error('Error logging in with social account', err)
}
})
}
}

47 changes: 0 additions & 47 deletions app/account/login/login.jade
Original file line number Diff line number Diff line change
@@ -1,47 +0,0 @@
- var logoMobile = require("../../../assets/images/logo_mobile.svg")

.login-container
header
a.logo-link(href="/", title="Back to the home page")
img(src=logoMobile, alt="Topcoder Logo")

h1 LOG IN TO TOPCODER

form(name="vm.loginForm", role="form", ng-submit="vm.loginForm.$valid && vm.login()", novalidate)
.form-errors(ng-messages="vm.loginErrors")
p.form-error(ng-message="USERNAME_NONEXISTANT") We couldn't find a member with that {{vm.emailOrUsername || "username"}}. Please check that you entered it correctly.

p.form-error(ng-message="WRONG_PASSWORD") That password is incorrect. Please check that you entered the right one.

p.form-error(ng-message="SOCIAL_LOGIN_ERROR") User with that profile is not registered.

div.validation-bar(ng-class="{'error-bar': vm.loginErrors.USERNAME_NONEXISTANT}")
input(ng-model="vm.username", name="username", placeholder="Username or Email", type="text", required)

toggle-password

p.problem-signin
a.forgot-password(ui-sref="resetPassword") Forgot your password?

button.tc-btn.tc-btn-wide(type="submit", ng-disabled="vm.loginForm.$invalid") Log In

section.login-options
p.tc-separator
span Or Log in With

ul.networks
li.network.github
a.ico(ng-click="vm.socialLogin('github')")
span Github
li.network.google-plus
a.ico(ng-click="vm.socialLogin('google-oauth2')")
span Google
li.network.facebook
a.ico(ng-click="vm.socialLogin('facebook')")
span Facebook
li.network.twitter
a.ico(ng-click="vm.socialLogin('twitter')")
span Twitter

p.join-topcoder Not a member yet?  
a(ui-sref="register(vm.$stateParams)") Join now
8 changes: 2 additions & 6 deletions app/account/logout/logout.controller.js
Original file line number Diff line number Diff line change
@@ -8,12 +8,8 @@ import angular from 'angular'
LogoutController.$inject = ['logger', 'TcAuthService', '$window', 'CONSTANTS']

function LogoutController(logger, TcAuthService, $window, CONSTANTS) {

TcAuthService.logout()
.then(function() {
logger.debug('Successfully logged out.')

// Redirect to home
TcAuthService.logout().then(() => {
logger.debug('MAIN_URL=> ' + CONSTANTS.MAIN_URL)
$window.location.href = CONSTANTS.MAIN_URL
})
}
1 change: 0 additions & 1 deletion app/layout/header/header.controller.js
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import _ from 'lodash'

vm.constants = CONSTANTS
vm.domain = CONSTANTS.domain
vm.login = TcAuthService.login
vm.checkSubmit = checkSubmit
vm.searchTerm = ''
vm.selectedGroup = selectedGroup
4 changes: 2 additions & 2 deletions app/services/api.service.js
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ import _ from 'lodash'

angular.module('tc.services').factory('ApiService', ApiService)

ApiService.$inject = ['$http', 'logger', 'AuthTokenService', 'Restangular', 'CONSTANTS']
ApiService.$inject = ['$http', 'logger', 'Restangular', 'CONSTANTS']

function ApiService($http, logger, AuthTokenService, Restangular, CONSTANTS) {
function ApiService($http, logger, Restangular, CONSTANTS) {
var service = {
requestHandler: requestHandler,
restangularV2: _getRestangularV2(),
52 changes: 0 additions & 52 deletions app/services/authToken.service.spec.js
Original file line number Diff line number Diff line change
@@ -40,16 +40,6 @@ describe('TcAuthToken Service', function() {

describe('AuthToken Service ', function() {

it('should call store to get v3 token', function() {
expect(service.getV3Token()).to.equal('value')
expect(store.get).to.be.have.been.calledWith('appiriojwt')
})

it('should call store to set v3 token', function() {
service.setV3Token('test')
expect(store.set).to.be.have.been.calledWith('appiriojwt', 'test')
})

it('should retrieve token from cookie', function() {
expect(service.getV2Token()).to.equal('value')
expect($cookies.get).to.be.have.been.calledWith('tcjwt')
@@ -62,11 +52,6 @@ describe('TcAuthToken Service', function() {
expect(store.remove).to.be.have.been.calledWith('appiriojwt')
})

it('should use jwtHelper to decode token', function() {
expect(service.decodeToken('test')).to.equal('decodedToken')
expect(jwtHelper.decodeToken).to.be.have.been.calledWith('test')
})

})

describe('Auth service ', function() {
@@ -107,42 +92,5 @@ describe('TcAuthToken Service', function() {
}
})
})

it('should make a POST request to /authorizations', function() {
service.getTokenFromAuth0Code('test')
$httpBackend.expectPOST(
apiUrl + '/authorizations', {}, {
'Content-Type': 'application/json',
'Authorization': 'Auth0Code test'
}
)
})

it('should make a POST request to exchange V2 token for V3 token', function() {
service.exchangeToken('refreshToken', 'idToken')
$httpBackend.expectPOST(
apiUrl + '/authorizations',
{
param: {
refreshToken: 'refreshToken',
externalToken: 'idToken'
}
},
{
withCredentials: true
}
)
})

it('should make a GET request to refresh V3 token', function() {
service.exchangeToken('refreshToken', 'idToken')
$httpBackend.expectGET(
apiUrl + '/authorizations/1',
{},
{
'Authorization': 'Bearer token'
}
)
})
})
})
Loading