mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Setting up after_login redirects
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory "AuthenticationService", (Navigation, $modal, $location)->
|
||||
Darkswarm.factory "AuthenticationService", (Navigation, $modal, $location, Redirections)->
|
||||
new class AuthenticationService
|
||||
selectedPath: "/login"
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Darkswarm.factory "Redirections", ($location)->
|
||||
new class Redirections
|
||||
after_login: $location.search().after_login
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
2
app/views/json/_injection.html.haml
Normal file
2
app/views/json/_injection.html.haml
Normal file
@@ -0,0 +1,2 @@
|
||||
:javascript
|
||||
angular.module('Darkswarm').value("#{name.to_s}", #{render "json/#{partial.to_s}"})
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
:javascript
|
||||
angular.module('Darkswarm').value('currentHub', #{render "json/current_hub"})
|
||||
@@ -1,2 +0,0 @@
|
||||
:javascript
|
||||
angular.module('Darkswarm').value('user', #{render "json/current_user"})
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user