new route auth
parent
1e92388cdc
commit
4e41ea5015
|
@ -41,11 +41,13 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
||||||
$routeProvider.when("/",
|
$routeProvider.when("/",
|
||||||
{
|
{
|
||||||
templateUrl: "home/home-page.html",
|
templateUrl: "home/home-page.html",
|
||||||
|
access: {
|
||||||
|
requiresLogin: true
|
||||||
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
loader: tgLoaderProvider.add(true),
|
loader: tgLoaderProvider.add(true),
|
||||||
pageParams: -> {
|
pageParams: -> {
|
||||||
"title": "PROJECT.WELCOME"
|
"title": "PROJECT.WELCOME"
|
||||||
"authRequired": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,11 +56,13 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
||||||
$routeProvider.when("/projects/",
|
$routeProvider.when("/projects/",
|
||||||
{
|
{
|
||||||
templateUrl: "projects/projects-page.html",
|
templateUrl: "projects/projects-page.html",
|
||||||
|
access: {
|
||||||
|
requiresLogin: true
|
||||||
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
loader: tgLoaderProvider.add(true),
|
loader: tgLoaderProvider.add(true),
|
||||||
pageParams: -> {
|
pageParams: -> {
|
||||||
"title": "PROJECT.SECTION_PROJECTS"
|
"title": "PROJECT.SECTION_PROJECTS"
|
||||||
"authRequired": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
controller: "Page"
|
controller: "Page"
|
||||||
|
@ -68,13 +72,12 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
||||||
$routeProvider.when("/project/:pslug/",
|
$routeProvider.when("/project/:pslug/",
|
||||||
{
|
{
|
||||||
templateUrl: "projects/project/project-page.html",
|
templateUrl: "projects/project/project-page.html",
|
||||||
resolve: {
|
access: {
|
||||||
loader: tgLoaderProvider.add(true),
|
requiresLogin: true
|
||||||
pageParams: -> {
|
|
||||||
"authRequired": true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
controller: "Page"
|
resolve: {
|
||||||
|
loader: tgLoaderProvider.add(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -172,7 +175,17 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
||||||
|
|
||||||
# User profile
|
# User profile
|
||||||
$routeProvider.when("/profile",
|
$routeProvider.when("/profile",
|
||||||
{templateUrl: "profile/profile.html"})
|
{
|
||||||
|
templateUrl: "profile/profile-page.html",
|
||||||
|
resolve: {
|
||||||
|
loader: tgLoaderProvider.add(true)
|
||||||
|
},
|
||||||
|
access: {
|
||||||
|
requiresLogin: true
|
||||||
|
}
|
||||||
|
controller: "ProfilePage"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# Auth
|
# Auth
|
||||||
$routeProvider.when("/login",
|
$routeProvider.when("/login",
|
||||||
|
@ -341,7 +354,7 @@ i18nInit = (lang, $translate) ->
|
||||||
checksley.updateMessages('default', messages)
|
checksley.updateMessages('default', messages)
|
||||||
|
|
||||||
|
|
||||||
init = ($log, $config, $rootscope, $auth, $events, $analytics, $translate) ->
|
init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $navUrls) ->
|
||||||
$log.debug("Initialize application")
|
$log.debug("Initialize application")
|
||||||
|
|
||||||
# Taiga Plugins
|
# Taiga Plugins
|
||||||
|
@ -360,6 +373,10 @@ init = ($log, $config, $rootscope, $auth, $events, $analytics, $translate) ->
|
||||||
# Analytics
|
# Analytics
|
||||||
$analytics.initialize()
|
$analytics.initialize()
|
||||||
|
|
||||||
|
$rootscope.$on '$routeChangeStart', (event, next) ->
|
||||||
|
if next.access && next.access.requiresLogin
|
||||||
|
if !$auth.isAuthenticated()
|
||||||
|
$location.path($navUrls.resolve("login"))
|
||||||
|
|
||||||
modules = [
|
modules = [
|
||||||
# Main Global Modules
|
# Main Global Modules
|
||||||
|
@ -426,11 +443,12 @@ module.config([
|
||||||
|
|
||||||
module.run([
|
module.run([
|
||||||
"$log",
|
"$log",
|
||||||
"$tgConfig",
|
|
||||||
"$rootScope",
|
"$rootScope",
|
||||||
"$tgAuth",
|
"$tgAuth",
|
||||||
"$tgEvents",
|
"$tgEvents",
|
||||||
"$tgAnalytics",
|
"$tgAnalytics",
|
||||||
"$translate"
|
"$translate",
|
||||||
|
"$tgLocation",
|
||||||
|
"$tgNavUrls",
|
||||||
init
|
init
|
||||||
])
|
])
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
class PageController extends taiga.Controller
|
class PageController extends taiga.Controller
|
||||||
@.$inject = [
|
@.$inject = [
|
||||||
"$tgAuth",
|
|
||||||
"$appTitle",
|
"$appTitle",
|
||||||
"$translate",
|
"$translate",
|
||||||
"$tgLocation",
|
|
||||||
"$tgNavUrls",
|
|
||||||
"pageParams"
|
"pageParams"
|
||||||
]
|
]
|
||||||
|
|
||||||
constructor: (@auth, @appTitle, @translate, @location, @navUrls, @pageParams) ->
|
constructor: (@appTitle, @translate, @pageParams) ->
|
||||||
if @pageParams.authRequired && !@auth.isAuthenticated()
|
|
||||||
@location.path(@navUrls.resolve("login"))
|
|
||||||
|
|
||||||
if @pageParams.title
|
if @pageParams.title
|
||||||
@translate(@pageParams.title).then (text) => @appTitle.set(text)
|
@translate(@pageParams.title).then (text) => @appTitle.set(text)
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,6 @@ describe "PageController", ->
|
||||||
|
|
||||||
provide.value "pageParams", mocks.pageParams
|
provide.value "pageParams", mocks.pageParams
|
||||||
|
|
||||||
_mockAuth = () ->
|
|
||||||
mocks.auth = {
|
|
||||||
isAuthenticated: sinon.stub()
|
|
||||||
}
|
|
||||||
|
|
||||||
provide.value "$tgAuth", mocks.auth
|
|
||||||
|
|
||||||
_mockAppTitle = () ->
|
_mockAppTitle = () ->
|
||||||
mocks.appTitle = {
|
mocks.appTitle = {
|
||||||
set: sinon.spy()
|
set: sinon.spy()
|
||||||
|
@ -23,20 +16,6 @@ describe "PageController", ->
|
||||||
|
|
||||||
provide.value "$appTitle", mocks.appTitle
|
provide.value "$appTitle", mocks.appTitle
|
||||||
|
|
||||||
_mockLocation = () ->
|
|
||||||
mocks.location = {
|
|
||||||
path: sinon.spy()
|
|
||||||
}
|
|
||||||
|
|
||||||
provide.value "$tgLocation", mocks.location
|
|
||||||
|
|
||||||
_mockNavUrls = () ->
|
|
||||||
mocks.navUrls = {
|
|
||||||
resolve: sinon.stub()
|
|
||||||
}
|
|
||||||
|
|
||||||
provide.value "$tgNavUrls", mocks.navUrls
|
|
||||||
|
|
||||||
_mockTranslate = () ->
|
_mockTranslate = () ->
|
||||||
mocks.translate = sinon.stub()
|
mocks.translate = sinon.stub()
|
||||||
|
|
||||||
|
@ -47,9 +26,6 @@ describe "PageController", ->
|
||||||
provide = $provide
|
provide = $provide
|
||||||
_mockAppTitle()
|
_mockAppTitle()
|
||||||
_mockPageParams()
|
_mockPageParams()
|
||||||
_mockAuth()
|
|
||||||
_mockLocation()
|
|
||||||
_mockNavUrls()
|
|
||||||
_mockTranslate()
|
_mockTranslate()
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
@ -62,43 +38,6 @@ describe "PageController", ->
|
||||||
inject ($controller) ->
|
inject ($controller) ->
|
||||||
controller = $controller
|
controller = $controller
|
||||||
|
|
||||||
describe "auth", () ->
|
|
||||||
it "if auth is required and the user is not logged redirect to login page", () ->
|
|
||||||
locationPath = "location-path"
|
|
||||||
|
|
||||||
mocks.pageParams.authRequired = true
|
|
||||||
mocks.auth.isAuthenticated.returns(false)
|
|
||||||
mocks.navUrls.resolve.withArgs("login").returns(locationPath)
|
|
||||||
|
|
||||||
pageCtrl = controller "Page",
|
|
||||||
$scope: {}
|
|
||||||
|
|
||||||
expect(mocks.location.path.withArgs(locationPath)).have.been.calledOnce
|
|
||||||
|
|
||||||
it "if auth is not required no redirect to login page", () ->
|
|
||||||
locationPath = "location-path"
|
|
||||||
|
|
||||||
mocks.pageParams.authRequired = false
|
|
||||||
mocks.auth.isAuthenticated.returns(false)
|
|
||||||
mocks.navUrls.resolve.withArgs("login").returns(locationPath)
|
|
||||||
|
|
||||||
pageCtrl = controller "Page",
|
|
||||||
$scope: {}
|
|
||||||
|
|
||||||
expect(mocks.location.path).have.callCount(0)
|
|
||||||
|
|
||||||
it "if auth is required and the user is logged no redirect", () ->
|
|
||||||
locationPath = "location-path"
|
|
||||||
|
|
||||||
mocks.pageParams.authRequired = true
|
|
||||||
mocks.auth.isAuthenticated.returns(true)
|
|
||||||
mocks.navUrls.resolve.withArgs("login").returns(locationPath)
|
|
||||||
|
|
||||||
pageCtrl = controller "Page",
|
|
||||||
$scope: {}
|
|
||||||
|
|
||||||
expect(mocks.location.path).have.callCount(0)
|
|
||||||
|
|
||||||
describe "page title", () ->
|
describe "page title", () ->
|
||||||
it "if title is defined set it", () ->
|
it "if title is defined set it", () ->
|
||||||
thenStub = sinon.stub()
|
thenStub = sinon.stub()
|
||||||
|
|
Loading…
Reference in New Issue