SHARE
TWEET

Untitled

a guest Dec 6th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.    
  3. angular.module('sch.home', ['ngRoute' ,'firebase'])
  4.  
  5. .config(['$routeProvider', function($routeProvider){
  6.     $routeProvider.when('/home',
  7.     {
  8.         templateUrl: 'home/home.html',
  9.         controller: 'HomeCtrl'
  10.     });
  11. }])
  12.    
  13. .controller('HomeCtrl', ['$scope', '$firebaseAuth', '$firebaseArray', '$location', 'CommonProp', function($scope, $firebaseAuth, $firebaseArray, $location, CommonProp){
  14.  
  15. $scope.username = CommonProp.getUser();
  16.  
  17. if($scope.username){
  18.     $location.path('/landing');
  19. }
  20.  
  21. $scope.signIn = function(){
  22.     var username = $scope.user.email;
  23.     var password = $scope.user.password;
  24.     var auth = $firebaseAuth();
  25.  
  26.     auth.$signInWithEmailAndPassword(username, password).then(function(){
  27.         console.log("matapancing");
  28.         CommonProp.setUser($scope.user.email);
  29.         $location.path('/landing');
  30.     }).catch(function(error){
  31.         console.log(error);
  32.     });
  33. }
  34.  
  35. var ref = firebase.database().ref().child('Scholarship');
  36. $scope.scholarship = $firebaseArray(ref);
  37.  
  38. }])
  39.    
  40. .service('CommonProp', ['$location', '$firebaseAuth', function($location, $firebaseAuth){
  41.     var user="";
  42.     var auth = $firebaseAuth();
  43.  
  44.     return{
  45.         getUser: function(){
  46.             if(user == ""){
  47.                 user = localStorage.getItem("userEmail");
  48.             }
  49.             return user;
  50.         },
  51.         setUser: function(value){
  52.             localStorage.setItem("userEmail", value);
  53.             user = value;
  54.         },
  55.         logoutUser: function(){
  56.             auth.$signOut();
  57.             console.log("Logged Out Succesfully");
  58.             user = "";
  59.             localStorage.removeItem('userEmail');
  60.             $location.path('/home');
  61.         }
  62.  
  63.     }
  64. }])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top