forked from solidusio/solidus_auth_devise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers_controller.rb
More file actions
68 lines (55 loc) · 1.48 KB
/
users_controller.rb
File metadata and controls
68 lines (55 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
class Spree::UsersController < Spree::StoreController
skip_before_action :set_current_order, only: :show, raise: false
prepend_before_action :authorize_actions, only: :new
def show
load_object
@orders = @user.orders.complete.order('completed_at desc')
end
def create
@user = Spree::User.new(user_params)
if @user.save
if current_order
session[:guest_token] = nil
end
redirect_back_or_default(root_url)
else
render :new
end
end
def edit
load_object
end
def update
load_object
if @user.update(user_params)
spree_current_user.reload
redirect_url = spree.account_url
if params[:user][:password].present?
# this logic needed b/c devise wants to log us out after password changes
if Spree::Auth::Config[:signout_after_password_change]
redirect_url = spree.login_url
else
bypass_sign_in(@user)
end
end
redirect_to redirect_url, notice: I18n.t('spree.account_updated')
else
render :edit
end
end
private
def user_params
params.require(:user).permit(Spree::PermittedAttributes.user_attributes | [:email])
end
def load_object
@user ||= Spree::User.find_by(id: spree_current_user&.id)
authorize! params[:action].to_sym, @user
end
def authorize_actions
authorize! params[:action].to_sym, Spree::User.new
end
def accurate_title
I18n.t('spree.my_account')
end
end