mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-24 01:57:46 -05:00
* Fix todo * Rubcop * Rubocop * Rubocop * Rename harvests_routing_spec.rb to harvests_controller_routing_spec.rb Making codeclimate happier * Rename for CodeFactor: updates_routing_spec.rb to posts_controller_updates_routing_spec.rb For codefactor * Rename for CodeFactor: follows_routing_spec.rb to follows_controller_routing_spec.rb * Rename for CodeFactor: forums_routing_spec.rb to forums_controller_routing_spec.rb * Rename spec/routing/roles_routing_spec.rb to spec/routing/admin/roles_controller_routing_spec.rb * Rename authentications_routing_spec.rb to authentications_controller_routing_spec.rb * Rename for CodeFactor: plantings_routing_spec.rb to plantings_controller_routing_spec.rb * Rename for CodeFactor: scientific_names_routing_spec.rb to scientific_names_controller_routing_spec.rb * Rename for CodeFactor: seeds_routing_spec.rb to seeds_controller_routing_spec.rb * Rename for CodeFactor: comments_routing_spec.rb to comments_controller_routing_spec.rb * Rename for CodeFactor: garden_types_routing_spec.rb to garden_types_controller_routing_spec.rb * Rename for CodeFactor: admin_routing_spec.rb to admin_controller_routing_spec.rb * Rename for CodeFactor: gardens_routing_spec.rb to gardens_controller_routing_spec.rb * Rename for CodeFactor: photos_routing_spec.rb to photos_controller_routing_spec.rb * Rename for CodeFactor: plant_parts_routing_spec.rb to plant_parts_controller_routing_spec.rb * Rename for CodeFactor: crops_routing_spec.rb to crops_controller_routing_spec.rb * [CodeFactor] Apply fixes * Rename * Code factor bot --------- Co-authored-by: Cesy <cesy.avon@gmail.com> Co-authored-by: codefactor-io <support@codefactor.io>
50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require './lib/actions/oauth_signup_action'
|
|
|
|
#
|
|
# Handle signup or signin
|
|
# from various oauth providers
|
|
#
|
|
# Heavily overlaps with Authentications controller
|
|
#
|
|
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|
def failure
|
|
flash[:alert] = "Authentication failed."
|
|
redirect_to request.env['omniauth.origin'] || "/"
|
|
end
|
|
|
|
private
|
|
|
|
def create
|
|
auth = request.env['omniauth.auth']
|
|
action = Growstuff::OauthSignupAction.new
|
|
|
|
@authentication = nil
|
|
|
|
return redirect_to request.env['omniauth.origin'] || edit_member_registration_path unless auth
|
|
|
|
member = action.find_or_create_from_authorization(auth)
|
|
@authentication = action.establish_authentication(auth, member)
|
|
|
|
if action.member_created?
|
|
raise "Invalid provider" unless %w(twitter flickr).index(auth['provider'].to_s)
|
|
|
|
session["devise.#{auth['provider']}_data"] = request.env["omniauth.auth"]
|
|
sign_in member
|
|
redirect_to finish_signup_url(member)
|
|
else
|
|
sign_in_and_redirect member, event: :authentication # this will throw if @user is not activated
|
|
set_flash_message(:notice, :success, kind: auth['provider']) if is_navigational_format?
|
|
end
|
|
end
|
|
|
|
def after_sign_in_path_for(resource)
|
|
if resource.tos_agreement
|
|
super(resource)
|
|
else
|
|
finish_signup_path(resource)
|
|
end
|
|
end
|
|
end
|