mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-11-04 12:12:48 -05:00
28 lines
902 B
Ruby
28 lines
902 B
Ruby
# frozen_string_literal: true
|
|
|
|
class SessionsController < Devise::SessionsController
|
|
respond_to :html, :json
|
|
|
|
def create
|
|
super do |_resource|
|
|
flash[:notice] = t('devise.sessions.signed_in') if request.format.json?
|
|
flash[:alert] = t('messages.crops_waiting') if Crop.pending_approval.present? && current_member.role?(:crop_wrangler)
|
|
flash[:alert] = location_prompt if current_member.location_unplaced? && request.format.html?
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def location_prompt
|
|
t('messages.location_unplaced_html', location: ERB::Util.h(current_member.location), link: edit_member_registration_path)
|
|
end
|
|
|
|
# The sign in dialog reloads the page it was opened over, so a success needs
|
|
# no body. A failure is Devise's own 401 with an `error` message.
|
|
def respond_with(*args, &)
|
|
return head :no_content if request.format.json? && member_signed_in?
|
|
|
|
super
|
|
end
|
|
end
|