Ionic app restrict user from moving back once logging into the app until user do logout

Hi i have developed one ionic application from Cordova and AngularJS. The issue I'm facing here is when the user open the app and do the Login, user navigates to the dashboard. Here once user navigate, until user clicks on Logout option or it clears the cache, he/she should not go back to Login page.

But in my case, when user logs in and click on device's back button it is again going back to Login page where user has to do the Login again. How to avoid it?

I want to maintain the users logged in state even after the app goes to background.

How to achieve this?

Update

I have tried this piece of code:

    controller('Dashboard', function ($scope, $http, $ionicPopup, $timeout, $state, $rootScope, $interval, $sce, $ionicPlatform) {
        $ionicPlatform.onHardwareBackButton(function () {
        if (true) { // your check here
            $ionicPopup.confirm({
                title: 'Exit from App!',
                template: 'are you sure you want to exit?'
            }).then(function (res) {
                if (res) {
                    navigator.app.exitApp();
                }
            })
        }
    });

It is executing well but the problem is it execute on every back button i press. SO if user navigates inside the dashboard to the menus and when click on back button (by Nature) to coma back to previous page which is not a dashboard page, at that moment even it is getting called. That is so embarrassing with respect to user experience. I have added this piece of code in in the dashboard controller and nowhere else? What i have to do to call this event only in the dashboard controller or is it possible to do so.

But in my case, when user logs in and click on device's back button it is again going back to Login page where user has to do the Login again. How to avoid it?

I think you should listen to the backbutton event as described in the Cordova docs. In this listener add some code to avoid going back to login page.

I want to maintain the users logged in state even after the app goes to background.

How to achieve this?

You should add some kind of caching to your application, add save the $ionicHistory to it and retrieve / reset it first thing when app loads, like in config time.