asciinema.org/app/controllers/sessions_controller.rb

41 lines
867 B
Ruby
Raw Normal View History

class SessionsController < ApplicationController
before_filter :load_omniauth_auth, :only => :create
def new; end
def create
2012-03-05 23:25:21 +00:00
@user =
User.find_by_provider_and_uid(@auth["provider"], @auth["uid"]) ||
User.create_with_omniauth(@auth)
2012-03-05 23:25:21 +00:00
unless @user.persisted?
2012-03-10 13:58:10 +00:00
store_sensitive_user_data_in_session
2012-03-05 23:25:21 +00:00
render 'users/new', :status => 422
else
self.current_user = @user
redirect_back_or_to root_url, :notice => "Signed in!"
end
end
def destroy
self.current_user = nil
redirect_to root_url, :notice => "Signed out!"
end
def failure
redirect_to root_url, :alert => params[:message]
end
private
def load_omniauth_auth
@auth = request.env["omniauth.auth"]
end
2012-03-10 13:58:10 +00:00
def store_sensitive_user_data_in_session
session[:provider] = @user.provider
session[:uid] = @user.uid
end
end