Setting up after_login redirects

This commit is contained in:
Will Marshall
2014-05-21 16:39:59 +10:00
parent 2d0a42b2c2
commit 67e72f4504
10 changed files with 42 additions and 14 deletions

View File

@@ -1,8 +1,11 @@
Darkswarm.controller "LoginCtrl", ($scope, $http, $location, AuthenticationService) ->
Darkswarm.controller "LoginCtrl", ($scope, $http, AuthenticationService, Redirections) ->
$scope.path = "/login"
$scope.submit = ->
$http.post("/user/spree_user/sign_in", {spree_user: $scope.spree_user}).success (data)->
location.href = location.origin + location.pathname # Strips out hash fragments
if Redirections.after_login
location.href = location.origin + Redirections.after_login
else
location.href = location.origin + location.pathname # Strips out hash fragments
.error (data) ->
$scope.errors = data.message

View File

@@ -1,4 +1,4 @@
Darkswarm.factory "AuthenticationService", (Navigation, $modal, $location)->
Darkswarm.factory "AuthenticationService", (Navigation, $modal, $location, Redirections)->
new class AuthenticationService
selectedPath: "/login"

View File

@@ -0,0 +1,3 @@
Darkswarm.factory "Redirections", ($location)->
new class Redirections
after_login: $location.search().after_login

View File

@@ -13,8 +13,7 @@ Spree::Admin::OverviewController.class_eval do
redirect_to '/unauthorized'
else
store_location
url = respond_to?(:spree_login_path) ? spree_login_path : root_path
redirect_to url
redirect_to root_path(anchor: "login?after_login=#{spree.admin_path}")
end
end
end

View File

@@ -1,4 +1,9 @@
module SharedHelper
def inject_json(name, partial)
render "json/injection", name: name, partial: partial
end
def distributor_link_class(distributor)
cart = current_order(true)
@active_distributors ||= Enterprise.distributors_with_active_order_cycles

View File

@@ -0,0 +1,2 @@
:javascript
angular.module('Darkswarm').value("#{name.to_s}", #{render "json/#{partial.to_s}"})

View File

@@ -15,16 +15,16 @@
= csrf_meta_tags
%body.off-canvas{"ng-app" => "Darkswarm"}
= inject_json "currentHub", "current_hub"
= inject_json "user", "current_user"
.off-canvas-wrap{offcanvas: true}
.inner-wrap
= render partial: "shared/current_hub"
= render partial: "shared/current_user"
= render partial: "shared/menu/menu"
= display_flash_messages
%ofn-flash
-#= render "shared/sidebar"
%section{ role: "main" }
= yield

View File

@@ -1,2 +0,0 @@
:javascript
angular.module('Darkswarm').value('currentHub', #{render "json/current_hub"})

View File

@@ -1,2 +0,0 @@
:javascript
angular.module('Darkswarm').value('user', #{render "json/current_user"})

View File

@@ -5,7 +5,27 @@ feature "Authentication", js: true do
describe "login" do
let(:user) { create(:user, password: "password", password_confirmation: "password") }
describe "newskool" do
describe "With redirects" do
scenario "logging in with a redirect set" do
visit groups_path(anchor: "login?after_login=#{producers_path}")
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_login_button
page.should have_content "Select a producer from the list below"
current_path.should == producers_path
end
scenario "logging into admin redirects home, then back to admin" do
visit spree.admin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_login_button
page.should have_content "Dashboard"
current_path.should == spree.admin_path
end
end
describe "Loggin in from the home page" do
before do
visit root_path
end