Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Χάρης Παπαδόπουλος
e-epal
Commits
1a3540d5
Commit
1a3540d5
authored
Jun 14, 2017
by
Χάρης Παπαδόπουλος
Browse files
Merge branch 'application_form' into 'develop'
created and applied new route guard for reports view See merge request !165
parents
c0296d05
a3ed18c2
Changes
4
Hide whitespace changes
Inline
Side-by-side
source/app.ts
View file @
1a3540d5
...
...
@@ -34,6 +34,7 @@ import SchoolAuthGuard from './guards/school.auth.guard';
import
SchoolStudentsLockedGuard
from
'
./guards/school.students.locked.guard
'
;
import
SchoolCapacityLockedGuard
from
'
./guards/school.capacity.locked.guard
'
;
import
StudentAuthGuard
from
'
./guards/student.auth.guard
'
;
import
ReportsAuthGuard
from
'
./guards/reports.auth.guard
'
;
import
StudentLockGuard
from
'
./guards/student.lock.guard
'
;
import
RegionEduAuthGuard
from
'
./guards/regionedu.auth.guard
'
;
import
EduAdminAuthGuard
from
'
./guards/eduadmin.auth.guard
'
;
...
...
@@ -94,7 +95,8 @@ class MyLocalization extends NgLocalization {
StudentLockGuard
,
RegionEduAuthGuard
,
EduAdminAuthGuard
,
MinistryAuthGuard
MinistryAuthGuard
,
ReportsAuthGuard
]
})
class
AppModule
{}
...
...
source/containers/main.routes.ts
View file @
1a3540d5
...
...
@@ -46,6 +46,7 @@ import RegionEduAuthGuard from '../guards/regionedu.auth.guard';
import
EduAdminAuthGuard
from
'
../guards/eduadmin.auth.guard
'
;
import
MinistryAuthGuard
from
'
../guards/ministry.auth.guard
'
;
import
ReportsAuthGuard
from
'
../guards/reports.auth.guard
'
;
import
Breadcrumbs
from
'
../components/main/breadcrumbs
'
;
export
const
MainRoutes
:
Routes
=
[
...
...
@@ -76,8 +77,8 @@ export const MainRoutes: Routes = [
{
path
:
'
school/director-buttons
'
,
component
:
DirectorButtons
,
canActivate
:
[
SchoolAuthGuard
]
},
{
path
:
'
school/director-classcapacity
'
,
component
:
DirectorClassCapacity
,
canActivate
:
[
SchoolAuthGuard
,
SchoolCapacityLockedGuard
]
},
{
path
:
'
ministry/minister-view
'
,
component
:
MinisterView
,
canActivate
:
[
MinistryAuthGuard
]
},
{
path
:
'
ministry/minister-reports
'
,
component
:
MinisterReports
},
{
path
:
'
ministry/report-all-stat/:reportId
'
,
component
:
ReportAllStat
},
{
path
:
'
ministry/minister-reports
'
,
component
:
MinisterReports
,
canActivate
:
[
ReportsAuthGuard
]
},
{
path
:
'
ministry/report-all-stat/:reportId
'
,
component
:
ReportAllStat
,
canActivate
:
[
ReportsAuthGuard
]
},
{
path
:
'
ministry/report-general/:reportId
'
,
component
:
ReportGeneral
,
canActivate
:
[
MinistryAuthGuard
]
},
{
path
:
'
ministry/report-users/:reportId
'
,
component
:
ReportUsers
,
canActivate
:
[
MinistryAuthGuard
]
},
{
path
:
'
ministry/report-no-capacity/:reportId
'
,
component
:
ReportNoCapacity
,
canActivate
:
[
MinistryAuthGuard
]
},
...
...
source/guards/reports.auth.guard.ts
0 → 100644
View file @
1a3540d5
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
CanActivate
}
from
'
@angular/router
'
;
import
{
AuthService
}
from
'
../services/auth.service
'
;
import
{
MINISTRY_ROLE
,
DIDE_ROLE
,
PDE_ROLE
}
from
'
../constants
'
;
import
{
Router
}
from
'
@angular/router
'
;
@
Injectable
()
export
default
class
ReportsAuthGuard
implements
CanActivate
{
constructor
(
private
authService
:
AuthService
,
private
router
:
Router
)
{}
canActivate
()
{
return
this
.
authService
.
isLoggedInForReports
(
DIDE_ROLE
,
PDE_ROLE
,
MINISTRY_ROLE
).
then
(
loggedIn
=>
{
if
(
!
loggedIn
)
{
this
.
router
.
navigate
([
'
/ministry/logout
'
]);
//this.router.navigate(['/ministy/minister-settings']);
}
return
loggedIn
;
}).
catch
(
err
=>
{
return
false
;
});
}
}
source/services/auth.service.ts
View file @
1a3540d5
...
...
@@ -44,6 +44,34 @@ export class AuthService {
});
}
isLoggedInForReports
(
role1
,
role2
,
role3
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
_ngRedux
.
select
(
state
=>
{
return
state
.
loginInfo
;
}).
subscribe
(
loginInfo
=>
{
if
(
loginInfo
.
size
>
0
)
{
loginInfo
.
reduce
(({},
loginInfoToken
)
=>
{
if
((
loginInfoToken
.
auth_token
&&
loginInfoToken
.
auth_token
.
length
>
0
&&
(
loginInfoToken
.
auth_role
===
role1
||
loginInfoToken
.
auth_role
===
role2
))
||
(
loginInfoToken
.
minedu_username
&&
loginInfoToken
.
minedu_username
.
length
>
0
&&
loginInfoToken
.
auth_role
===
MINISTRY_ROLE
&&
role3
===
MINISTRY_ROLE
)
)
{
resolve
(
true
);
}
else
{
resolve
(
false
);
}
return
loginInfoToken
;
},
{});
}
else
resolve
(
false
);
},
error
=>
{
console
.
log
(
"
Error Getting Auth Data
"
);
reject
(
"
Error Getting Auth Data
"
);
},
()
=>
console
.
log
(
"
Getting Auth Data
"
));
});
}
isApplicationLocked
(
role
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
_ngRedux
.
select
(
state
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment