Attempt to assign anonymous screenshots to logged-in user
This commit is contained in:
parent
228b7375e7
commit
0dd63f6bf6
7 changed files with 65 additions and 25 deletions
23
app/controllers/users/my_sessions_controller.rb
Normal file
23
app/controllers/users/my_sessions_controller.rb
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue