Open FerdinaKusumah opened 6 years ago
app.controller('LoginController', ['$scope', 'USER_ROLES', '$state', 'PermPermissionStore', 'PermRoleStore', function ($scope, USER_ROLES, $state, PermPermissionStore, PermRoleStore) {
/** * @argument {Clean session user} */ PermPermissionStore.clearStore(); PermRoleStore.clearStore(); const admin_permissions = ['canCreate', 'canRead', 'canUpdate', 'canDelete']; const user_permissions = ['canRead']; PermRoleStore.defineRole('ADMIN', ['canCreate', 'canRead', 'canUpdate', 'canDelete']); PermRoleStore.defineRole('USER', ['canRead']); $scope.login = {}; const verifyUser = async function (object) { username = object.username; password = object.password; const status = {}; if ((username == 'admin') && (password == 'admin')) { status.valid = true; status.permissions = admin_permissions; status.username = 'ADMIN'; } else if ((username == 'user') && (password == 'user')) { status.valid = true; status.permissions = user_permissions; status.username = 'USER'; } else status.valid = false; return status; }; $scope.login = async function () { let user = $scope.login; user_status = await verifyUser(user); if (user_status.valid) { PermRoleStore.defineRole(user_status.username, [user_status.permissions]); $state.go('home'); } else { $scope.error = true; setTimeout(() => { $scope.error = false; }, 2000); } };
}]); this is my login controller,
app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function ($stateProvider, $urlRouterProvider, $locationProvider) {
$locationProvider.hashPrefix(''); $urlRouterProvider.otherwise("/login"); $stateProvider .state('login', { url: '/login', controller: 'LoginController', templateUrl: 'template/login/login.inc.html' }) .state('home', { url: '/home', controller: 'homeController', templateUrl: 'template/home/home.inc.html', data: { permissions: { only: ['ADMIN','USER'], redirectTo: 'unauthorized' } } }) .state('user', { url: '/user', controller: 'UserController', templateUrl: 'template/user/user.inc.html', data: { permissions: { only: ['USER'], redirectTo: 'unauthorized' } } }) .state('unauthorized', { url: '/unauthorized', templateUrl: 'template/error/403.inc.html' }) ;
}]);
this is my route controller,
this is my view.
thank youu
app.controller('LoginController', ['$scope', 'USER_ROLES', '$state', 'PermPermissionStore', 'PermRoleStore', function ($scope, USER_ROLES, $state, PermPermissionStore, PermRoleStore) {
}]); this is my login controller,
app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function ($stateProvider, $urlRouterProvider, $locationProvider) {
}]);
this is my route controller,
Admin page
this is my view.
thank youu