Sha256: 8ff1ccc29b34a5c150ca76d77032f593595d7938486dd8de2b03b1020ce11e5c

Contents?: true

Size: 1.7 KB

Versions: 14

Compression:

Stored size: 1.7 KB

Contents

module Adminpanel
  class SessionsController < ActionController::Base
    include SessionsHelper
    include ApplicationHelper

    layout 'adminpanel/application-login'
    before_action :configure_instagram, only: [
                                          :instagram_login,
                                          :instagram_callback
                                        ]

    def new
    end

    def create
      user = User.find_by_email(params[:session][:email].downcase)
      if user && user.authenticate(params[:session][:password])
        sign_in user
        flash[:success] = I18n.t('authentication.signin_success')
        permission = user.role.permissions.first
        if permission.nil?
          redirect_to root_url
        else
          redirect_to [route_symbol(permission.resource)]
        end
      else
        flash.now[:error] = I18n.t('authentication.signin_error')
        render 'new'
      end
    end

    def destroy
      sign_out
      redirect_to signin_path
    end

    def instagram_login
      redirect_to Instagram.authorize_url(redirect_uri: instagram_callback_sessions_url, scope: 'comments')
    end

    def instagram_callback
      response = Instagram.get_access_token(params[:code], redirect_uri: instagram_callback_sessions_url)
      username = Instagram.client(access_token: response.access_token).user.username
      Auth.create(key: 'instagram', value: response.access_token, name: "@#{username}")
      redirect_to instagram_analytics_path
    end

    private

    def configure_instagram
      Instagram.configure do |config|
        config.client_id = Adminpanel.instagram_client_id
        config.client_secret = Adminpanel.instagram_client_secret
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
adminpanel-3.6.1 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.6.0 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.5.1 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.5.0 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.4.7 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.4.6 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.4.5 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.4.4 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.4.3 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.4.2 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.4.1 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.4.0 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.3.4 app/controllers/adminpanel/sessions_controller.rb
adminpanel-3.3.3 app/controllers/adminpanel/sessions_controller.rb