Sha256: 82f6da1807099648607d62086e1b1f53fb5b3a56a88e842eb821c269a641f6e6

Contents?: true

Size: 877 Bytes

Versions: 32

Compression:

Stored size: 877 Bytes

Contents

class Sessions::OmniauthController < ApplicationController
  skip_before_action :verify_authenticity_token
  skip_before_action :authenticate

  def create
    @user = User.where(omniauth_params).first_or_initialize(user_params)

    if @user.save
      session = @user.sessions.create!
      cookies.signed.permanent[:session_token] = { value: session.id, httponly: true }

      redirect_to root_path, notice: "Signed in successfully"
    else
      redirect_to sign_in_path, alert: "Authentication failed"
    end
  end

  def failure
    redirect_to sign_in_path, alert: params[:message]
  end

  private
    def omniauth_params
      { provider: omniauth.provider, uid: omniauth.uid }
    end

    def user_params
      { email: omniauth.info.email, password: SecureRandom::base58, verified: true }
    end

    def omniauth
      request.env["omniauth.auth"]
    end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
authentication-zero-2.16.12 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.11 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.10 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.9 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.8 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.7 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.6 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.5 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.4 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.3 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.2 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.1 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.16.0 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.15.9 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.15.8 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.15.7 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.15.6 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.15.5 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.15.4 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt
authentication-zero-2.15.3 lib/generators/authentication/templates/controllers/html/sessions/omniauth_controller.rb.tt