refactoring and rubocop changes
This commit is contained in:
parent
f7ec73f85e
commit
5475086622
13 changed files with 33 additions and 10 deletions
|
@ -39,16 +39,9 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def recover_password
|
||||
user = User.find(params[:user_id])
|
||||
if user.recovery_password_digest && user.authenticate_recovery_password(params[:recovery_password])
|
||||
user.password = params[:password]
|
||||
user.password_confirmation = params[:password_confirmation]
|
||||
if user.save
|
||||
user.update(recovery_password: nil)
|
||||
redirect_to '/welcome', notice: 'Password changed'
|
||||
else
|
||||
redirect_to '/welcome', notice: 'Passwords don\'t match'
|
||||
end
|
||||
@user = User.find(params[:user_id])
|
||||
if recovery_password_proper?
|
||||
set_new_password
|
||||
else
|
||||
redirect_to '/welcome', notice: 'Recovery link expired or invalid'
|
||||
end
|
||||
|
@ -63,4 +56,22 @@ class UsersController < ApplicationController
|
|||
User.find(params[:id]).update(status: :blocked)
|
||||
redirect_to '/users'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def recovery_password_proper?
|
||||
@user.recovery_password_digest &&
|
||||
@user.authenticate_recovery_password(params[:recovery_password])
|
||||
end
|
||||
|
||||
def set_new_password
|
||||
@user.password = params[:password]
|
||||
@user.password_confirmation = params[:password_confirmation]
|
||||
if @user.save
|
||||
@user.update(recovery_password: nil)
|
||||
redirect_to '/welcome', notice: 'Password changed'
|
||||
else
|
||||
redirect_to '/welcome', notice: 'Passwords don\'t match'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Application helper
|
||||
module ApplicationHelper
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Books helper
|
||||
module BooksHelper
|
||||
def cart_summary
|
||||
number_to_currency(@books.map(&:price).reduce(:+))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Sessions helper
|
||||
module SessionsHelper
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Users helper
|
||||
module UsersHelper
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# User mailer
|
||||
class UserMailer < ApplicationMailer
|
||||
def password_recovery
|
||||
@user = params[:user]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Application record
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
def update(*args)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Books presenter
|
||||
class BooksPresenter < SimpleDelegator
|
||||
include ActiveSupport::NumberHelper
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ require 'rails/all'
|
|||
# you've limited to :test, :development, or :production.
|
||||
Bundler.require(*Rails.groups)
|
||||
|
||||
# App
|
||||
module App
|
||||
class Application < Rails::Application
|
||||
# Initialize configuration defaults for originally generated Rails version.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Create authors
|
||||
class CreateAuthors < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :authors do |t|
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Create books
|
||||
class CreateBooks < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :books do |t|
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Create association table between authors and books
|
||||
class CreateAuthorsBooks < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :authors_books do |t|
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Create users
|
||||
class CreateUsers < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :users do |t|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue