Class: Contour::SessionsController

Inherits:
Devise::SessionsController
  • Object
show all
Defined in:
app/controllers/contour/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

Overwrite Devise authentication to check if the user is typing another credential into the default box if so, find alternative login methods for that user and forward the user to those login screens



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/contour/sessions_controller.rb', line 24

def create
  # resource = warden.authenticate!(auth_options)
  resource = warden.authenticate(auth_options)

  if resource
    set_flash_message(:notice, :signed_in) if is_navigational_format?
    (resource_name, resource)

    respond_to do |format|
      format.html { respond_with resource, location: (resource) }
      format.json { render json: { success: true, user: resource.as_json( only: [:id, :email, :first_name, :last_name, :authentication_token ] ) } }
    end
  else
    resource = resource_name.to_s.titleize.constantize.find_by_email(params[resource_name][:email])
    if resource and resource.respond_to?('authentications') and providers = resource.authentications.pluck(:provider).uniq and providers.size > 0
      redirect_to request.script_name + '/auth/' + providers.first
    elsif providers = Authentication.where(uid: params[resource_name][:email]).pluck(:provider).uniq and providers.size > 0
      redirect_to request.script_name + '/auth/' + providers.first
    else
      resource = warden.authenticate!(auth_options)
    end
  end
end

#newObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/contour/sessions_controller.rb', line 6

def new
  @news_feed = ''
  unless Contour.news_feed.blank?
    begin
      open(Contour.news_feed, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
        response = http.read
        @news_feed = RSS::Parser.parse(response, false)
      end
    rescue => e
      logger.info "\n\nRSS Feed #{Contour.news_feed}\nRSS Feed Error: #{e}\n\n"
    end
  end

  super
end