title: In Angular js, how can I restrict a form submission (or function) to a logged in User only?
body: <p>I'm using AngularFire to create a simple Scrum app. Basically, the user can register, add some information, and a user is created in Firebase. I'm using ng-repeat to show all users on a team.html page.</p>
  
  <p>I currently have a function that allows users to click on a "user's tile", which uses ng-route to bring you to that specific user's 'dashboard.html'. My dashboard.html has a few ng-change directives that update the user's 'color' and 'projectDescription' properties - these are tied into the 'DashboardController'. </p>
  
  <p>I want to be able to restrict the updating of a user's status if the 'currentUuser' is not the same as the dashboard.html user. Can someone please give me a hint?</p>
  
  <p>app.js</p>
  
  <pre><code>var myApp = angular.module('myApp', 
  ['ngRoute', 'firebase', 'appControllers'])
  .constant('FIREBASE_URL', 'https://scrumcheck.firebaseio.com/');
  
  // Dependencies
  var appControllers = angular.module('appControllers',['firebase']);
  
  myApp.config(['$routeProvider', function($routeProvider){
  $routeProvider.
      when('/login', {
          templateUrl: 'views/login.html',
          controller: 'RegistrationController'
      }).
      when('/team', {
          templateUrl: 'views/team.html',
          controller: 'MembersController'
      }).
      when('/views/dashboard/:uId/:mId', {
          templateUrl: 'views/dashboard.html',
          controller: 'DashboardController'
      }).
      when('/register', {
          templateUrl: 'views/register.html',
          controller: 'RegistrationController'
      }).
      otherwise({
          redirectTo: '/login'
      });
  }]);
  </code></pre>
  
  <p>authentication.js (factory)</p>
  
  <pre><code>myApp.factory('Authentication', function($firebase, 
    $firebaseSimpleLogin, FIREBASE_URL, $rootScope, $location) {
  
    var ref = new Firebase(FIREBASE_URL);
    var simpleLogin = $firebaseSimpleLogin(ref);
  
    var myObject = {
  
      login : function(user) {
  
        var userRef = new Firebase(FIREBASE_URL + '/users/' + user.uid);
        var userObj = $firebase(userRef).$asObject();
  
        userObj.$loaded().then(function() {
          $rootScope.currentUser = userObj;
        });
  
        return simpleLogin.$login('password', {
          email: user.email,
          password: user.password
        });
      }, //login
  
      register : function(user) {
        return simpleLogin.$createUser(user.email, user.password)
        .then(function(regUser){
          var ref = new Firebase(FIREBASE_URL + 'users');
          var firebaseUsers = $firebase(ref);
  
          var userInfo = {
            date: Firebase.ServerValue.TIMESTAMP,
            regUser: regUser.uid,
            firstname: user.firstname,
            email: user.email,
                image : "http://telehealth.org/wp-content/images/user-placeholder.jpg",
                color : "plain",
                projectDescription : "Currently working on...",
                yahoo : "yahooIM",
                upcoming : "PTO / WFH / OOO"
          }
  
          firebaseUsers.$set(regUser.uid, userInfo);
        }); //add user
      }, //register
  
      logout : function() {
        return simpleLogin.$logout();
      }, //logout
  
      signedIn: function() {
        return simpleLogin.user != null;
      }
  
      } //myObject
  
    //add the function to the rootScope
  
    $rootScope.signedIn = function() {
      return myObject.signedIn();
    }
  
    return myObject;
  });
  </code></pre>
  
  <p>dashboard.html</p>
  
  <pre><code>    &lt;div class="edit" id="frame-{{member.color}}"&gt;
          &lt;div id="title-{{member.color}}" class="dashTitle"&gt;
          &lt;/div&gt;
              &lt;p class="userInfo"&gt;{{member.email}} | {{member.yahoo}}&lt;/p&gt;
          &lt;div class="dashimage"&gt;
              &lt;img ng-src="{{member.image}}" id="frame-{{member.color}}"&gt;
          &lt;/div&gt;
  
          &lt;form name="dashColorForm"
              id="dashColorForm"
              novalidate&gt;
              &lt;div class="radio-toolbar"&gt;
                  &lt;input 
                      type="radio" 
                      id="radio1" 
                      name="radios" 
                      ng-model="color" 
                      ng-change="colorChange(color)"
                      value="green"&gt;
                &lt;label for="radio1" id="greenRadio"&gt;&lt;/label&gt;
  
                &lt;input 
                  type="radio" 
                  id="radio2" 
                  name="radios" 
                  ng-model="color" 
                  ng-change="colorChange(color)"
                  value="grellow"&gt;
                &lt;label for="radio2" id="grellowRadio"&gt;&lt;/label&gt;
  
                &lt;input 
                  type="radio" 
                  id="radio3" 
                  name="radios" 
                  ng-model="color" 
                  ng-change="colorChange(color)"
                  value="yellow"&gt;
                &lt;label for="radio3" id="yellowRadio"&gt;&lt;/label&gt;
  
                &lt;input 
                  type="radio" 
                  id="radio4" 
                  name="radios" 
                  ng-model="color" 
                  ng-change="colorChange(color)"
                  value="orange"&gt;
                &lt;label for="radio4" id="orangeRadio"&gt;&lt;/label&gt;
  
                &lt;input 
                  type="radio" 
                  id="radio5" 
                  name="radios" 
                  ng-model="color" 
                  ng-change="colorChange(color)"
                  value="red"&gt;
                &lt;label for="radio5" id="redRadio"&gt;&lt;/label&gt;
  
                &lt;input 
                  type="radio" 
                  id="radio6" 
                  name="radios" 
                  ng-model="color" 
                  ng-change="colorChange(color)"
                  value="darkred"&gt;
                &lt;label for="radio6" id="darkredRadio"&gt;&lt;/label&gt;
  
                &lt;input 
                  type="radio" 
                  id="radio7" 
                  name="radios" 
                  ng-model="color" 
                  ng-change="colorChange(color)"
                  value="unavailable"&gt;
                &lt;label for="radio7" id="unavailableRadio"&gt;&lt;/label&gt;
  
              &lt;/div&gt;
          &lt;/form&gt;
  
          &lt;form name="dashProjectForm"
              id="projectForm"
              novalidate&gt;
              &lt;div class="dashprojects"&gt;
                  &lt;textarea 
                      name="projectDescription" 
                      id="memberproject" 
                      ng-model="projectDescription"
                      ng-change="dashProjectUpdate(projectDescription)"
                      placeholder="{{member.projectDescription}}"&gt;{{member.projectDescription}}
                  &lt;/textarea&gt;
              &lt;/div&gt;
          &lt;/form&gt;
          &lt;p&gt;&lt;a class="btn dashsubmit" ng-href="#/team"&gt;Go Back&lt;/a&gt;&lt;/p&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>dashboard.js</p>
  
  <pre><code>    myApp.controller('DashboardController', 
          function($scope, $firebase, $routeParams, $location, FIREBASE_URL){
  
          var whichMember = $routeParams.uId;
          var ref = new Firebase(FIREBASE_URL + 'users/'  + whichMember);
          var member = $firebase(ref);
  
          $scope.member = member.$asObject();
  
          $scope.colorChange = function() {
              var updateObj = $firebase(ref);
  
              var updateColor = {
                  date: Firebase.ServerValue.TIMESTAMP,
            color : $scope.color
          };
  
              updateObj.$update(updateColor);
          }
  
          $scope.dashProjectUpdate = function() {
              var updateObj = $firebase(ref);
  
              var updateProject = {
                  date: Firebase.ServerValue.TIMESTAMP,
            projectDescription : $scope.projectDescription
              };
  
              updateObj.$update(updateProject);
          }
  
      });
  </code></pre>
  
  <p>members.json</p>
  
  <pre><code>{
    "users" : {
      "simplelogin:1" : {
        "date" : 1410328158691,
        "firstname" : "Adam",
        "image" : "http://www.charitydynamics.com/wp-content/uploads/2012/09/AdamKaye-Team.jpg",
        "color" : "red",
        "projectDescription" : "Currently working on...",
        "email": "test@email.com",
        "yahoo" : "yahooIM",
        "upcoming" : "PTO / WFH / OOO"
      }
  </code></pre>