Install Rails' authentication generator #142

Merged
bustikiller merged 6 commits from authentication into main 2024-11-29 19:44:50 +00:00
16 changed files with 32 additions and 0 deletions
Showing only changes of commit 134bf27955 - Show all commits

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
module ApplicationCable module ApplicationCable
class Connection < ActionCable::Connection::Base class Connection < ActionCable::Connection::Base
identified_by :current_user identified_by :current_user

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
module Authentication module Authentication
extend ActiveSupport::Concern extend ActiveSupport::Concern

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
class PasswordsController < ApplicationController class PasswordsController < ApplicationController
allow_unauthenticated_access allow_unauthenticated_access
before_action :set_user_by_token, only: %i[ edit update ] before_action :set_user_by_token, only: %i[ edit update ]

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
class SessionsController < ApplicationController class SessionsController < ApplicationController
allow_unauthenticated_access only: %i[ new create ] allow_unauthenticated_access only: %i[ new create ]
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." } rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." }

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
class PasswordsMailer < ApplicationMailer class PasswordsMailer < ApplicationMailer
def reset(user) def reset(user)
@user = user @user = user

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
class Current < ActiveSupport::CurrentAttributes class Current < ActiveSupport::CurrentAttributes
attribute :session attribute :session
delegate :user, to: :session, allow_nil: true delegate :user, to: :session, allow_nil: true

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information
# #
# Table name: sessions # Table name: sessions

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information
# #
# Table name: users # Table name: users

View File

@ -1,3 +1,5 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<h1>Update your password</h1> <h1>Update your password</h1>
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %> <%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>

View File

@ -1,3 +1,5 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<h1>Forgot your password?</h1> <h1>Forgot your password?</h1>
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %> <%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>

View File

@ -1,3 +1,5 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<p> <p>
You can reset your password within the next 15 minutes on You can reset your password within the next 15 minutes on
<%= link_to "this password reset page", edit_password_url(@user.password_reset_token) %>. <%= link_to "this password reset page", edit_password_url(@user.password_reset_token) %>.

View File

@ -1,2 +1,4 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
You can reset your password within the next 15 minutes on this password reset page: You can reset your password within the next 15 minutes on this password reset page:
<%= edit_password_url(@user.password_reset_token) %> <%= edit_password_url(@user.password_reset_token) %>

View File

@ -1,3 +1,5 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %> <%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
<%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %> <%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
class CreateUsers < ActiveRecord::Migration[8.0] class CreateUsers < ActiveRecord::Migration[8.0]
def change def change
create_table :users do |t| create_table :users do |t|

View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
class CreateSessions < ActiveRecord::Migration[8.0] class CreateSessions < ActiveRecord::Migration[8.0]
def change def change
create_table :sessions do |t| create_table :sessions do |t|

2
db/schema.rb generated
View File

@ -1,3 +1,5 @@
# Copyright (C) 2024 Manuel Bustillo
# This file is auto-generated from the current state of the database. Instead # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to # of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition. # incrementally modify your database, and then regenerate this schema definition.