Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. $scope.submit = function () {
  2. $scope.errorMessagePassword = false;
  3. $scope.errorMessageUsername = false;
  4. //so rootscope users for a match, else, show error message where the match fails
  5. $http.get('/chatdatabase').then(function(response){
  6. for ( var i = 0; i < response.data.length; i++ ) {
  7. if ( $scope.users.username === response.data[i].username ) {
  8. if ( $scope.users.password === response.data[i].password ) {
  9.  
  10. // The password is correct
  11. $localStorage.loggedInUserId = response.data.userId;
  12.  
  13. //Another alternative is
  14. $localStorage.loggedInUser = response.data;
  15.  
  16. $location.path('/chat/public');
  17. $scope.errorMessageUsername = false;
  18. loggedInUser.id = response.data[i]._id;
  19. loggedInUser.username = response.data[i].username;
  20. loggedInUser.avatar = response.data[i].avatar.src;
  21.  
  22. return loggedInUser;
  23. } else {
  24. $scope.errorMessageUsername = false;
  25. $scope.errorMessagePassword = true;
  26. break;
  27. }
  28. } else {
  29. $scope.errorMessageUsername = true;
  30. }
  31. }
  32. });
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement