Skip to content

Instantly share code, notes, and snippets.

@uncletammy
Created October 24, 2014 21:13
Show Gist options
  • Save uncletammy/627c834195dc5b0ad9eb to your computer and use it in GitHub Desktop.
Save uncletammy/627c834195dc5b0ad9eb to your computer and use it in GitHub Desktop.
Mike!
// Set hrvst module
var hrvst = angular.module('hrvst');
// Configure UI Router
hrvst.config([
'$stateProvider',
'$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {
$stateProvider
/******************************
* States
*******************************/
/**
* Brochure
*/
.state('brochure', {
templateUrl: 'templates/brochure/brochure.html',
controller: 'BrochureCtrl',
abstract: true
})
.state('brochure.home', {
url: '/',
templateUrl: 'templates/brochure/brochure.home.html',
controller: 'BrochureCtrl'
})
.state('brochure.newInvestor', {
url: '/new-investor',
templateUrl: 'templates/brochure/new-investor.html',
controller: 'BrochureCtrl'
})
.state('brochure.resetPassword', {
url: '/reset',
templateUrl: 'templates/account/reset-password.html',
controller: 'ResetPasswordCtrl'
})
.state('brochure.logout', {
url: '/logout',
templateUrl: 'templates/account/logout.html',
controller: 'LogoutCtrl'
})
.state('brochure.activate', {
url: '/activate',
templateUrl: 'templates/account/activate.html',
controller: 'ActivateCtrl'
})
.state('brochure.profile', {
url: '/profile',
templateUrl: 'templates/account/profile.html',
controller: 'ProfileCtrl'
})
.state('brochure.login', {
url: '/login',
templateUrl: 'templates/account/login.html',
controller: 'LoginCtrl'
})
.state('brochure.socialLogin', {
url: '/login',
templateUrl: 'templates/account/login.html',
controller: 'LoginCtrl'
})
/**
* Signup
*/
.state('brochure.signup', {
url: '/signup',
templateUrl: 'templates/account/signup.html',
controller: 'SignupCtrl'
})
.state('brochure.socialSignup', {
url: '/signup/:integrationType',
templateUrl: 'templates/account/signup.html',
controller: 'SignupCtrl'
})
/**
* Account Setup
*/
.state('setup', {
templateUrl: 'templates/setup/setup.html',
controller: 'SetupCtrl',
abstract: true
})
.state('setup.profile', {
url: '/setup/profile',
templateUrl: 'templates/setup/setup.profile.html',
controller: 'SetupCtrl'
})
.state('setup.accounts', {
url: '/setup/accounts',
templateUrl: 'templates/setup/setup.accounts.html',
controller: 'SetupAccountsCtrl'
})
/**
* Dashboard
*/
.state('dashboard', {
url: '/dashboard',
templateUrl: 'templates/dashboard/dashboard.html',
controller: 'DashCtrl'
})
.state('dashboardDemo', {
url: '/dashboard-demo',
templateUrl: 'templates/dashboard/dashboard-demo.html',
controller: 'DashCtrl'
})
/******************************
* Standard url routing
*******************************/
$urlRouterProvider
.otherwise('/');
}
]);
angular.module('hrvst').controller('LoginCtrl', [
'$stateParams',
'$rootScope',
'$scope',
'$state',
'Harvest',
// UI state objects
'uiMe',
'uiErrorBus',
function($stateParams,$rootScope, $scope, $state, Harvest, uiMe, uiErrorBus) {
// If a user is already saved on the scope, then you
// are already logged in and can be redirected to the
// dashboard.
if ($stateParams.integrationType){
}
if ($rootScope.app.user) {
if ($rootScope.app.user.birthdate){
$state.go('dashboard');
} else {
$state.go('setup.profile');
}
} else {
Harvest.getProfile()
.then(function areWeLoggedIn(user){
$rootScope.app.user = user;
})
.catch(function(err){
})
.finally(function(){
if ($rootScope.app.user) {
if ($rootScope.app.user.birthdate){
$state.go('dashboard');
} else {
$state.go('setup.profile');
}
} else {
}
});
}
$scope.login = function() {
// Show loading state
$scope.syncing.login = true;
Harvest.login($scope.user.email, $scope.user.password)
.then(function loginSuccessful(data) {
uiMe.fetch()
.then(function (){
$rootScope.app.user = uiMe;
$state.go('setup.profile');
})
.catch(function (err) {
uiErrorBus.$handleError(err);
})
.finally(function (){
$scope.syncing.login = false;
});
})
.catch(function loginFailed(err) {
$scope.statusMessage = err.message;
$scope.syncing.login = false;
});
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment