From 522f1cfa45ed5bd9df169cc216a10e6954a9dbcb Mon Sep 17 00:00:00 2001 From: yuji91 Date: Fri, 16 Apr 2021 23:39:04 +0900 Subject: [PATCH 01/32] Add login function --- Gemfile | 2 + Gemfile.lock | 23 + app/controllers/application_controller.rb | 8 + app/controllers/posts_controller.rb | 2 +- app/controllers/user_sessions_controller.rb | 21 + app/controllers/users_controller.rb | 24 + app/models/post.rb | 4 + app/models/user.rb | 19 + app/views/layouts/application.html.erb | 7 + app/views/posts/index.html.erb | 6 +- .../shared/_before_login_header.html.erb | 16 + app/views/shared/_flash_message.html.erb | 3 + app/views/shared/_footer.html.erb | 12 + app/views/shared/_header.html.erb | 41 ++ app/views/user_sessions/new.html.erb | 25 + app/views/users/new.html.erb | 34 ++ config/initializers/sorcery.rb | 545 ++++++++++++++++++ config/routes.rb | 5 +- db/migrate/20210417000922_sorcery_core.rb | 15 + .../20210417042717_add_user_id_to_posts.rb | 5 + db/schema.rb | 15 +- spec/models/user_spec.rb | 5 + 22 files changed, 832 insertions(+), 5 deletions(-) create mode 100644 app/controllers/user_sessions_controller.rb create mode 100644 app/controllers/users_controller.rb create mode 100644 app/models/user.rb create mode 100644 app/views/shared/_before_login_header.html.erb create mode 100644 app/views/shared/_flash_message.html.erb create mode 100644 app/views/shared/_footer.html.erb create mode 100644 app/views/shared/_header.html.erb create mode 100644 app/views/user_sessions/new.html.erb create mode 100644 app/views/users/new.html.erb create mode 100644 config/initializers/sorcery.rb create mode 100644 db/migrate/20210417000922_sorcery_core.rb create mode 100644 db/migrate/20210417042717_add_user_id_to_posts.rb create mode 100644 spec/models/user_spec.rb diff --git a/Gemfile b/Gemfile index d8941a0..0bf7cdc 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,8 @@ gem 'turbolinks', '~> 5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false +gem 'sorcery', '0.15.0' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index d1a09ae..ad09eeb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,7 @@ GEM public_suffix (>= 2.0.2, < 5.0) arel (9.0.0) ast (2.4.2) + bcrypt (3.1.16) bindex (0.8.1) bootsnap (1.7.3) msgpack (~> 1.0) @@ -79,11 +80,17 @@ GEM railties (>= 5.0.0) faker (2.17.0) i18n (>= 1.6, < 2) + faraday (1.3.0) + faraday-net_http (~> 1.0) + multipart-post (>= 1.2, < 3) + ruby2_keywords + faraday-net_http (1.0.1) ffi (1.15.0) globalid (0.4.2) activesupport (>= 4.2.0) i18n (1.8.10) concurrent-ruby (~> 1.0) + jwt (2.2.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -99,10 +106,20 @@ GEM mini_portile2 (2.5.0) minitest (5.14.4) msgpack (1.4.2) + multi_json (1.15.0) + multi_xml (0.6.0) + multipart-post (2.1.1) nio4r (2.5.7) nokogiri (1.11.3) mini_portile2 (~> 2.5.0) racc (~> 1.4) + oauth (0.5.5) + 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) parallel (1.20.1) parser (3.0.1.0) ast (~> 2.4.1) @@ -180,6 +197,7 @@ GEM rack (>= 1.1) rubocop (>= 0.90.0, < 2.0) ruby-progressbar (1.11.0) + ruby2_keywords (0.0.4) ruby_dep (1.5.0) rubyzip (2.3.0) sass (3.7.4) @@ -196,6 +214,10 @@ GEM selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) + sorcery (0.15.0) + bcrypt (~> 3.1) + oauth (~> 0.4, >= 0.4.4) + oauth2 (~> 1.0, >= 0.8.0) spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -253,6 +275,7 @@ DEPENDENCIES rubocop-checkstyle_formatter rubocop-rails sass-rails (~> 5.0) + sorcery (= 0.15.0) spring spring-watcher-listen (~> 2.0.0) sqlite3 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d1..ef41854 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,10 @@ class ApplicationController < ActionController::Base + add_flash_types :success, :info, :warning, :danger + before_action :require_login + + private + + def not_authenticated + redirect_to login_path, warning: 'ログインしてください' + end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 2a7d565..a1ef654 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -21,7 +21,7 @@ def edit # POST /posts def create - @post = Post.new(post_params) + @post = current_user.posts.build(post_params) if @post.save redirect_to @post, notice: 'Post was successfully created.' diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb new file mode 100644 index 0000000..4f20d3d --- /dev/null +++ b/app/controllers/user_sessions_controller.rb @@ -0,0 +1,21 @@ +class UserSessionsController < ApplicationController + skip_before_action :require_login, only: %i[new create] + + def new; end + + def create + @user = login(params[:email], params[:password]) + if @user + redirect_back_or_to posts_path, success: 'Login successful.' + else + flash.now[:danger] = 'Login failed.' + render :new + end + end + + def destroy + logout + redirect_to login_path, success: 'Logout successful.' + end +end + diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..6f83537 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,24 @@ +class UsersController < ApplicationController + skip_before_action :require_login, only: %i[new create] + + def new + @user = User.new + end + + def create + @user = User.new(user_params) + if @user.save + redirect_to login_path, success: 'User was successfully created.' + else + flash.now[:danger] = 'User creation failed.' + render :new + end + end + + private + + def user_params + params.require(:user).permit(:email, :password, :password_confirmation, :last_name, :first_name) + end +end + diff --git a/app/models/post.rb b/app/models/post.rb index b2a8b46..b910192 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,2 +1,6 @@ class Post < ApplicationRecord + belongs_to :user + + validates :title, presence: true, length: { maximum: 255 } + validates :content, presence: true, length: { maximum: 65_535 } end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..85b2a90 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,19 @@ +class User < ApplicationRecord + authenticates_with_sorcery! + + has_many :posts, dependent: :destroy + + validates :password, length: { minimum: 3 }, if: -> { new_record? || changes[:crypted_password] } + validates :password, confirmation: true, if: -> { new_record? || changes[:crypted_password] } + validates :password_confirmation, presence: true, if: -> { new_record? || changes[:crypted_password] } + + validates :email, uniqueness: true + validates :email, presence: true + validates :first_name, presence: true, length: { maximum: 255 } + validates :last_name, presence: true, length: { maximum: 255 } + + def mine?(object) + # [注意]ここでは current_user は使用できないため、idで比較する + object.user_id == id + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f662943..7d33891 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,13 @@ + <% if logged_in? %> + <%= render 'shared/header' %> + <% else %> + <%= render 'shared/before_login_header' %> + <% end %> + <%= render 'shared/flash_message' %> <%= yield %> + <%= render 'shared/footer' %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index ad63fbf..4d3add6 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -17,8 +17,10 @@ <%= post.title %> <%= post.content %> <%= link_to 'Show', post %> - <%= link_to 'Edit', edit_post_path(post) %> - <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %> + <% if current_user.mine?(post) %> + <%= link_to 'Edit', edit_post_path(post) %> + <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %> + <% end %> <% end %> diff --git a/app/views/shared/_before_login_header.html.erb b/app/views/shared/_before_login_header.html.erb new file mode 100644 index 0000000..25ccc8f --- /dev/null +++ b/app/views/shared/_before_login_header.html.erb @@ -0,0 +1,16 @@ +
+ +
diff --git a/app/views/shared/_flash_message.html.erb b/app/views/shared/_flash_message.html.erb new file mode 100644 index 0000000..e4717e9 --- /dev/null +++ b/app/views/shared/_flash_message.html.erb @@ -0,0 +1,3 @@ +<% flash.each do |message_type, message| %> +
<%= message %>
+<% end %> diff --git a/app/views/shared/_footer.html.erb b/app/views/shared/_footer.html.erb new file mode 100644 index 0000000..b48f787 --- /dev/null +++ b/app/views/shared/_footer.html.erb @@ -0,0 +1,12 @@ + + diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb new file mode 100644 index 0000000..5e51f18 --- /dev/null +++ b/app/views/shared/_header.html.erb @@ -0,0 +1,41 @@ +
+ +
+ diff --git a/app/views/user_sessions/new.html.erb b/app/views/user_sessions/new.html.erb new file mode 100644 index 0000000..e0e9000 --- /dev/null +++ b/app/views/user_sessions/new.html.erb @@ -0,0 +1,25 @@ +
+
+
+

ログイン

+ <%= form_with url: login_path, local: true do |f| %> +
+ <%= f.label :email %> + <%= f.email_field :email, class: 'form-control' %> +
+
+ <%= f.label :password %> + <%= f.password_field :password, class: 'form-control' %> +
+
+ <%= f.submit 'ログイン', class: 'btn btn-primary' %> +
+ <% end %> +
+ <%= link_to '登録ページへ', new_user_path %> + パスワードをお忘れの方はこちら +
+
+
+
+ diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000..b0b9dd3 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,34 @@ +
+
+
+

ユーザー登録

+ <%= form_with model: @user, local: true do |f| %> +
+ <%= f.label :last_name %> + <%= f.text_field :last_name, class: 'form-control' %> +
+
+ <%= f.label :first_name %> + <%= f.text_field :first_name, class: 'form-control' %> +
+
+ <%= f.label :email %> + <%= f.email_field :email, class: 'form-control' %> +
+
+ <%= f.label :password %> + <%= f.password_field :password, class: 'form-control' %> +
+
+ <%= f.label :password_confirmation %> + <%= f.password_field :password_confirmation, class: 'form-control' %> +
+ <%= f.submit '登録', class: 'btn btn-primary' %> + <% end %> +
+ <%= link_to 'ログインページへ', login_path %> +
+
+
+
+ diff --git a/config/initializers/sorcery.rb b/config/initializers/sorcery.rb new file mode 100644 index 0000000..30ba8da --- /dev/null +++ b/config/initializers/sorcery.rb @@ -0,0 +1,545 @@ +# The first thing you need to configure is which modules you need in your app. +# The default is nothing which will include only core features (password encryption, login/logout). +# +# Available submodules are: :user_activation, :http_basic_auth, :remember_me, +# :reset_password, :session_timeout, :brute_force_protection, :activity_logging, +# :magic_login, :external +Rails.application.config.sorcery.submodules = [] + +# Here you can configure each submodule's features. +Rails.application.config.sorcery.configure do |config| + # -- core -- + # What controller action to call for non-authenticated users. You can also + # override the 'not_authenticated' method of course. + # Default: `:not_authenticated` + # + # config.not_authenticated_action = + + # When a non logged-in user tries to enter a page that requires login, save + # the URL he wants to reach, and send him there after login, using 'redirect_back_or_to'. + # Default: `true` + # + # config.save_return_to_url = + + # Set domain option for cookies; Useful for remember_me submodule. + # Default: `nil` + # + # config.cookie_domain = + + # Allow the remember_me cookie to be set through AJAX + # Default: `true` + # + # config.remember_me_httponly = + + # Set token randomness. (e.g. user activation tokens) + # The length of the result string is about 4/3 of `token_randomness`. + # Default: `15` + # + # config.token_randomness = + + # -- session timeout -- + # How long in seconds to keep the session alive. + # Default: `3600` + # + # config.session_timeout = + + # Use the last action as the beginning of session timeout. + # Default: `false` + # + # config.session_timeout_from_last_action = + + # Invalidate active sessions. Requires an `invalidate_sessions_before` timestamp column + # Default: `false` + # + # config.session_timeout_invalidate_active_sessions_enabled = + + # -- http_basic_auth -- + # What realm to display for which controller name. For example {"My App" => "Application"} + # Default: `{"application" => "Application"}` + # + # config.controller_to_realm_map = + + # -- activity logging -- + # Will register the time of last user login, every login. + # Default: `true` + # + # config.register_login_time = + + # Will register the time of last user logout, every logout. + # Default: `true` + # + # config.register_logout_time = + + # Will register the time of last user action, every action. + # Default: `true` + # + # config.register_last_activity_time = + + # -- external -- + # What providers are supported by this app + # i.e. [:twitter, :facebook, :github, :linkedin, :xing, :google, :liveid, :salesforce, :slack, :line]. + # Default: `[]` + # + # config.external_providers = + + # You can change it by your local ca_file. i.e. '/etc/pki/tls/certs/ca-bundle.crt' + # Path to ca_file. By default use a internal ca-bundle.crt. + # Default: `'path/to/ca_file'` + # + # config.ca_file = + + # Linkedin requires r_emailaddress scope to fetch user's email address. + # You can skip including the email field if you use an intermediary signup form. (using build_from method). + # The r_emailaddress scope is only necessary if you are using the create_from method directly. + # + # config.linkedin.key = "" + # config.linkedin.secret = "" + # config.linkedin.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=linkedin" + # config.linkedin.user_info_mapping = { + # first_name: 'localizedFirstName', + # last_name: 'localizedLastName', + # email: 'emailAddress' + # } + # config.linkedin.scope = "r_liteprofile r_emailaddress" + # + # + # For information about XING API: + # - user info fields go to https://dev.xing.com/docs/get/users/me + # + # config.xing.key = "" + # config.xing.secret = "" + # config.xing.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=xing" + # config.xing.user_info_mapping = {first_name: "first_name", last_name: "last_name"} + # + # + # Twitter will not accept any requests nor redirect uri containing localhost, + # Make sure you use 0.0.0.0:3000 to access your app in development + # + # config.twitter.key = "" + # config.twitter.secret = "" + # config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter" + # config.twitter.user_info_mapping = {:email => "screen_name"} + # + # config.facebook.key = "" + # config.facebook.secret = "" + # config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook" + # config.facebook.user_info_path = "me?fields=email" + # config.facebook.user_info_mapping = {:email => "email"} + # config.facebook.access_permissions = ["email"] + # config.facebook.display = "page" + # config.facebook.api_version = "v2.3" + # config.facebook.parse = :json + # + # config.instagram.key = "" + # config.instagram.secret = "" + # config.instagram.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=instagram" + # config.instagram.user_info_mapping = {:email => "username"} + # config.instagram.access_permissions = ["basic", "public_content", "follower_list", "comments", "relationships", "likes"] + # + # config.github.key = "" + # config.github.secret = "" + # config.github.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=github" + # config.github.user_info_mapping = {:email => "name"} + # config.github.scope = "" + # + # config.paypal.key = "" + # config.paypal.secret = "" + # config.paypal.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=paypal" + # config.paypal.user_info_mapping = {:email => "email"} + # + # config.wechat.key = "" + # config.wechat.secret = "" + # config.wechat.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=wechat" + # + # For Auth0, site is required and should match the domain provided by Auth0. + # + # config.auth0.key = "" + # config.auth0.secret = "" + # config.auth0.callback_url = "https://0.0.0.0:3000/oauth/callback?provider=auth0" + # config.auth0.site = "https://example.auth0.com" + # + # config.google.key = "" + # config.google.secret = "" + # config.google.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=google" + # config.google.user_info_mapping = {:email => "email", :username => "name"} + # config.google.scope = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile" + # + # For Microsoft Graph, the key will be your App ID, and the secret will be your app password/public key. + # The callback URL "can't contain a query string or invalid special characters" + # See: https://docs.microsoft.com/en-us/azure/active-directory/active-directory-v2-limitations#restrictions-on-redirect-uris + # More information at https://graph.microsoft.io/en-us/docs + # + # config.microsoft.key = "" + # config.microsoft.secret = "" + # config.microsoft.callback_url = "http://0.0.0.0:3000/oauth/callback/microsoft" + # config.microsoft.user_info_mapping = {:email => "userPrincipalName", :username => "displayName"} + # config.microsoft.scope = "openid email https://graph.microsoft.com/User.Read" + # + # config.vk.key = "" + # config.vk.secret = "" + # config.vk.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=vk" + # config.vk.user_info_mapping = {:login => "domain", :name => "full_name"} + # config.vk.api_version = "5.71" + # + # config.slack.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=slack" + # config.slack.key = '' + # config.slack.secret = '' + # config.slack.user_info_mapping = {email: 'email'} + # + # To use liveid in development mode you have to replace mydomain.com with + # a valid domain even in development. To use a valid domain in development + # simply add your domain in your /etc/hosts file in front of 127.0.0.1 + # + # config.liveid.key = "" + # config.liveid.secret = "" + # config.liveid.callback_url = "http://mydomain.com:3000/oauth/callback?provider=liveid" + # config.liveid.user_info_mapping = {:username => "name"} + + # For information about JIRA API: + # https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+OAuth+authentication + # To obtain the consumer key and the public key you can use the jira-ruby gem https://github.com/sumoheavy/jira-ruby + # or run openssl req -x509 -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem to obtain the public key + # Make sure you have configured the application link properly + + # config.jira.key = "1234567" + # config.jira.secret = "jiraTest" + # config.jira.site = "http://localhost:2990/jira/plugins/servlet/oauth" + # config.jira.signature_method = "RSA-SHA1" + # config.jira.private_key_file = "rsakey.pem" + + # For information about Salesforce API: + # https://developer.salesforce.com/signup & + # https://www.salesforce.com/us/developer/docs/api_rest/ + # Salesforce callback_url must be https. You can run the following to generate self-signed ssl cert: + # openssl req -new -newkey rsa:2048 -sha1 -days 365 -nodes -x509 -keyout server.key -out server.crt + # Make sure you have configured the application link properly + # config.salesforce.key = '123123' + # config.salesforce.secret = 'acb123' + # config.salesforce.callback_url = "https://127.0.0.1:9292/oauth/callback?provider=salesforce" + # config.salesforce.scope = "full" + # config.salesforce.user_info_mapping = {:email => "email"} + + # config.line.key = "" + # config.line.secret = "" + # config.line.callback_url = "http://mydomain.com:3000/oauth/callback?provider=line" + + # For infromation about Discord API + # https://discordapp.com/developers/docs/topics/oauth2 + # config.discord.key = "xxxxxx" + # config.discord.secret = "xxxxxx" + # config.discord.callback_url = "http://localhost:3000/oauth/callback?provider=discord" + # config.discord.scope = "email guilds" + # --- user config --- + config.user_config do |user| + # -- core -- + # Specify username attributes, for example: [:username, :email]. + # Default: `[:email]` + # + # user.username_attribute_names = + + # Change *virtual* password attribute, the one which is used until an encrypted one is generated. + # Default: `:password` + # + # user.password_attribute_name = + + # Downcase the username before trying to authenticate, default is false + # Default: `false` + # + # user.downcase_username_before_authenticating = + + # Change default email attribute. + # Default: `:email` + # + # user.email_attribute_name = + + # Change default crypted_password attribute. + # Default: `:crypted_password` + # + # user.crypted_password_attribute_name = + + # What pattern to use to join the password with the salt + # Default: `""` + # + # user.salt_join_token = + + # Change default salt attribute. + # Default: `:salt` + # + # user.salt_attribute_name = + + # How many times to apply encryption to the password. + # Default: 1 in test env, `nil` otherwise + # + user.stretches = 1 if Rails.env.test? + + # Encryption key used to encrypt reversible encryptions such as AES256. + # WARNING: If used for users' passwords, changing this key will leave passwords undecryptable! + # Default: `nil` + # + # user.encryption_key = + + # Use an external encryption class. + # Default: `nil` + # + # user.custom_encryption_provider = + + # Encryption algorithm name. See 'encryption_algorithm=' for available options. + # Default: `:bcrypt` + # + # user.encryption_algorithm = + + # Make this configuration inheritable for subclasses. Useful for ActiveRecord's STI. + # Default: `false` + # + # user.subclasses_inherit_config = + + # -- remember_me -- + # How long in seconds the session length will be + # Default: `60 * 60 * 24 * 7` + # + # user.remember_me_for = + + # When true, sorcery will persist a single remember me token for all + # logins/logouts (to support remembering on multiple browsers simultaneously). + # Default: false + # + # user.remember_me_token_persist_globally = + + # -- user_activation -- + # The attribute name to hold activation state (active/pending). + # Default: `:activation_state` + # + # user.activation_state_attribute_name = + + # The attribute name to hold activation code (sent by email). + # Default: `:activation_token` + # + # user.activation_token_attribute_name = + + # The attribute name to hold activation code expiration date. + # Default: `:activation_token_expires_at` + # + # user.activation_token_expires_at_attribute_name = + + # How many seconds before the activation code expires. nil for never expires. + # Default: `nil` + # + # user.activation_token_expiration_period = + + # REQUIRED: + # User activation mailer class. + # Default: `nil` + # + # user.user_activation_mailer = + + # When true, sorcery will not automatically + # send the activation details email, and allow you to + # manually handle how and when the email is sent. + # Default: `false` + # + # user.activation_mailer_disabled = + + # Method to send email related + # options: `:deliver_later`, `:deliver_now`, `:deliver` + # Default: :deliver (Rails version < 4.2) or :deliver_now (Rails version 4.2+) + # + # user.email_delivery_method = + + # Activation needed email method on your mailer class. + # Default: `:activation_needed_email` + # + # user.activation_needed_email_method_name = + + # Activation success email method on your mailer class. + # Default: `:activation_success_email` + # + # user.activation_success_email_method_name = + + # Do you want to prevent users who did not activate by email from logging in? + # Default: `true` + # + # user.prevent_non_active_users_to_login = + + # -- reset_password -- + # Password reset token attribute name. + # Default: `:reset_password_token` + # + # user.reset_password_token_attribute_name = + + # Password token expiry attribute name. + # Default: `:reset_password_token_expires_at` + # + # user.reset_password_token_expires_at_attribute_name = + + # When was password reset email sent. Used for hammering protection. + # Default: `:reset_password_email_sent_at` + # + # user.reset_password_email_sent_at_attribute_name = + + # REQUIRED: + # Password reset mailer class. + # Default: `nil` + # + # user.reset_password_mailer = + + # Reset password email method on your mailer class. + # Default: `:reset_password_email` + # + # user.reset_password_email_method_name = + + # When true, sorcery will not automatically + # send the password reset details email, and allow you to + # manually handle how and when the email is sent + # Default: `false` + # + # user.reset_password_mailer_disabled = + + # How many seconds before the reset request expires. nil for never expires. + # Default: `nil` + # + # user.reset_password_expiration_period = + + # Hammering protection: how long in seconds to wait before allowing another email to be sent. + # Default: `5 * 60` + # + # user.reset_password_time_between_emails = + + # Access counter to a reset password page attribute name + # Default: `:access_count_to_reset_password_page` + # + # user.reset_password_page_access_count_attribute_name = + + # -- magic_login -- + # Magic login code attribute name. + # Default: `:magic_login_token` + # + # user.magic_login_token_attribute_name = + + # Magic login expiry attribute name. + # Default: `:magic_login_token_expires_at` + # + # user.magic_login_token_expires_at_attribute_name = + + # When was magic login email sent — used for hammering protection. + # Default: `:magic_login_email_sent_at` + # + # user.magic_login_email_sent_at_attribute_name = + + # REQUIRED: + # Magic login mailer class. + # Default: `nil` + # + # user.magic_login_mailer_class = + + # Magic login email method on your mailer class. + # Default: `:magic_login_email` + # + # user.magic_login_email_method_name = + + # When true, sorcery will not automatically + # send magic login details email, and allow you to + # manually handle how and when the email is sent + # Default: `true` + # + # user.magic_login_mailer_disabled = + + # How many seconds before the request expires. nil for never expires. + # Default: `nil` + # + # user.magic_login_expiration_period = + + # Hammering protection: how long in seconds to wait before allowing another email to be sent. + # Default: `5 * 60` + # + # user.magic_login_time_between_emails = + + # -- brute_force_protection -- + # Failed logins attribute name. + # Default: `:failed_logins_count` + # + # user.failed_logins_count_attribute_name = + + # This field indicates whether user is banned and when it will be active again. + # Default: `:lock_expires_at` + # + # user.lock_expires_at_attribute_name = + + # How many failed logins are allowed. + # Default: `50` + # + # user.consecutive_login_retries_amount_limit = + + # How long the user should be banned, in seconds. 0 for permanent. + # Default: `60 * 60` + # + # user.login_lock_time_period = + + # Unlock token attribute name + # Default: `:unlock_token` + # + # user.unlock_token_attribute_name = + + # Unlock token mailer method + # Default: `:send_unlock_token_email` + # + # user.unlock_token_email_method_name = + + # When true, sorcery will not automatically + # send email with the unlock token + # Default: `false` + # + # user.unlock_token_mailer_disabled = true + + # REQUIRED: + # Unlock token mailer class. + # Default: `nil` + # + # user.unlock_token_mailer = + + # -- activity logging -- + # Last login attribute name. + # Default: `:last_login_at` + # + # user.last_login_at_attribute_name = + + # Last logout attribute name. + # Default: `:last_logout_at` + # + # user.last_logout_at_attribute_name = + + # Last activity attribute name. + # Default: `:last_activity_at` + # + # user.last_activity_at_attribute_name = + + # How long since user's last activity will they be considered logged out? + # Default: `10 * 60` + # + # user.activity_timeout = + + # -- external -- + # Class which holds the various external provider data for this user. + # Default: `nil` + # + # user.authentications_class = + + # User's identifier in the `authentications` class. + # Default: `:user_id` + # + # user.authentications_user_id_attribute_name = + + # Provider's identifier in the `authentications` class. + # Default: `:provider` + # + # user.provider_attribute_name = + + # User's external unique identifier in the `authentications` class. + # Default: `:uid` + # + # user.provider_uid_attribute_name = + end + + # This line must come after the 'user config' block. + # Define which model authenticates with sorcery. + config.user_class = "User" +end diff --git a/config/routes.rb b/config/routes.rb index abba78d..c45ee81 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Rails.application.routes.draw do + get 'login', to: 'user_sessions#new' + post 'login', to: 'user_sessions#create' + delete 'logout', to: 'user_sessions#destroy' resources :posts - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + resources :users, only: %i[new create] end diff --git a/db/migrate/20210417000922_sorcery_core.rb b/db/migrate/20210417000922_sorcery_core.rb new file mode 100644 index 0000000..a73966f --- /dev/null +++ b/db/migrate/20210417000922_sorcery_core.rb @@ -0,0 +1,15 @@ +class SorceryCore < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.string :email, null: false + t.string :crypted_password + t.string :salt + t.string :first_name, null: false + t.string :last_name, null: false + + t.timestamps null: false + end + + add_index :users, :email, unique: true + end +end diff --git a/db/migrate/20210417042717_add_user_id_to_posts.rb b/db/migrate/20210417042717_add_user_id_to_posts.rb new file mode 100644 index 0000000..fdb5564 --- /dev/null +++ b/db/migrate/20210417042717_add_user_id_to_posts.rb @@ -0,0 +1,5 @@ +class AddUserIdToPosts < ActiveRecord::Migration[5.2] + def change + add_reference :posts, :user, foreign_key: true, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 533bc0b..8f95ac4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,13 +10,26 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_04_16_062704) do +ActiveRecord::Schema.define(version: 2021_04_17_042717) do create_table "posts", force: :cascade do |t| t.string "title" t.text "content" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "user_id", null: false + t.index ["user_id"], name: "index_posts_on_user_id" + end + + create_table "users", force: :cascade do |t| + t.string "email", null: false + t.string "crypted_password" + t.string "salt" + t.string "first_name", null: false + t.string "last_name", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_users_on_email", unique: true end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..47a31bb --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 213d5a33959efc86958696f9e7abe86a32551166 Mon Sep 17 00:00:00 2001 From: yuji91 Date: Fri, 16 Apr 2021 23:40:35 +0900 Subject: [PATCH 02/32] Add assets --- Gemfile | 4 +++- Gemfile.lock | 24 ++++++++++++++++++++++++ app/assets/images/sample.jpg | Bin 0 -> 5787 bytes app/assets/javascripts/application.js | 3 +++ app/assets/stylesheets/application.css | 15 --------------- app/assets/stylesheets/application.scss | 4 ++++ app/assets/stylesheets/top.scss | 21 +++++++++++++++++++++ 7 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 app/assets/images/sample.jpg delete mode 100644 app/assets/stylesheets/application.css create mode 100644 app/assets/stylesheets/application.scss create mode 100644 app/assets/stylesheets/top.scss diff --git a/Gemfile b/Gemfile index 0bf7cdc..4c89835 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,9 @@ gem 'turbolinks', '~> 5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false - +gem 'bootstrap', '~> 4.3.1' +gem 'font-awesome-sass', '~> 5.11.2' +gem 'jquery-rails' gem 'sorcery', '0.15.0' group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index ad09eeb..5a3e19b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,10 +46,16 @@ GEM public_suffix (>= 2.0.2, < 5.0) arel (9.0.0) ast (2.4.2) + autoprefixer-rails (10.2.0.0) + execjs bcrypt (3.1.16) bindex (0.8.1) bootsnap (1.7.3) msgpack (~> 1.0) + bootstrap (4.3.1) + autoprefixer-rails (>= 9.1.0) + popper_js (>= 1.14.3, < 2) + sassc-rails (>= 2.0.0) builder (3.2.4) byebug (11.1.3) capybara (3.35.3) @@ -86,10 +92,16 @@ GEM ruby2_keywords faraday-net_http (1.0.1) ffi (1.15.0) + font-awesome-sass (5.11.2) + sassc (>= 1.11) globalid (0.4.2) activesupport (>= 4.2.0) i18n (1.8.10) concurrent-ruby (~> 1.0) + jquery-rails (4.4.0) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) jwt (2.2.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) @@ -123,6 +135,7 @@ GEM parallel (1.20.1) parser (3.0.1.0) ast (~> 2.4.1) + popper_js (1.16.0) public_suffix (4.0.6) puma (3.12.6) racc (1.5.2) @@ -211,6 +224,14 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) @@ -261,11 +282,14 @@ PLATFORMS DEPENDENCIES bootsnap (>= 1.1.0) + bootstrap (~> 4.3.1) byebug capybara coffee-rails (~> 4.2) factory_bot_rails faker + font-awesome-sass (~> 5.11.2) + jquery-rails listen (>= 3.0.5, < 3.2) puma (~> 3.11) rails (~> 5.2.5) diff --git a/app/assets/images/sample.jpg b/app/assets/images/sample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1e9eac8b7993381d1e94fde5837da7cfa6d73c2a GIT binary patch literal 5787 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 hZSFB6$__g`<-Colw7n@hcSz5_ Date: Fri, 16 Apr 2021 23:46:43 +0900 Subject: [PATCH 03/32] Fix show page --- app/views/posts/show.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index e03ead5..568ed53 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -9,6 +9,7 @@ Content: <%= @post.content %>

- -<%= link_to 'Edit', edit_post_path(@post) %> | +<% if current_user.mine?(@post) %> + <%= link_to 'Edit', edit_post_path(@post) %> | +<% end %> <%= link_to 'Back', posts_path %> From 9d99a61af6adb67e7bab0d6d5942a337dfafee89 Mon Sep 17 00:00:00 2001 From: yuji91 Date: Thu, 22 Apr 2021 19:50:29 +0900 Subject: [PATCH 04/32] =?UTF-8?q?Fix:=20bootstrap=204.5.0=E3=82=92?= =?UTF-8?q?=E6=8C=87=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 4c89835..0038869 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,7 @@ gem 'turbolinks', '~> 5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false -gem 'bootstrap', '~> 4.3.1' +gem 'bootstrap', '~> 4.5.0' gem 'font-awesome-sass', '~> 5.11.2' gem 'jquery-rails' gem 'sorcery', '0.15.0' diff --git a/Gemfile.lock b/Gemfile.lock index 5a3e19b..a0484e5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,13 +46,13 @@ GEM public_suffix (>= 2.0.2, < 5.0) arel (9.0.0) ast (2.4.2) - autoprefixer-rails (10.2.0.0) + autoprefixer-rails (10.2.4.0) execjs bcrypt (3.1.16) bindex (0.8.1) bootsnap (1.7.3) msgpack (~> 1.0) - bootstrap (4.3.1) + bootstrap (4.5.3) autoprefixer-rails (>= 9.1.0) popper_js (>= 1.14.3, < 2) sassc-rails (>= 2.0.0) @@ -282,7 +282,7 @@ PLATFORMS DEPENDENCIES bootsnap (>= 1.1.0) - bootstrap (~> 4.3.1) + bootstrap (~> 4.5.0) byebug capybara coffee-rails (~> 4.2) From 71ad84cb93562c29b639422b169e7212cfa93e30 Mon Sep 17 00:00:00 2001 From: yuji91 Date: Thu, 22 Apr 2021 19:53:38 +0900 Subject: [PATCH 05/32] =?UTF-8?q?Fix:=20=E8=AA=AC=E6=98=8E=E3=81=AE?= =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 85b2a90..79e4605 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,7 +13,8 @@ class User < ApplicationRecord validates :last_name, presence: true, length: { maximum: 255 } def mine?(object) - # [注意]ここでは current_user は使用できないため、idで比較する + # 呼び出し元のオブジェクトのIDを示す self.id を省略した記法。 + # @user.mine?(object)のように利用すると、object.user_id と @user.id を比較する。 object.user_id == id end end From deb4907afc2e661a3599bc807f719669af38f46e Mon Sep 17 00:00:00 2001 From: yuji91 Date: Thu, 22 Apr 2021 23:39:44 +0900 Subject: [PATCH 06/32] Fix flash message --- app/controllers/posts_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index a1ef654..5297873 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -24,7 +24,7 @@ def create @post = current_user.posts.build(post_params) if @post.save - redirect_to @post, notice: 'Post was successfully created.' + redirect_to @post, success: 'Post was successfully created.' else render :new end @@ -33,7 +33,7 @@ def create # PATCH/PUT /posts/1 def update if @post.update(post_params) - redirect_to @post, notice: 'Post was successfully updated.' + redirect_to @post, success: 'Post was successfully updated.' else render :edit end @@ -42,7 +42,7 @@ def update # DELETE /posts/1 def destroy @post.destroy - redirect_to posts_url, notice: 'Post was successfully destroyed.' + redirect_to posts_url, success: 'Post was successfully destroyed.' end private From 0e9532fdb1bdc131f0f02c9fb82bda0ae082b07f Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Thu, 22 Apr 2021 23:45:02 +0900 Subject: [PATCH 07/32] Update Gemfile --- Gemfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index 6886d84..69a1e99 100644 --- a/Gemfile +++ b/Gemfile @@ -35,10 +35,6 @@ gem 'turbolinks', '~> 5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false -gem 'bootstrap', '~> 4.5.0' -gem 'font-awesome-sass', '~> 5.11.2' -gem 'jquery-rails' -gem 'sorcery', '0.15.0' gem 'bootstrap', '~> 4.5.0' gem 'font-awesome-sass', '~> 5.11.2' From a83c7af974d1f4a909c08282be7189d7ccfe834b Mon Sep 17 00:00:00 2001 From: yuji91 Date: Fri, 23 Apr 2021 15:44:50 +0900 Subject: [PATCH 08/32] Delete useless example --- spec/models/user_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 47a31bb..ab0da92 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,4 @@ require 'rails_helper' RSpec.describe User, type: :model do - pending "add some examples to (or delete) #{__FILE__}" end From 488551d5051eae5cc2714e34f0e7a71a29754b62 Mon Sep 17 00:00:00 2001 From: yuji91 Date: Fri, 7 May 2021 16:08:44 +0900 Subject: [PATCH 09/32] rubocop -a --- app/controllers/application_controller.rb | 4 ++-- app/controllers/user_sessions_controller.rb | 1 - app/controllers/users_controller.rb | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef41854..41c7b7b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,9 @@ class ApplicationController < ActionController::Base add_flash_types :success, :info, :warning, :danger before_action :require_login - + private - + def not_authenticated redirect_to login_path, warning: 'ログインしてください' end diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb index 4f20d3d..025ae44 100644 --- a/app/controllers/user_sessions_controller.rb +++ b/app/controllers/user_sessions_controller.rb @@ -18,4 +18,3 @@ def destroy redirect_to login_path, success: 'Logout successful.' end end - diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6f83537..c8b9781 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,4 +21,3 @@ def user_params params.require(:user).permit(:email, :password, :password_confirmation, :last_name, :first_name) end end - From 3a89f7fa7ef4a6046cc2bfe244e1a79fc7b04bc1 Mon Sep 17 00:00:00 2001 From: yuji91 Date: Fri, 27 Aug 2021 18:21:56 +0900 Subject: [PATCH 10/32] bundle update ffi --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4d91a41..d6bd9a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,7 +96,7 @@ GEM faraday-excon (1.1.0) faraday-net_http (1.0.1) faraday-net_http_persistent (1.1.0) - ffi (1.15.0) + ffi (1.15.3) font-awesome-sass (5.11.2) sassc (>= 1.11) globalid (0.4.2) From 9886354f95fb749056950f780bf96080d687fce5 Mon Sep 17 00:00:00 2001 From: kenchasonakai Date: Tue, 5 Oct 2021 22:45:20 +0900 Subject: [PATCH 11/32] fix: ignore vendor/ --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 81452db..72db1b7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ # Ignore bundler config. /.bundle +# Ignore vendor +/vendor + # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal From 76be2bd0fe446eadc3fd378790b375988ffaf1ee Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Wed, 6 Oct 2021 12:18:22 +0900 Subject: [PATCH 12/32] =?UTF-8?q?Add:=20=E3=82=B3=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=A3=9C=E8=B6=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 72db1b7..507d5a2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ # Ignore bundler config. /.bundle -# Ignore vendor +# Ignore vendor for CodeCommit Build /vendor # Ignore the default SQLite database. From 97ae43a2df96500a585c0bb7c65f0514b9f8b727 Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Tue, 15 Feb 2022 14:52:06 +0900 Subject: [PATCH 13/32] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 507d5a2..bbf636f 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +# Ignore vendor +/vendor From cb544886795f8b9202ea2886cac3769dbae98e6e Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Tue, 15 Feb 2022 15:13:13 +0900 Subject: [PATCH 14/32] Update .gitignore --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index bbf636f..24d519b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,6 @@ # Ignore bundler config. /.bundle -# Ignore vendor for CodeCommit Build -/vendor - # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal From a9791fc68fea4930b60a943c5fb947b844796cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=8B=E3=81=84=E3=81=B2=E3=81=B3=E3=81=8D?= <67856090+kenchasonakai@users.noreply.github.com> Date: Mon, 21 Feb 2022 14:07:21 +0900 Subject: [PATCH 15/32] Update .rubocop.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ローカル環境でもrubocop-railsを読み込むように修正 --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 51b6561..31b59a4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,7 @@ # This file overrides https://github.com/bbatsov/rubocop/blob/master/config/default.yml + +require: + - rubocop-rails AllCops: NewCops: enable From 880044d06da6410a27d1a96b4c66b629e458e672 Mon Sep 17 00:00:00 2001 From: yuji91 Date: Mon, 21 Feb 2022 19:42:37 +0900 Subject: [PATCH 16/32] =?UTF-8?q?Modify:=20sassc=E3=82=922.1.0=E3=81=AB?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=81=97=E3=81=A6bundle=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 69a1e99..95fd0a8 100644 --- a/Gemfile +++ b/Gemfile @@ -38,6 +38,7 @@ gem 'bootsnap', '>= 1.1.0', require: false gem 'bootstrap', '~> 4.5.0' gem 'font-awesome-sass', '~> 5.11.2' +gem 'sassc', '2.1.0' gem 'jquery-rails' gem 'sorcery', '0.15.0' diff --git a/Gemfile.lock b/Gemfile.lock index d6bd9a2..af07f90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,7 +96,7 @@ GEM faraday-excon (1.1.0) faraday-net_http (1.0.1) faraday-net_http_persistent (1.1.0) - ffi (1.15.3) + ffi (1.15.5) font-awesome-sass (5.11.2) sassc (>= 1.11) globalid (0.4.2) @@ -240,7 +240,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.4.0) + sassc (2.1.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -320,6 +320,7 @@ DEPENDENCIES rubocop-checkstyle_formatter rubocop-rails sass-rails (~> 5.0) + sassc (= 2.1.0) sorcery (= 0.15.0) spring spring-watcher-listen (~> 2.0.0) From d09b852b9bfb2b3610cccd02bfaa14347a58adeb Mon Sep 17 00:00:00 2001 From: yuji91 Date: Thu, 24 Feb 2022 16:03:21 +0900 Subject: [PATCH 17/32] Add node-version --- .node-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .node-version diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..fc2cbe5 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +15.14.0 From 44de1b4ce5517b72edb230300214c1ce63ad690c Mon Sep 17 00:00:00 2001 From: yuji91 Date: Thu, 24 Feb 2022 16:14:37 +0900 Subject: [PATCH 18/32] Disable turbolinks --- Gemfile | 2 -- Gemfile.lock | 4 ---- app/assets/javascripts/application.js | 1 - app/views/layouts/application.html.erb | 4 ++-- 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 95fd0a8..0ce805b 100644 --- a/Gemfile +++ b/Gemfile @@ -18,8 +18,6 @@ gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' -# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks -gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder # gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production diff --git a/Gemfile.lock b/Gemfile.lock index af07f90..de0aa65 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -270,9 +270,6 @@ GEM thor (1.1.0) thread_safe (0.3.6) tilt (2.0.10) - turbolinks (5.2.1) - turbolinks-source (~> 5.2) - turbolinks-source (5.2.0) tzinfo (1.2.9) thread_safe (~> 0.1) uglifier (4.2.0) @@ -325,7 +322,6 @@ DEPENDENCIES spring spring-watcher-listen (~> 2.0.0) sqlite3 - turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index bfbf451..3ebdd26 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,5 +15,4 @@ //= require bootstrap-sprockets //= require rails-ujs //= require activestorage -//= require turbolinks //= require_tree . diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e47832c..9bd9d1e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,8 +5,8 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= stylesheet_link_tag 'application', media: 'all' %> + <%= javascript_include_tag 'application' %> From b49f53b68e8f926b581044aa0be8e3b724a930e3 Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Mon, 14 Mar 2022 15:32:18 +0900 Subject: [PATCH 19/32] =?UTF-8?q?Add:=20sassc=E3=81=AE=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AB=E6=89=8B=E9=A0=86=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0f10412..f0180e7 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,7 @@ - Ruby 2.6.6 を設定 - プロジェクトで利用するgemをインストール + - `bundle config set path 'vendor/bundle'` + - `bundle config build.sassc -- --disable-march-tune-native` + - `bundle install` - データベース、テーブルを作成 From a5fda36c435856b1ef540525b6383b215fa16c0f Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Mon, 14 Mar 2022 18:14:33 +0900 Subject: [PATCH 20/32] =?UTF-8?q?Modify:=20local=20app=E3=81=AB=E3=81=AE?= =?UTF-8?q?=E3=81=BF=E8=A8=AD=E5=AE=9A=E3=82=92=E5=8F=8D=E6=98=A0=E3=81=95?= =?UTF-8?q?=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f0180e7..1b184a2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - Ruby 2.6.6 を設定 - プロジェクトで利用するgemをインストール - - `bundle config set path 'vendor/bundle'` - - `bundle config build.sassc -- --disable-march-tune-native` + - `bundle config --local set path 'vendor/bundle'` + - `bundle config --local build.sassc -- --disable-march-tune-native` - `bundle install` - データベース、テーブルを作成 From be59b3f78e83a94b0321e5aeda4ced3b50d7b35e Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Mon, 14 Mar 2022 18:45:40 +0900 Subject: [PATCH 21/32] =?UTF-8?q?Fix:=20local=E3=82=AA=E3=83=97=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=81=AE=E8=A8=98=E8=BC=89=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b184a2..8c21865 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - Ruby 2.6.6 を設定 - プロジェクトで利用するgemをインストール - - `bundle config --local set path 'vendor/bundle'` + - `bundle config set --local path 'vendor/bundle'` - `bundle config --local build.sassc -- --disable-march-tune-native` - `bundle install` - データベース、テーブルを作成 From f19ae96b63b0527e7a8b6171d8acf02d2cf40ad1 Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Mon, 14 Mar 2022 19:12:49 +0900 Subject: [PATCH 22/32] =?UTF-8?q?Fix:=20=E8=A8=98=E6=B3=95=E3=82=92?= =?UTF-8?q?=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c21865..b2fb251 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - Ruby 2.6.6 を設定 - プロジェクトで利用するgemをインストール - - `bundle config set --local path 'vendor/bundle'` + - `bundle config --local path 'vendor/bundle'` - `bundle config --local build.sassc -- --disable-march-tune-native` - `bundle install` - データベース、テーブルを作成 From 067ce7699d1a009c8b2bda88c296ac4b05eb757d Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Fri, 18 Mar 2022 19:00:59 +0900 Subject: [PATCH 23/32] Modify: Convert jp to en --- app/views/shared/_header.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index c9857c4..826240e 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -13,13 +13,13 @@ From 7b37f1bb264e3d8182d02c9137c4db90ce6eea7b Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Fri, 18 Mar 2022 19:03:08 +0900 Subject: [PATCH 24/32] Modify: Convert jp to en --- app/views/shared/_before_login_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/_before_login_header.html.erb b/app/views/shared/_before_login_header.html.erb index 25ccc8f..175de25 100644 --- a/app/views/shared/_before_login_header.html.erb +++ b/app/views/shared/_before_login_header.html.erb @@ -8,7 +8,7 @@ From 9811c8d62658172f519f9cbeca2481daf1464bab Mon Sep 17 00:00:00 2001 From: YUJI ITO Date: Fri, 18 Mar 2022 19:33:20 +0900 Subject: [PATCH 25/32] =?UTF-8?q?Fix:=20scaffold=E3=81=A7generate=E3=81=97?= =?UTF-8?q?=E3=81=9FView=E3=81=AEh1=E3=82=BF=E3=82=B0=E3=81=8C=E5=85=88?= =?UTF-8?q?=E9=A0=AD=E5=A4=A7=E6=96=87=E5=AD=97=E3=81=AA=E3=81=AE=E3=81=A7?= =?UTF-8?q?link=E3=82=82=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shared/_header.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 826240e..5b05b48 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -13,13 +13,13 @@ From 25cdcba2d01847949b3deeb1c86e0c9e92b04c16 Mon Sep 17 00:00:00 2001 From: kenchaso Date: Thu, 17 Aug 2023 18:56:56 +0900 Subject: [PATCH 32/32] =?UTF-8?q?spec=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/spec_helper.rb | 1 + spec/system/posts_spec.rb | 4 ++-- spec/system/user_sessions_spec.rb | 32 +++++++++++++++---------------- spec/system/users_spec.rb | 32 +++++++++++++++---------------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d10f957..86edd1b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,7 @@ # it. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require 'capybara/rspec' RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest diff --git a/spec/system/posts_spec.rb b/spec/system/posts_spec.rb index 818971c..91ca0a9 100644 --- a/spec/system/posts_spec.rb +++ b/spec/system/posts_spec.rb @@ -18,12 +18,12 @@ expect(page).to have_css("label[for='password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' # ログイン用ボタンの存在確認 - expect(page).to have_button('ログイン'), 'ログイン用のボタンが表示されていることを確認してください' + expect(page).to have_button('Login'), 'ログイン用のボタンが表示されていることを確認してください' # ユーザーログイン処理 fill_in 'Email', with: user.email fill_in 'Password', with: 'password' - click_button 'ログイン' + click_button 'Login' end it '4-1:自分の投稿を編集することができる' do diff --git a/spec/system/user_sessions_spec.rb b/spec/system/user_sessions_spec.rb index 584c043..107f3b2 100644 --- a/spec/system/user_sessions_spec.rb +++ b/spec/system/user_sessions_spec.rb @@ -19,12 +19,12 @@ expect(page).to have_css("label[for='password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' # ログイン用ボタンの存在確認 - expect(page).to have_button('ログイン'), 'ログイン用のボタンが表示されていることを確認してください' + expect(page).to have_button('Login'), 'ログイン用のボタンが表示されていることを確認してください' # ユーザーログイン処理 fill_in 'Email', with: user.email fill_in 'Password', with: 'password' - click_button 'ログイン' + click_button 'Login' # 処理結果の確認 expect(current_path).not_to eq('/login'), 'ログイン処理が正しく行えるかを確認してください' @@ -47,12 +47,12 @@ expect(page).to have_css("label[for='password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' # ログイン用ボタンの存在確認 - expect(page).to have_button('ログイン'), 'ログイン用のボタンが表示されていることを確認してください' + expect(page).to have_button('Login'), 'ログイン用のボタンが表示されていることを確認してください' # ユーザーログイン処理 fill_in 'Email', with: nil fill_in 'Password', with: nil - click_button 'ログイン' + click_button 'Login' # 処理結果の確認 expect(current_path).not_to eq('/posts'), '入力項目が不足している場合にログインできていないかを確認してください' @@ -75,12 +75,12 @@ expect(page).to have_css("label[for='password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' # ログイン用ボタンの存在確認 - expect(page).to have_button('ログイン'), 'ログイン用のボタンが表示されていることを確認してください' + expect(page).to have_button('Login'), 'ログイン用のボタンが表示されていることを確認してください' # ユーザーログイン処理 fill_in 'Email', with: 'another_user@example.com' fill_in 'Password', with: 'password' - click_button 'ログイン' + click_button 'Login' # 処理結果の確認 expect(current_path).not_to eq('/posts'), '存在しないユーザーでログインできていないかを確認してください' @@ -103,12 +103,12 @@ expect(page).to have_css("label[for='password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' # ログイン用ボタンの存在確認 - expect(page).to have_button('ログイン'), 'ログイン用のボタンが表示されていることを確認してください' + expect(page).to have_button('Login'), 'ログイン用のボタンが表示されていることを確認してください' # ユーザーログイン処理 fill_in 'Email', with: user.email fill_in 'Password', with: 'wrong_password' - click_button 'ログイン' + click_button 'Login' # 処理結果の確認 expect(current_path).not_to eq('/posts'), 'パスワードが間違っている場合にログインできていないかを確認してください' @@ -133,12 +133,12 @@ expect(page).to have_css("label[for='password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' # ログイン用ボタンの存在確認 - expect(page).to have_button('ログイン'), 'ログイン用のボタンが表示されていることを確認してください' + expect(page).to have_button('Login'), 'ログイン用のボタンが表示されていることを確認してください' # ユーザーログイン処理 fill_in 'Email', with: second_user.email fill_in 'Password', with: 'password' - click_button 'ログイン' + click_button 'Login' # 処理結果の確認 expect(current_path).not_to eq('/login'), 'ログイン処理が正しく行えるかを確認してください' @@ -167,23 +167,23 @@ expect(page).to have_css("label[for='password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' # ログイン用ボタンの存在確認 - expect(page).to have_button('ログイン'), 'ログイン用のボタンが表示されていることを確認してください' + expect(page).to have_button('Login'), 'ログイン用のボタンが表示されていることを確認してください' # ユーザーログイン処理 fill_in 'Email', with: user.email fill_in 'Password', with: 'password' - click_button 'ログイン' + click_button 'Login' # ユーザーログアウト処理 find('#header-profile').click # ログアウト用ボタンの存在確認 - expect(page).to have_link('ログアウト'), 'ログアウトのボタンが表示されていることを確認してください' + expect(page).to have_link('Logout'), 'ログアウトのボタンが表示されていることを確認してください' - click_on 'ログアウト' + click_on 'Logout' # 処理結果の確認 - expect(page).to have_button('ログイン'), 'ログアウトができているかを確認してください' + expect(page).to have_button('Login'), 'ログアウトができているかを確認してください' end it '3-2:ログインしていない場合、ユーザーのログアウトリンクが表示されない' do @@ -191,7 +191,7 @@ visit '/login' # 処理結果の確認 - expect(page).not_to have_link('ログアウト'), 'ログインしていない場合でも、ログアウトリンクが表示されています' + expect(page).not_to have_link('Logout'), 'ログインしていない場合でも、ログアウトリンクが表示されています' end end end diff --git a/spec/system/users_spec.rb b/spec/system/users_spec.rb index 0b6e979..01eb89b 100644 --- a/spec/system/users_spec.rb +++ b/spec/system/users_spec.rb @@ -4,8 +4,8 @@ RSpec.describe "Users", type: :system do let(:user) { create(:user) } - describe '確認観点1:ユーザー新規登録' do - it '1-1:ユーザーの新規登録ができる' do + describe '確認観点1:ユーザー新規作成' do + it '1-1:ユーザーの新規作成ができる' do # 確認対象の画面に移動 visit 'users/new' @@ -23,22 +23,22 @@ expect(page).to have_css("label[for='user_password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' expect(page).to have_css("label[for='user_password_confirmation']"), 'Password confirmation というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' - # 登録ボタンの存在確認 - expect(page).to have_button('登録'), '登録ボタンが表示されていることを確認してください' + # ユーザー作成用ボタンの存在確認 + expect(page).to have_button('Create User'), 'ユーザー作成用のボタンが表示されていることを確認してください' - # ユーザー新規登録処理 + # ユーザー新規作成用の処理 expect { fill_in 'Last name', with: 'test01' fill_in 'First name', with: 'test01' fill_in 'Email', with: 'test01@example.com' fill_in 'Password', with: 'password' fill_in 'Password confirmation', with: 'password' - click_on '登録' + click_on 'Create User' }.to change { User.count }.by(1) # 処理結果の確認 expect(current_path).to eq('/login'), 'ユーザー作成後にログイン画面に遷移できていません' end - it '1-2:同じメールアドレスのユーザーは新規登録できない' do + it '1-2:同じメールアドレスのユーザーは新規作成できない' do # テストデータの用意 user = create(:user) # describe使わないので、let!を使わずに記載 @@ -59,21 +59,21 @@ expect(page).to have_css("label[for='user_password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' expect(page).to have_css("label[for='user_password_confirmation']"), 'Password confirmation というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' - # 登録ボタンの存在確認 - expect(page).to have_button('登録'), '登録ボタンが表示されていることを確認してください' + # ユーザー作成用ボタンの存在確認 + expect(page).to have_button('Create User'), 'ユーザー作成用のボタンが表示されていることを確認してください' - # ユーザー新規登録処理 + # ユーザー新規作成用の処理 expect { fill_in 'Last name', with: 'test01' fill_in 'First name', with: 'test01' fill_in 'Email', with: user.email fill_in 'Password', with: 'password' fill_in 'Password confirmation', with: 'password' - click_on '登録' + click_on 'Create User' }.to change { User.count }.by(0) # 処理結果の確認 end - it '1-3:入力項目が不足している場合に新規登録ができない' do + it '1-3:入力項目が不足している場合に新規作成ができない' do # 確認対象の画面に移動 visit 'users/new' @@ -91,17 +91,17 @@ expect(page).to have_css("label[for='user_password']"), 'Password というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' expect(page).to have_css("label[for='user_password_confirmation']"), 'Password confirmation というラベルをクリックすると対応するフィールドにフォーカスすることを確認してください' - # 登録ボタンの存在確認 - expect(page).to have_button('登録'), '登録ボタンが表示されていることを確認してください' + # ユーザー作成用ボタンの存在確認 + expect(page).to have_button('Create User'), 'ユーザー作成用のボタンが表示されていることを確認してください' - # ユーザー新規登録処理 + # ユーザー新規作成用の処理 expect { fill_in 'Last name', with: nil fill_in 'First name', with: nil fill_in 'Email', with: nil fill_in 'Password', with: nil fill_in 'Password confirmation', with: nil - click_on '登録' + click_on 'Create User' }.to change { User.count }.by(0) # 処理結果の確認 end end