Commit db1c54ad by phuctmZigexn

refactor Userscontroller and remove redundant files

parent 96d08f17
......@@ -14,23 +14,6 @@ gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# 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
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
......
......@@ -72,13 +72,6 @@ GEM
chromedriver-helper (1.2.0)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
crass (1.0.4)
erubi (1.7.1)
......@@ -91,9 +84,6 @@ GEM
i18n (1.0.1)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
......@@ -115,7 +105,6 @@ GEM
mini_portile2 (2.3.0)
minitest (5.11.3)
msgpack (1.2.4)
multi_json (1.13.1)
nio4r (2.3.1)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
......@@ -189,9 +178,6 @@ GEM
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
turbolinks (5.1.1)
turbolinks-source (~> 5.1)
turbolinks-source (5.1.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.17)
......@@ -219,9 +205,7 @@ DEPENDENCIES
byebug
capybara (>= 2.15, < 4.0)
chromedriver-helper
coffee-rails (~> 4.2)
faker (~> 1.9, >= 1.9.1)
jbuilder (~> 2.5)
jquery-rails (~> 4.3, >= 4.3.3)
listen (>= 3.0.5, < 3.2)
pg (~> 1.0)
......@@ -233,7 +217,6 @@ DEPENDENCIES
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
turbolinks (~> 5)
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
......
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
......@@ -2,5 +2,4 @@
//= require bootstrap
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .
// Place all the styles related to the account_activations controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -2,13 +2,13 @@ class UsersController < ApplicationController
before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update]
before_action :admin_user, only: [:destroy]
before_action :find_user, only: [:show, :edit, :update, :destroy]
def index
@users = User.paginate(page: params[:page])
end
def show
@user = User.find(params[:id])
end
def new
......@@ -27,11 +27,9 @@ class UsersController < ApplicationController
end
def edit
@user = User.find params[:id]
end
def update
@user = User.find params[:id]
if @user.update_attributes user_params
flash[:success] = "Profile updated"
redirect_to @user
......@@ -41,7 +39,7 @@ class UsersController < ApplicationController
end
def destroy
User.find(params[:id]).destroy
@user.destroy
flash[:success] = "User deleted"
redirect_to users_url
end
......@@ -51,6 +49,10 @@ class UsersController < ApplicationController
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
def find_user
@user = User.find(params[:id])
end
#confirm a logged-in user
# if user don't login and they're in GET request, it store this request to session[:forwarding_url]
def logged_in_user
......@@ -63,8 +65,7 @@ class UsersController < ApplicationController
# confirm the correct user
def correct_user
@user = User.find params[:id]
redirect_to root_url unless current_user? @user
redirect_to root_url unless current_user? find_user
end
# confirm an admin user
......
......@@ -32,7 +32,8 @@ Rails.application.configure do
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :test
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: 'localhost', port: '1025' }
config.action_mailer.default_url_options = { host: 'localhost:3000', protocol: 'http' }
config.action_mailer.perform_caching = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment