-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
108 lines (83 loc) · 2.45 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// AngularJS App Initialization
var app = angular.module('nagariyaApp', ['ngRoute', 'firebase']);
// Firebase References
var database = firebase.database();
var databaseRef = database.ref();
// Routes
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$routeProvider.
when('/login', {
templateUrl: 'templates/login.html',
controller: 'LoginController'
}).
when('/home', {
templateUrl: 'templates/home.html',
controller: 'HomeController'
}).
when('/profile', {
templateUrl: 'templates/profile.html',
controller: 'ProfileController'
}).
when('/cleanmycity', {
templateUrl: 'templates/services/cleanmycity.html',
controller: 'CleanMyCityController'
}).
otherwise({
redirectTo: '/login'
});
}]);
// Controllers
// Login Controller
app.controller('LoginController', function($scope, $rootScope, $window) {
$scope.signInWithGoogle = function() {
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/plus.login');
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
$rootScope.loggedUser = user;
writeUserData(user.uid,
user.displayName,
user.email,
user.photoURL);
$window.location.assign('#/home');
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
alert(errorMessage);
});
};
});
// Home Controller
app.controller('HomeController', function($scope) {
$scope.loggedUser = firebase.auth().currentUser;
});
// Profile Controller
app.controller('ProfileController', function($scope) {
$scope.loggedUser = firebase.auth().currentUser;
});
// Clean My City Controller
app.controller('CleanMyCityController', function($scope) {
$scope.loggedUser = firebase.auth().currentUser;
$scope.openDialog = function() {
$('#spotfixmodal').modal('open');
};
});
// App Logic
$(".button-collapse").sideNav();
function writeUserData(userId, name, email, imageUrl) {
firebase.database().ref('users/' + userId).set({
display_name: name,
email: email,
profile_picture : imageUrl,
spot_fixes: 0,
complaints: 0,
points: 0
});
}
$('.modal-trigger').click(function(e){
console.log('asdasd');
});