Files
growstuff/app/controllers/omniauth_callbacks_controller.rb
google-labs-jules[bot] 4b9763e1da feat: Add problem tracking feature
This commit introduces a new `Problem` model, analogous to `Crop`, to allow users to track problems they have on their plantings (e.g., aphids on tomatoes).

Key features:
- A new `Problem` model that can be curated by admins (`problem_wranglers`).
- Users can associate problems with their plantings and upload photos of the problems.
- Aggregated problem information is displayed on the crop detail page (e.g., "Problems: aphids (27), blight (13)").
- Users can mention problems in posts (e.g., `[aphids](problem)`), which automatically links to the problem's page.
- Admin functionality for reviewing and approving new problem suggestions.

Resolves merge conflict in app/controllers/plantings_controller.rb
2025-09-07 11:47:53 +00:00

50 lines
1.3 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
else
finish_signup_path(resource)
end
end
end