From 520e2d73dbfa8e3ba951c7ef6244239237c687c5 Mon Sep 17 00:00:00 2001 From: kinoppyd Date: Thu, 28 Mar 2024 01:25:07 +0900 Subject: [PATCH] Implements signup with GitHub --- app/controllers/profiles_controller.rb | 7 +++++ app/controllers/sessions_controller.rb | 10 ++++++- app/helpers/profiles_helper.rb | 4 +++ app/views/layouts/_header.html.erb | 9 ++++++ app/views/profiles/show.html.erb | 30 ++++++++++++++++++++ config/locales/en.yml | 1 + config/locales/ja.yml | 1 + config/routes.rb | 2 ++ public/icons/github-mark.svg | 1 + test/controllers/profiles_controller_test.rb | 9 ++++++ 10 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 app/controllers/profiles_controller.rb create mode 100644 app/helpers/profiles_helper.rb create mode 100644 app/views/profiles/show.html.erb create mode 100644 public/icons/github-mark.svg create mode 100644 test/controllers/profiles_controller_test.rb diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb new file mode 100644 index 00000000..8d9b3511 --- /dev/null +++ b/app/controllers/profiles_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class ProfilesController < ApplicationController + include EventRouting + + def show; end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 98578400..194846b0 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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 diff --git a/app/helpers/profiles_helper.rb b/app/helpers/profiles_helper.rb new file mode 100644 index 00000000..9ba602e9 --- /dev/null +++ b/app/helpers/profiles_helper.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +module ProfilesHelper +end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 43bc2363..b736f80e 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -64,6 +64,15 @@ <%= I18n.t('nav.plan') %> <% end %> +
  • + + > + + <%= I18n.t('nav.profile') %> +