Sha256: 0588526aede218091a1292d26a64dd5d6762c5f7b5d5037574d01e5141ca80fd

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

class DiscoApp::UserSessionsController < ApplicationController
  include DiscoApp::Concerns::AuthenticatedController

  def new
    authenticate if sanitized_shop_name.present?
  end

  def create
    authenticate
  end

  def callback
    if auth_hash
      login_user
      redirect_to return_address
    else
      redirect_to root_path
    end
  end

  def destroy
    session[:shopify_user] = nil
    redirect_to root_path
  end

  protected

    def auth_hash
      request.env['omniauth.auth']
    end

    def associated_user(auth_hash)
      auth_hash['extra']['associated_user']
    end

    def authenticate
      if sanitized_shop_name.present?
        fullpage_redirect_to "#{main_app.root_path}auth/shopify_user?shop=#{sanitized_shop_name}"
      else
        redirect_to return_address
      end
    end

    def login_user
      @user = DiscoApp::User.create_user(associated_user(auth_hash), @shop)
      session[:shopify_user] = @user.id
    end

    def return_address
      session.delete(:return_to) || main_app.root_url
    end

    def sanitized_shop_name
      @shop.shopify_domain
    end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
disco_app-0.13.6 app/controllers/disco_app/user_sessions_controller.rb
disco_app-0.13.7 app/controllers/disco_app/user_sessions_controller.rb
disco_app-0.13.8 app/controllers/disco_app/user_sessions_controller.rb
disco_app-0.13.6.pre.puma.pre.3 app/controllers/disco_app/user_sessions_controller.rb