UNPKG

1.3 kBtext/coffeescriptView Raw
1###
2Module dependencies.
3###
4
5url = require 'url'
6
7getRedirectSettings = (options, returnUrl) ->
8#getRedirectSettings = (defaultRedirectUri, returnUrl, useReturnUrl) ->
9 throw new Error '"options" parameter is required' if not options?
10
11 defaultRedirectUri = options.redirectUrl
12 useReturnUrl = options.useReturnUrl
13 logoutUrl = options.logoutUrl
14
15 portalLoginUrl = "/admin/site/Login.aspx"
16 if returnUrl.indexOf(portalLoginUrl) isnt -1
17 redirectUrl = "#{defaultRedirectUri}#{encodeURIComponent(returnUrl)}"
18 return {
19 returnUrl: encodeURIComponent(returnUrl)
20 redirectUrl: redirectUrl
21 }
22
23 returnUrlParams = url.parse(returnUrl, true)
24 returnUrl = returnUrlParams.pathname
25 if returnUrlParams.query.previousUrl
26 returnUrl = returnUrlParams.query.previousUrl
27
28 #returnUrlParts = returnUrl.split('?')
29 #returnUrl = returnUrlParts[0]
30 #if returnUrlParts.length > 1
31 #previousUrl = returnUrlParts[1].split('=')[1]
32
33 #if(returnUrl is logoutUrl)
34 #returnUrl = previousUrl
35
36 #returnUrl = returnUrl.replace(/\/$/, '')
37
38 redirectUrl = defaultRedirectUri
39 redirectUrl = "#{defaultRedirectUri}#{encodeURIComponent(returnUrl)}" if useReturnUrl
40
41 return {
42 returnUrl: encodeURIComponent(returnUrl)
43 redirectUrl: redirectUrl
44 }
45
46module.exports = getRedirectSettings