Attempt to assign anonymous screenshots to logged-in user

This commit is contained in:
Christoph Haas 2018-08-20 19:32:34 +02:00
parent 228b7375e7
commit 0dd63f6bf6
7 changed files with 65 additions and 25 deletions

View file

@ -0,0 +1,23 @@
class Users::MySessionsController < Devise::SessionsController
# before_filter :before_login, :only => :create
after_filter :after_login, :only => :create
# def before_login
# end
# Hook after successful login
def after_login
Log.log "User #{current_user} logged in."
old_screenshots = session[:uploaded_screenshots]
raise
if count = old_screenshots.to_a.length > 0
old_screenshots.each do |id|
ss = Screenshot.find(id)
ss.user = @user
ss.save!
end
flash[:info] = "#{count} uploads have been added to your account"
Log.log "Anonymously uploaded screenshots #{old_screenshots} added to account."
end
end
end

View file

@ -33,6 +33,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
# Has the user uploaded screenshots while not being logged in?
# Move the screenshots to the real account and tell the user.
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => provider_name
sign_in_and_redirect @user, :event => :authentication