-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add user signup with GitHub OAuth #125
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d2cf8d5
Add dotenv
kinoppyd 752a910
Add ignore files
kinoppyd f4268d5
Add omniauth-github
kinoppyd ffa1811
Add initializer for omniauth
kinoppyd b51e46f
bin/rails g controller sessions
kinoppyd 03a4225
Add routes and controller action
kinoppyd 6e4624d
Add Profile model, relations and migrations
kinoppyd b05d484
Don't create default user. Create when agree to terms of service
kinoppyd 42a814c
Implements signup with GitHub
kinoppyd 919365a
Remove email column from profiles table
kinoppyd 0ffb99b
Use login name instead of user name
kinoppyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 @@ | ||
# frozen_string_literal: true | ||
|
||
class ProfilesController < ApplicationController | ||
include EventRouting | ||
|
||
def show; 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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
class SessionsController < ApplicationController | ||
skip_before_action :set_plan | ||
skip_before_action :set_locale | ||
skip_before_action :set_last_path | ||
|
||
def create | ||
user_info = request.env['omniauth.auth'] | ||
profile = Profile.find_by(uid: user_info['uid']) | ||
|
||
if profile | ||
session[:user_id] = profile.user.id | ||
else | ||
create_and_set_user unless @user | ||
@user.create_profile( | ||
provider: user_info['provider'], | ||
uid: user_info['uid'], | ||
name: user_info['info']['name'], | ||
email: user_info['info']['email'], | ||
avatar_url: user_info['info']['image'] | ||
) | ||
end | ||
|
||
redirect_to session[:last_path] || root_path | ||
end | ||
|
||
def delete | ||
session[:user_id] = nil | ||
|
||
redirect_to root_path | ||
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,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module ProfilesHelper | ||
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,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module SessionsHelper | ||
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 @@ | ||
# frozen_string_literal: true | ||
|
||
class Profile < ApplicationRecord | ||
belongs_to :user | ||
|
||
validates :provider, presence: true | ||
validates :uid, presence: true | ||
validates :name, presence: true | ||
validates :email, presence: true | ||
validates :avatar_url, presence: true | ||
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,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class User < ApplicationRecord | ||
has_one :profile | ||
has_many :plans | ||
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,37 @@ | ||
<% if @user && @user.profile %> | ||
<div class="flex justify-center"> | ||
<div class="w-1/2"> | ||
<div class="w-full min-w-[400px] h-fit p-4 shadow-[0_1px_2px_0_rgba(3,3,2,0.3)] rounded-md bg-white"> | ||
<div class="flex gap-4"> | ||
<img class="w-36 h-36 rounded-full" src="<%= @user.profile.avatar_url %>"> | ||
<div class="flex flex-col gap-2 w-full"> | ||
<div class="flex-grow flex flex-col gap-2"> | ||
<h1 class="text-4xl"><%= @user.profile.name %></h1> | ||
<h2><%= @user.profile.email %></h2> | ||
</div> | ||
<div class="self-end"> | ||
<%= form_with(url: '/session', method: :delete) do |f| %> | ||
<%= f.submit I18n.t('button.signout'), class: "p-2 text-sm m-h-[calc(0.857143rem+18px)] normal-button" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<% else %> | ||
<div class="flex items-center justify-center h-96"> | ||
<div class="h-auto"> | ||
<%= form_tag('/auth/github', method: 'post' , data: {turbo: false}) do %> | ||
<button type='submit' class="p-2 border border-black border-solid rounded-md"> | ||
<div class="flex items-center gap-2"> | ||
<img src="/icons/github-mark.svg" class="w-6 h-6"> | ||
<span class="font-bold"> | ||
Sign up with GitHub | ||
</span> | ||
</div> | ||
</button> | ||
<% end %> | ||
</div> | ||
</div> | ||
<% 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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :github, ENV.fetch('GITHUB_KEY', nil), ENV.fetch('GITHUB_SECRET', nil), scope: 'read:user' | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emailとnameはGithub側で空欄で登録できるので、必須にしないほうが親切かも?と思いました!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emailは以下をチェックしていてもnilになるみたいです!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
必須にする場合は、profile作成失敗時に適切にエラーメッセージを表示してあげると良さそうです!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ちなみにアバター画像については、頑張って外そうと試みたのですが、gravatarの画像が勝手に設定されちゃってできませんでした...
docによると
とあるので空になることはないのかもしれません。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emailはもしかしたら、と思っていたんですがnameは想定外だったので、チェックしていただいて助かりました。
ちょっと修正を入れます