Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application refactor #8

Merged
merged 3 commits into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 8 additions & 5 deletions observatorio-app/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/Login/loginFactory.js"></script>
<script src="js/states.js"></script>
<script src="js/factories.js"></script>
<script src="js/signIn/signInCtrl.js"></script>
<script src="js/signIn/socialService.js"></script>
<script src="js/signUp/signUpCtrl.js"></script>
<script src="js/signUp/passwordDirective.js"></script>
<script src="lib/angular-resource/angular-resource.js"></script>

<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>

<script src="lib/firebase/firebase.js"></script>
<script src="lib/firebase/angularfire.min.js"></script>
</head>

<body ng-app="starter" animation="slide-left-right-ios7">
Expand Down
43 changes: 1 addition & 42 deletions observatorio-app/www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,13 @@ angular.module('starter', ['ionic', 'ngResource','app.controllers'])
.constant('URL', 'http://localhost:3000')
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs).
// The reason we default this to hidden is that native apps don't usually show an accessory bar, at
// least on iOS. It's a dead giveaway that an app is using a Web View. However, it's sometimes
// useful especially with forms, though we would prefer giving the user a little more room
// to interact with the app.

if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// Set the statusbar to use the default style, tweak this to
// remove the status bar on iOS or change it to use white instead of dark colors.
StatusBar.styleDefault();
}
})
})

.config(function($stateProvider, $urlRouterProvider){
$stateProvider

.state('menu.home', {
url: '/home',
views: {
'side-menu': {
templateUrl: 'templates/home.html'
}
}
})

.state('menu', {
url: '/side-menu',
templateUrl: 'templates/menu.html'
})

.state('signin', {
url: '/signin',
templateUrl: 'templates/signin.html',
controller: 'signinCtrl'
})

.state('signup', {
url: '/signup',
templateUrl: 'templates/signup.html',
controller: 'signupCtrl'
})

$urlRouterProvider.otherwise('/signin')

//$urlRouterProvider.otherwise("app/home");
})
111 changes: 0 additions & 111 deletions observatorio-app/www/js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,112 +1 @@
angular.module('app.controllers', [])

.service('socialService',function(){
var userData = "";
var setUserData = function(paramUserData){
userData = paramUserData
}
var getUserData = function(){
console.log(userData)
return userData
}
return {
setUserData: setUserData,
getUserData: getUserData
}
})

.controller('signinCtrl', function ($scope, $stateParams, $state, socialService, factoryEmail, factoryLogin, $ionicLoading, $timeout) {
$scope.loginAttempt = function(user){
console.log(user);
factoryLogin.save(user, function(result){
console.log(result);
$state.go("menu.home")
$scope.loginError = false;
}, function(error){
console.log("ERRO!")
$scope.loginError = true;
})
}

$scope.registerSocial = function(socialNetwork){
var ref = new Firebase("dojogrupo04.firebaseio.com");
ref.authWithOAuthPopup(socialNetwork, function(error, authData){
if(error){
console.log("Failed ", error)
}
else{
console.log(authData)
$scope.user = authData;
factoryEmail.save({"email": ((socialNetwork=='facebook')?authData.facebook.email:authData.google.email)}, function(result) {
if(result.userExist){
$state.go('menu.home')
}else{
if(socialNetwork=='facebook'){
$scope.user.first_name = authData.facebook.cachedUserProfile.first_name;
$scope.user.last_name = authData.facebook.cachedUserProfile.last_name;
$scope.user.gender = authData.facebook.cachedUserProfile.gender;
$scope.user.profile_type = "cidadao";
$scope.user.email = authData.facebook.email;
}else{
$scope.user.first_name = authData.google.cachedUserProfile.given_name;
console.log("nome:"+ $scope.user.first_name)
$scope.user.last_name = authData.google.cachedUserProfile.family_name;
console.log("lastNome:"+ $scope.user.last_name)
$scope.user.gender = authData.google.cachedUserProfile.gender;
$scope.user.profile_type = "cidadao";
$scope.user.email = authData.google.email;
}
socialService.setUserData($scope.user)
$state.go('signup')
}
}, function(error){
console.log(error)
})
$ionicLoading.show({
template: 'Recebendo suas informações... <ion-spinner icon="android"></ion-spinner>'
});
$timeout(function(){
$ionicLoading.hide();
},10000);
}
},{
scope: "email"
})
}
})

.controller('signupCtrl', function ($scope, factoryRegister,socialService, $state) {

$scope.user = socialService.getUserData()
$scope.registerEmail= function(user){
console.log(user);
factoryRegister.save(user, function(result){
console.log(result);
$scope.invalidEmail = false;
$state.go("menu.home")
}, function(error){
$scope.invalidEmail = true;
})
}
})

.directive('confirmPwd', function($interpolate, $parse) {
return {
require: 'ngModel',
link: function(scope, elem, attr, ngModelCtrl) {

var pwdToMatch = $parse(attr.confirmPwd);
var pwdFn = $interpolate(attr.confirmPwd)(scope);

scope.$watch(pwdFn, function(newVal) {
ngModelCtrl.$setValidity('password', ngModelCtrl.$viewValue == newVal);
})

ngModelCtrl.$validators.password = function(modelValue, viewValue) {
var value = modelValue || viewValue;
return value == pwdToMatch(scope);
};

}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ angular.module('starter')
.factory('factoryRegister', function($resource,URL) {
return $resource(URL+"/users/create")
})

.factory('factoryLogin', function($resource, URL){
return $resource(URL+"/sessions/login")
})

.factory('factoryEmail', function($resource, URL){
return $resource(URL+"/users/verify_email")
});
61 changes: 61 additions & 0 deletions observatorio-app/www/js/signIn/signInCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
angular.module('app.controllers')

.controller('signinCtrl', function ($scope, $stateParams, $state, socialService, factoryEmail, factoryLogin, $ionicLoading, $timeout) {
$scope.loginAttempt = function(user){
console.log(user);
factoryLogin.save(user, function(result){
console.log(result);
$state.go("menu.home")
$scope.loginError = false;
}, function(error){
console.log("ERRO!")
$scope.loginError = true;
})
}

$scope.registerSocial = function(socialNetwork){
var ref = new Firebase("dojogrupo04.firebaseio.com");
ref.authWithOAuthPopup(socialNetwork, function(error, authData){
if(error){
console.log("Failed ", error)
}
else{
console.log(authData)
$scope.user = authData;
factoryEmail.save({"email": ((socialNetwork=='facebook')?authData.facebook.email:authData.google.email)}, function(result) {
if(result.userExist){
$state.go('menu.home')
}else{
if(socialNetwork=='facebook'){
$scope.user.first_name = authData.facebook.cachedUserProfile.first_name;
$scope.user.last_name = authData.facebook.cachedUserProfile.last_name;
$scope.user.gender = authData.facebook.cachedUserProfile.gender;
$scope.user.profile_type = "cidadao";
$scope.user.email = authData.facebook.email;
}else{
$scope.user.first_name = authData.google.cachedUserProfile.given_name;
console.log("nome:"+ $scope.user.first_name)
$scope.user.last_name = authData.google.cachedUserProfile.family_name;
console.log("lastNome:"+ $scope.user.last_name)
$scope.user.gender = authData.google.cachedUserProfile.gender;
$scope.user.profile_type = "cidadao";
$scope.user.email = authData.google.email;
}
socialService.setUserData($scope.user)
$state.go('signup')
}
}, function(error){
console.log(error)
})
$ionicLoading.show({
template: 'Recebendo suas informações... <ion-spinner icon="android"></ion-spinner>'
});
$timeout(function(){
$ionicLoading.hide();
},10000);
}
},{
scope: "email"
})
}
})
16 changes: 16 additions & 0 deletions observatorio-app/www/js/signIn/socialService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
angular.module('starter')

.service('socialService',function(){
var userData = "";
var setUserData = function(paramUserData){
userData = paramUserData
}
var getUserData = function(){
console.log(userData)
return userData
}
return {
setUserData: setUserData,
getUserData: getUserData
}
})
22 changes: 22 additions & 0 deletions observatorio-app/www/js/signUp/passwordDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
angular.module('starter')

.directive('confirmPwd', function($interpolate, $parse) {
return {
require: 'ngModel',
link: function(scope, elem, attr, ngModelCtrl) {

var pwdToMatch = $parse(attr.confirmPwd);
var pwdFn = $interpolate(attr.confirmPwd)(scope);

scope.$watch(pwdFn, function(newVal) {
ngModelCtrl.$setValidity('password', ngModelCtrl.$viewValue == newVal);
})

ngModelCtrl.$validators.password = function(modelValue, viewValue) {
var value = modelValue || viewValue;
return value == pwdToMatch(scope);
};

}
}
});
16 changes: 16 additions & 0 deletions observatorio-app/www/js/signUp/signUpCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
angular.module('app.controllers')

.controller('signupCtrl', function ($scope, factoryRegister,socialService, $state) {

$scope.user = socialService.getUserData()
$scope.registerEmail= function(user){
console.log(user);
factoryRegister.save(user, function(result){
console.log(result);
$scope.invalidEmail = false;
$state.go("menu.home")
}, function(error){
$scope.invalidEmail = true;
})
}
})
35 changes: 35 additions & 0 deletions observatorio-app/www/js/states.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
angular.module('starter')

.config(function($stateProvider, $urlRouterProvider){
$stateProvider

.state('menu.home', {
url: '/home',
views: {
'side-menu': {
templateUrl: 'templates/home.html'
}
}
})

.state('menu', {
url: '/side-menu',
templateUrl: 'templates/menu.html'
})

.state('signin', {
url: '/signin',
templateUrl: 'templates/signin.html',
controller: 'signinCtrl'
})

.state('signup', {
url: '/signup',
templateUrl: 'templates/signup.html',
controller: 'signupCtrl'
})

$urlRouterProvider.otherwise('/signin')

//$urlRouterProvider.otherwise("app/home");
})
Loading