asciinema.org/app/controllers/sessions_controller.rb

44 lines
942 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 =
2012-06-09 22:11:27 +00:00
User.find_by_provider_and_uid(@auth["provider"], @auth["uid"].to_s) ||
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
2012-07-25 18:24:20 +00:00
redirect_back_or_to root_url, :notice => "Logged in!"
2012-03-05 23:25:21 +00:00
end
end
def destroy
self.current_user = nil
2012-07-25 18:24:20 +00:00
redirect_to root_url, :notice => "Logged 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
2012-04-09 12:42:22 +00:00
session[:new_user] = {
:provider => @user.provider,
:uid => @user.uid,
:avatar_url => @user.avatar_url
}
2012-03-10 13:58:10 +00:00
end
end