custom next url workflow in the register form

stable
Juanfran 2016-05-31 14:59:30 +02:00
parent 05c828339b
commit 35b7894346
2 changed files with 23 additions and 10 deletions

View File

@ -478,7 +478,14 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
errorHandlingService.error()
else if response.status == 401 and $location.url().indexOf('/login') == -1
nextUrl = encodeURIComponent($location.url())
$location.url($navUrls.resolve("login")).search("next=#{nextUrl}")
search = $location.search()
if search.force_next
$location.url($navUrls.resolve("login"))
.search("force_next", search.force_next)
else
$location.url($navUrls.resolve("login"))
.search("next", nextUrl)
return $q.reject(response)

View File

@ -243,8 +243,9 @@ PublicRegisterMessageDirective = ($config, $navUrls, $routeParams, templates) ->
return ""
url = $navUrls.resolve("register")
if $routeParams['next'] and $routeParams['next'] != $navUrls.resolve("register")
nextUrl = encodeURIComponent($routeParams['next'])
if $routeParams['force_next']
nextUrl = encodeURIComponent($routeParams['force_next'])
url += "?next=#{nextUrl}"
return template({url:url})
@ -259,7 +260,7 @@ module.directive("tgPublicRegisterMessage", ["$tgConfig", "$tgNavUrls", "$routeP
"$tgTemplate", PublicRegisterMessageDirective])
LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $events, $translate) ->
LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $events, $translate, $window) ->
link = ($scope, $el, $attrs) ->
form = new checksley.Form($el.find("form.login-form"))
@ -268,9 +269,16 @@ LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $
else
$scope.nextUrl = $navUrls.resolve("home")
if $routeParams['force_next']
$scope.nextUrl = decodeURIComponent($routeParams['force_next'])
onSuccess = (response) ->
$events.setupConnection()
$location.url($scope.nextUrl)
if $scope.nextUrl.indexOf('http') == 0
$window.location.href = $scope.nextUrl
else
$location.url($scope.nextUrl)
onError = (response) ->
$confirm.notify("light-error", $translate.instant("LOGIN_FORM.ERROR_AUTH_INCORRECT"))
@ -308,7 +316,7 @@ LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $
return {link:link}
module.directive("tgLogin", ["$tgAuth", "$tgConfirm", "$tgLocation", "$tgConfig", "$routeParams",
"$tgNavUrls", "$tgEvents", "$translate", LoginDirective])
"$tgNavUrls", "$tgEvents", "$translate", "$window", LoginDirective])
#############################################################################
@ -324,10 +332,8 @@ RegisterDirective = ($auth, $confirm, $location, $navUrls, $config, $routeParams
$scope.data = {}
form = $el.find("form").checksley({onlyOneErrorElement: true})
console.log $routeParams['forceNext']
if $routeParams['forceNext'] and $routeParams['forceNext'] != $navUrls.resolve("register")
$scope.nextUrl = decodeURIComponent($routeParams['forceNext'])
if $routeParams['next'] and $routeParams['next'] != $navUrls.resolve("login")
$scope.nextUrl = decodeURIComponent($routeParams['next'])
else
$scope.nextUrl = $navUrls.resolve("home")