Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- angular.module('sch.home', ['ngRoute' ,'firebase'])
- .config(['$routeProvider', function($routeProvider){
- $routeProvider.when('/home',
- {
- templateUrl: 'home/home.html',
- controller: 'HomeCtrl'
- });
- }])
- .controller('HomeCtrl', ['$scope', '$firebaseAuth', '$firebaseArray', '$location', 'CommonProp', function($scope, $firebaseAuth, $firebaseArray, $location, CommonProp){
- $scope.username = CommonProp.getUser();
- if($scope.username){
- $location.path('/landing');
- }
- $scope.signIn = function(){
- var username = $scope.user.email;
- var password = $scope.user.password;
- var auth = $firebaseAuth();
- auth.$signInWithEmailAndPassword(username, password).then(function(){
- console.log("matapancing");
- CommonProp.setUser($scope.user.email);
- $location.path('/landing');
- }).catch(function(error){
- console.log(error);
- });
- }
- var ref = firebase.database().ref().child('Scholarship');
- $scope.scholarship = $firebaseArray(ref);
- }])
- .service('CommonProp', ['$location', '$firebaseAuth', function($location, $firebaseAuth){
- var user="";
- var auth = $firebaseAuth();
- return{
- getUser: function(){
- if(user == ""){
- user = localStorage.getItem("userEmail");
- }
- return user;
- },
- setUser: function(value){
- localStorage.setItem("userEmail", value);
- user = value;
- },
- logoutUser: function(){
- auth.$signOut();
- console.log("Logged Out Succesfully");
- user = "";
- localStorage.removeItem('userEmail');
- $location.path('/home');
- }
- }
- }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement