Class: Checkout::LoginController
- Inherits:
-
CheckoutController
- Object
- CheckoutController
- Checkout::LoginController
- Defined in:
- app/controllers/gemgento/checkout/login_controller.rb
Instance Method Summary collapse
-
#guest ⇒ Object
Continue with current order as guest.
-
#login ⇒ Object
Login user to an existing account and associate with current order.
-
#register ⇒ Object
Register a new user and associate with order current order.
- #show ⇒ Object
Instance Method Details
#guest ⇒ Object
Continue with current order as guest
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/gemgento/checkout/login_controller.rb', line 72 def guest @quote.customer_is_guest = true @user = User.new respond_to do |format| if @quote.update(quote_params) format.html { redirect_to after_checkout_login_path } format.json { render json: { result: true } } else # problem saving order format.html { render 'show' } format.json { render json: { result: false, errors: @quote.errors }, status: 422 } end end end |
#login ⇒ Object
Login user to an existing account and associate with current order.
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 |
# File 'app/controllers/gemgento/checkout/login_controller.rb', line 16 def login respond_to do |format| if @user = User::is_valid_login(params[:email], params[:password]) @quote.customer_is_guest = false @quote.user = @user @quote.push_customer = true if @quote.save sign_in(:user, @user) format.html { redirect_to after_checkout_login_path } format.json { render json: { result: true } } else # problem saving order format.html { render 'show' } format.json { render json: { result: false, errors: @quote.errors }, status: 422 } end else # failed login attempt @user = User.new flash.now[:alert] = 'Invalid username and password.' format.html { render 'show' } format.json { render json: { result: false, errors: flash[:alert] }, status: 422 } end end end |
#register ⇒ Object
Register a new user and associate with order current order
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 69 |
# File 'app/controllers/gemgento/checkout/login_controller.rb', line 43 def register @user = User.new(user_params) @user.stores << current_store @user.user_group = UserGroup.find_by(code: 'General') respond_to do |format| if @user.save @quote.customer_is_guest = false @quote.user = @user @quote.push_customer = true if @quote.save sign_in(:user, @user) format.html { redirect_to after_checkout_login_path } format.json { render json: { result: true } } else format.html { render 'show' } format.json { render json: { result: false, errors: @quote.errors }, status: 422 } end else # couldn't create user format.html { render 'show' } format.json { render json: { result: false, errors: @user.errors }, status: 422 } end end end |
#show ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'app/controllers/gemgento/checkout/login_controller.rb', line 6 def show @user = @quote.user || User.new respond_to do |format| format.html format.json { render json: { user: @user, quote: @quote } } end end |