Commit afbc5c47 by Trịnh Hoàng Phúc

Merge branch 'feature/social_authenticate' into 'master'

Feature/social authenticate

See merge request !19
parents 629f8bc6 0aeba9ec
Pipeline #625 failed with stages
in 0 seconds
......@@ -33,6 +33,8 @@ gem 'activerecord-import', require: false
gem 'will_paginate'
gem 'omniauth-facebook'
gem 'settingslogic'
gem 'parallel', require: false
......
......@@ -103,6 +103,7 @@ GEM
ffi (1.12.2-x86-mingw32)
globalid (0.4.2)
activesupport (>= 4.2.0)
hashie (4.1.0)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
image_processing (1.10.3)
......@@ -110,6 +111,7 @@ GEM
ruby-vips (>= 2.0.17, < 3)
jbuilder (2.10.0)
activesupport (>= 5.0.0)
jwt (2.2.1)
kaminari (1.2.0)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.0)
......@@ -145,6 +147,8 @@ GEM
msgpack (1.3.3-java)
msgpack (1.3.3-x64-mingw32)
msgpack (1.3.3-x86-mingw32)
multi_json (1.14.1)
multi_xml (0.6.0)
multipart-post (2.1.1)
mysql2 (0.5.3)
mysql2 (0.5.3-x64-mingw32)
......@@ -159,6 +163,20 @@ GEM
mini_portile2 (~> 2.4.0)
nokogiri (1.10.9-x86-mingw32)
mini_portile2 (~> 2.4.0)
oauth2 (1.4.4)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.9.1)
hashie (>= 3.4.6)
rack (>= 1.6.2, < 3)
omniauth-facebook (6.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.6.0)
oauth2 (~> 1.1)
omniauth (~> 1.9)
orm_adapter (0.5.0)
parallel (1.19.1)
pry (0.13.0)
......@@ -306,6 +324,7 @@ DEPENDENCIES
listen (>= 3.0.5, < 3.2)
meta-tags
mysql2
omniauth-facebook
parallel
pry
puma (~> 4.1)
......
......@@ -27,4 +27,19 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# def after_omniauth_failure_path_for(scope)
# super(scope)
# end
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def failure
redirect_to root_path
end
end
......@@ -2,7 +2,7 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :confirmable
:recoverable, :rememberable, :validatable, :confirmable, :omniauthable, omniauth_providers: %i[facebook]
has_many :applies
has_many :jobs, through: :applies
......@@ -10,4 +10,24 @@ class User < ApplicationRecord
has_many :jobs, through: :favorites
mount_uploader :cv, CvUploader
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0, 20]
user.full_name = auth.info.name # assuming the user model has a name
# user.image = auth.info.image # assuming the user model has an image
# If you are using confirmable and the provider(s) you use validate emails,
# uncomment the line below to skip the confirmation emails.
user.skip_confirmation!
end
end
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
user.email = data["email"] if user.email.blank?
end
end
end
end
......@@ -28,6 +28,7 @@
<p class="actions">
<%= f.submit "Log in", class: "button" %>
<%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path, class: "button" %>
</p>
<% end %>
<p>
......
......@@ -6,20 +6,20 @@
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<!-- <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end %>
<% end %> -->
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<!-- <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_user_confirmation_path(resource_name) %><br />
<% end %>
<% end %> -->
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<!-- <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end %>
<% end %> -->
<%- if devise_mapping.omniauthable? %>
<!-- <%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
<% end %>
<% end %>
<% end %> -->
......@@ -27,7 +27,14 @@
<div id="content" class="container content-area" role="main">
<div class="job-overview-content row">
<div class="job_listing-description job-overview col-md-9 col-sm-12">
<h4>Benefit</h4>
<%= raw(@job.benefit) %>
<h4>Job requirements</h4>
<%= raw(@job.job_requirements) %>
<h4>Job description</h4>
<%= raw(@job.job_description) %>
<h4>Other information</h4>
<%= raw(@job.other_information) %>
</div>
<div class="job-meta col-md-3 col-sm-6 col-xs-12">
<aside class="widget widget--job_listing">
......@@ -54,7 +61,7 @@
<ul>
<li>Name: <%= @job.company.title %></li>
<li>Address: <%= @job.company.address %></li>
<li>Description: <%= @job.company.description %></li>
<li>Description: <%= raw(@job.company.description) %></li>
</ul>
</aside>
<aside class="widget widget--job_listing">
......
......@@ -260,7 +260,7 @@ Devise.setup do |config|
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
config.omniauth :facebook, "174972447159044", "24253120f824a205681970a5ebb707ab", token_params: { parse: :json }
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
# change the failure app, you can configure them inside the config.warden block.
......
......@@ -4,7 +4,8 @@ Rails.application.routes.draw do
}
devise_for :users, controllers: {
sessions: 'users/sessions',
confirmations: 'users/confirmations'
confirmations: 'users/confirmations',
omniauth_callbacks: 'users/omniauth_callbacks'
}
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root to: 'home#index'
......
class AddColumnsToUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :full_name, :string
add_column :users, :image, :string
add_column :users, :cv, :string
end
end
class AddColumnsProviderAndUidToUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :provider, :string
add_column :users, :uid, :string
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_05_11_055632) do
ActiveRecord::Schema.define(version: 2020_05_15_033747) do
create_table "admins", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "email", default: "", null: false
......@@ -111,6 +111,8 @@ ActiveRecord::Schema.define(version: 2020_05_11_055632) do
t.datetime "updated_at", precision: 6, null: false
t.string "full_name"
t.string "cv"
t.string "provider"
t.string "uid"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment