我已经链接了一些我想按特定顺序执行的方法。第二种方法deviseLogin()
返回一个 URL,应该在下一个方法中传递redirect(url)
第一种和第二种方法运行,但我从来没有从最后一个听到任何消息redirect(url)
。你能看出我做错了什么吗?
getUserToken = (username, password) ->
console.log "I'm first"
$http(
method: "POST"
url: "/oauth/token"
params: params
).success((data, status, headers, config) ->
$scope.$storage.token = data.access_token
defer = $q.defer()
$scope.signIn = (data) ->
defer.promise
.then( getUserToken($scope.email, $scope.password) )
.then( deviseLogin() )
.then( redirect(url) )
redirect = (url) ->
console.log "I'm last"
console.log "will redirect to #{url}"
$window.location = data.url
deviseLogin = () ->
console.log "I'm second"
$scope.authErrors = []
authData = { user: { email: $scope.email, password: $scope.password }}
$http(
# Perform a regular Devise login
method: "POST"
url: "/users/sign_in"
data: authData
)
.success (data) ->
# I can see the log lines below and data.url is what I expect it to be
console.log "logged in devise"
console.log "data.url: #{data.url}"
data.url