I am in the process of implementing a login system using cookies to ensure that a user stays logged in even after leaving the application. While I have successfully set the cookie, I am unsure of how to utilize it to restrict access to the login screen for users who are already logged in.
I believe the most effective approach would be to handle this within the routes. Here is a snippet of my current file:
var routes = angular.module('we365', ['rcForm', 'ngCookie', 'ngCookies']);
routes.config(function ($routeProvider) {
$routeProvider
.when('/login', {
templateUrl: 'views/login.html',
controller: 'loginCtrl'
})
.when('/', {// get digest view
templateUrl: 'views/getDigest.html',
controller: 'GetDigestCtrl'
})
.when('/artifact/:artifact_id', {// single artifact view
templateUrl: 'views/artifact.html',
controller: 'artifactCtrl'
})
.otherwise({
redirectTo: '/'
});
});
Additionally, I am looking to remove the 'login' button from the parent view to prevent users from accessing it. Here is the current view structure:
<div class="container">
<div class="page-header col col-lg-12">
<h1>Welcome!</h1>
<a href="/#/login/" class="btn btn-sm btn-primary button-login">Login</a>
<a href="/#/" class="btn btn-sm btn-primary button-getDigest">Load Digest Data</a>
</div>
</div>