Class: Checkout::LoginController

Inherits:
CheckoutController
  • Object
show all
Defined in:
app/controllers/gemgento/checkout/login_controller.rb

Instance Method Summary collapse

Instance Method Details

#guestObject

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  }
      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

#loginObject

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 
  respond_to do |format|

    if @user = User::(params[:email], params[:password])
      @quote.customer_is_guest = false
      @quote.user = @user
      @quote.push_customer = true

      if @quote.save
        (:user, @user)
        format.html { redirect_to  }
        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

#registerObject

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
        (:user, @user)
        format.html { redirect_to  }
        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

#showObject



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