Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scope.submit = function () {
- $scope.errorMessagePassword = false;
- $scope.errorMessageUsername = false;
- //so rootscope users for a match, else, show error message where the match fails
- $http.get('/chatdatabase').then(function(response){
- for ( var i = 0; i < response.data.length; i++ ) {
- if ( $scope.users.username === response.data[i].username ) {
- if ( $scope.users.password === response.data[i].password ) {
- // The password is correct
- $localStorage.loggedInUserId = response.data.userId;
- //Another alternative is
- $localStorage.loggedInUser = response.data;
- $location.path('/chat/public');
- $scope.errorMessageUsername = false;
- loggedInUser.id = response.data[i]._id;
- loggedInUser.username = response.data[i].username;
- loggedInUser.avatar = response.data[i].avatar.src;
- return loggedInUser;
- } else {
- $scope.errorMessageUsername = false;
- $scope.errorMessagePassword = true;
- break;
- }
- } else {
- $scope.errorMessageUsername = true;
- }
- }
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement