app.get('/auth/account', ensureLoggedIn('/profile'), function(req, res, next) {
// check if the user has a complete profile
if(req.user != undefined && (req.user.mobile == undefined || req.user.mobile === "" || req.user.mobile == null)){
// redirect them to the complete profile interface and pass the access token and user id
res.redirect('/profile/#/register/fbcomplete/?access_token='+req.accessToken.id+"&user_id="+req.accessToken.userId);
}else{
// redirect them to the profile dashboard and pass the access token and user id
res.redirect('/profile/?access_token='+req.accessToken.id+"&user_id="+req.accessToken.userId);
}
});var socialLoginWindow = window.open('http://xxxxxxxxx/auth/facebook', "_blank", 'location=no,toolbar=yes');// listen to page load eventssocialLoginWindow.addEventListener('loadstart', function (event) { var url = event.url; var general_fail_url = "http://xxxxxxxxx/profile"; var profile_url = "http://xxxxxxxxx/profile/?access_token="; var complete_registration_url = "http://xxxxxxxxx/profile/#/register/fbcomplete"; var facebook_fail_url = "http://xxxxxxxxx/profile/#/login/?error=fblogin"; if (url.substring(0, complete_registration_url.length) == complete_registration_url) { // .... get params from event.url ... // socialLoginWindow.close(); // user has registered but needs to finish their profile if (params.access_token && params.user_id) { AppAuth.setTokenAndID(params.access_token, params.user_id.replace("#_", "")); $state.go('register-user', {step: 1}); } } else if (url.substring(0, facebook_fail_url.length) == facebook_fail_url) { socialLoginWindow.close(); $ionicPopup.alert({ title: 'Sorry!', template: 'Login failed, please try again' }); } else if (url.substring(0, profile_url.length) == profile_url) { // .... get params from event.url ... // socialLoginWindow.close(); // user has registered successfully... get the user profile if (params.access_token && params.user_id) { AppAuth.setTokenAndID(params.access_token, params.user_id.replace("#_", "")); AppAuth.ensureHasCurrentUser(function (UserObj) { if (!UserObj || UserObj.firstName === undefined) { $ionicPopup.alert({ title: 'Sorry!', template: 'Login failed, please try again' }); } else { $state.go('app.dashboard'); } }); } else { $ionicPopup.alert({ title: 'Sorry!', template: 'Login failed, please try again' }); } } else if (url.substring(0, general_fail_url.length) == general_fail_url) { $ionicPopup.alert({ title: 'Sorry!', template: 'Login failed, please try again' }); }
});