-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dcc698
commit 14c1c7f
Showing
9 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the omniauth controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: https://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class OmniauthController < ApplicationController | ||
|
||
def google_oauth2 | ||
@user = User.create_from_google_data(request.env['omniauth.auth']) | ||
if @user.persisted? | ||
sign_in_and_redirect @user | ||
set_flash_message(:notice, :success, kind: 'Google') if is_navigation_format? | ||
else | ||
flash[:error] = 'There was a problem signing you in through Google, Please register or try signing in later.' | ||
redirect_to new_user_registration_url | ||
end | ||
end | ||
|
||
def failure | ||
flash[:error] = 'There was a problem signing you in through Google, Please register or try signing in later.' | ||
redirect_to new_user_registration_url | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module OmniauthHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
class User < ApplicationRecord | ||
class User < ApplicationRecord | ||
# Include default devise modules. Others available are: | ||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :validatable | ||
:recoverable, :rememberable, :validatable, | ||
:omniauthable, omniauth_providers: [:google_oauth2] | ||
|
||
has_many :ratings | ||
has_many :rated_games, through: :ratings, source: :game | ||
|
||
#but also user has created many games to the list | ||
has_many :games | ||
|
||
def self.create_from_provider_data(provider_data) | ||
where(provider: provider_data.provider, uid: provider_data.uid).first_or_create do |user| | ||
user.email = provider_data.info.email | ||
user.password =Devise.friendly_token[0, 20] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class UpdateUsers < ActiveRecord::Migration[6.0] | ||
def change | ||
add_column(:users, :provider, :string, limit: 50, null: false, default: '') | ||
add_column(:users, :uid, :string, limit: 500, null: false, default: '') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateSessions < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :sessions do |t| | ||
t.string :session_id, null: false | ||
t.text :data | ||
t.timestamps | ||
end | ||
add_index :sessions, :session_id, unique: true | ||
add_index :sessions, :updated_at | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class OmniauthControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |