[RUBY] [Rails] Function restrictions in devise (login / logout)

Function restrictions in devise (login / logout)

table of contents

  1. I want to use only the login / logout function
  2. About the default function in devise
  3. Limit functionality

1. I want to use only the login / logout function

I was creating an app that can manage reservations. (Users do not need to register as a member) On the admin screen, I decided to use `` `gem'devise'``` to create an authentication function so that it can only be used by authorized users. After completing the devise-related installation and settings, I checked the available functions and noticed that there were many unnecessary functions (user registration / password setting, etc ..). Since the administrator screen is basically used by only two people, only the user information of two people was set when creating the app. (Set by rails console or SQL)

2. About the default function in devise

module function
database_authenticatable Password encryption stored in DB(User registration is not possible without this function)
registerable Sign-up process
recoverable Password reset
rememberable Keep login information in cookie
trackable Save the number of sign-ins, time, and IP address
validatable Email address and password validation

By default, all features except `trackable` are enabled.

app/models/user.rb


class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable :validatable
end

3. Limit functionality

Since the only function used this time is "login / logout", make the following changes. registerable sign-up process(Unnecessary function) recoverable password reset(Unnecessary function)

app/models/user.rb


class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :rememberable, :validatable
end

For confirmation, check the routing with rake routes in the terminal.

    new_user_session GET    /users/sign_in(.:format)  devise/sessions#new
        user_session POST   /users/sign_in(.:format)  devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy

Only the routing used for "login / logout" is available.

[Rails] Session timeout setting in devise

Recommended Posts

[Rails] Function restrictions in devise (login / logout)
[rails] Login screen implementation in devise
Implement simple login function in Rails
Create authentication function in Rails application using devise
[Note] Summary of rails login function using devise ①
Implementation of Ruby on Rails login function (devise edition)
Implement follow function in Rails
Rails application guest login function implemented (devise not used)
Login function implementation with rails
Implement login function in Rails simply by name and password (1)
Implement login function in Rails simply by name and password (2)
Implement login function simply with name and password in Rails (3)
Implement user registration function and corporate registration function separately in Rails devise
[Rails] Session timeout setting in devise
Add a search function in Rails.
[Rails] Unexpected validation error in devise
Implement CSV download function in Rails
[Rails] Implementation of new registration function in wizard format using devise
[Rails] devise
Login function
Authentication function in Play Framework [Access restrictions]
Rails Addition of easy and easy login function
Make a login function with Rails anyway
Implemented follow function in Rails (Ajax communication)
Implementation of Ruby on Rails login function (Session)
Rails access restrictions
Use [Rails] devise Guest user function (for portfolio)
[Rails 6] Ranking function
Posting function implemented by asynchronous communication in Rails
Implement star rating function using Raty in Rails6
[Rails] Give this article to you who looked up in "devise name login"
[Rails] Implementation of retweet function in SNS application
[Rails] Category function
[Rails] Introducing devise
Group_by in Rails
Rails follow function
rails + devise + devise_token_auth
[Rails] Added in devise: username not added to database
How to make a follow function in Rails
Simple notification function in Rails (only when followed)
[Rails] Notification function
[rails devise] How to transition users who are not logged in to the login page
How to implement guest login in 5 minutes in rails portfolio
Implement post search function in Rails application (where method)
[Rails] Return login result in JSON format (for beginners)
[Rails] Implement credit card registration / deletion function in PAY.JP
Introduce devise in Rails to implement user management functionality
Implement user follow function in Rails (I use Ajax) ②
I tried to make a login function in Java
[Ruby on Rails] Post image preview function in refile
I want to define a function in Rails Console
Implement user follow function in Rails (I use Ajax) ①
[Rails] Initial setting of user-created login with devise, devise_token_auth
Rails tutorial (6th edition) Background operation of login function
Model association in Rails
[Rails] devise helper method
Adding columns in Rails
[Rails] Customize devise validation
[Rails] Implement search function
Disable turbolinks in Rails
[Rails] Implemented hashtag function