Skip to content

Commit

Permalink
Implements signup with GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
kinoppyd committed Mar 27, 2024
1 parent b05d484 commit 520e2d7
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/profiles_controller.rb
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
10 changes: 9 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# frozen_string_literal: true

class SessionsController < ApplicationController
skip_before_action :set_user
skip_before_action :set_plan
skip_before_action :set_locale
skip_before_action :set_last_path

def create
create_and_set_user unless @user

user_info = request.env['omniauth.auth']
@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']
)
redirect_to session[:last_path]
end
end
4 changes: 4 additions & 0 deletions app/helpers/profiles_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

module ProfilesHelper
end
9 changes: 9 additions & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
<%= I18n.t('nav.plan') %></a>
</li>
<% end %>
<li>
<a
href="<%= event_profile_path %>"
class="flex items-center gap-2 h-max box-border m-0 boder-none bg-transparent px-2 py-3 <%= current_path?(event_profile_path) ? 'nav-current' : '' %>"
<%= sanitize current_path?(event_path) ? 'aria-current="page"' : '' %>
>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" width="1em" height="1em" class="" role="img" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" style="color: rgb(112, 109, 101);"><path d="M256 288A144 144 0 1 0 256 0a144 144 0 1 0 0 288zm-94.7 32C72.2 320 0 392.2 0 481.3c0 17 13.8 30.7 30.7 30.7H481.3c17 0 30.7-13.8 30.7-30.7C512 392.2 439.8 320 350.7 320H161.3z"></path></svg>
<%= I18n.t('nav.profile') %></a>
</li>
</ul>
<div class="ml-auto">
<label class="flex items-center justify-start gap-2">
Expand Down
30 changes: 30 additions & 0 deletions app/views/profiles/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<% 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">
<h1 class="text-4xl"><%= @user.profile.name %></h1>
<h2><%= @user.profile.email %></h2>
</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 %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ en:
root: "Top"
schedule: "Schedule"
plan: "My Plans"
profile: "Profile"
info:
create_plan_title: "Create your RubyKaigi Plans"
create_plan_text: "Create your RubyKaigi Plans with RubyKaigi mie.ru kun. Agree to Terms of service and press create button."
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ja:
root: "top"
schedule: "スケジュール"
plan: "視聴予定"
profile: "プロフィール"
info:
create_plan_title: "セッションの視聴予定を作成しませんか?"
create_plan_text: "RubyKaigi mie.ru 君を使って、RubyKaigi2021 Takeoutのセッション視聴予定表を作成しましょう! 利用規約に同意の上、予定の作成ボタンを押してください。"
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
resource :ogp, only: %i[show]
end
end

resource :profile, only: %i[show update]
end

get '*path', controller: 'application', action: 'not_found'
Expand Down
1 change: 1 addition & 0 deletions public/icons/github-mark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/controllers/profiles_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'test_helper'

class ProfilesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

0 comments on commit 520e2d7

Please sign in to comment.