Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
helper_method :current_user

before_action :require_login

protected
def require_login
origin = request.original_fullpath
redirect_to root_path(origin: origin) unless current_user
end

private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class HomeController < ApplicationController
skip_before_action :require_login

def index
redirect_to friends_path if current_user
end
end
4 changes: 3 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class SessionsController < ApplicationController
skip_before_action :require_login

def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id

redirect_to friends_path, :notice => "Signed in!"
redirect_to request.env['omniauth.origin'] || friends_path, :notice => "Signed in!"
end

def destroy
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
module ApplicationHelper
def login_path
query = request.query_parameters.to_query
"/auth/facebook?#{query}"
end
end
2 changes: 1 addition & 1 deletion app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

<div>
<%= link_to "/auth/facebook", id:"fb-link" do %>
<%= link_to login_path, id:"fb-link" do %>
<div class="fb-join">
<div class="fb-join-image"><img src="https://d12hfz37g51hrt.cloudfront.net/assets/intro/intro_btn_fb-86680a3702eb0c41f5cf6412554e2360.png"></div>
<div class="fb-join-text">페이스북으로 시작하기</div>
Expand Down