change level of development.yml, add callback in reset_password

parent 4fc05e8f
Pipeline #1083 failed with stages
in 0 seconds
...@@ -6,12 +6,12 @@ class ConfirmationsController < ApplicationController ...@@ -6,12 +6,12 @@ class ConfirmationsController < ApplicationController
def mail_register def mail_register
email = params[:confirmation][:email].downcase email = params[:confirmation][:email].downcase
if User.find_by(email: email) if User.find_by(email: email)
flash[:danger] = Settings.sign_up.email_existed flash[:danger] = Settings.user.sign_up.existed
redirect_to register_step1_path redirect_to register_step1_path
end end
@user = Confirmation.find_or_initialize_by(email: email) @user = Confirmation.find_or_initialize_by(email: email)
unless @user.save unless @user.save
flash[:danger] = Settings.sign_up.email_format_failed flash[:danger] = Settings.user.sign_up.format_failed
return redirect_to register_step1_path return redirect_to register_step1_path
end end
......
class JobAppliedsController < ApplicationController
before_action :sign_in_validation, only: [:new, :confirmation, :create]
def new
end
def confirmation
@user = JobApplied.new(apply_params)
return root_path unless apply_params
end
def create
binding.pry
@user = JobApplied.new(apply_params)
return root_path unless @user
return job_detail_path(apply_params[:job_id]) unless @user.save
end
private
def sign_in_validation
return if signed_in?
flash[:warning] = Settings.user.warning_signin
redirect_to login_path
end
def apply_params
params.require(:job_applied).permit(:name, :email, :job_id, :cv_user)
end
end
class ResetPasswordsController < ApplicationController class ResetPasswordsController < ApplicationController
before_action :find_token_param, only: [:edit]
def reset_password def reset_password
end end
...@@ -6,20 +7,19 @@ class ResetPasswordsController < ApplicationController ...@@ -6,20 +7,19 @@ class ResetPasswordsController < ApplicationController
def sending_email def sending_email
@user = User.find_by(email: params[:reset_password][:email].downcase) @user = User.find_by(email: params[:reset_password][:email].downcase)
unless @user unless @user
flash[:danger] = Settings.reset_password.sending_email_failed flash[:danger] = Settings.user.reset_password.failed
redirect_to reset_password_step1_path
else else
forgot_token = Digest::SHA1.hexdigest(SecureRandom.urlsafe_base64) forgot_token = Digest::SHA1.hexdigest(SecureRandom.urlsafe_base64)
@user.update_attribute(:remember_token, forgot_token) @user.update_attribute(:remember_token, forgot_token)
ResetPasswordMailer.reset_password(@user).deliver_later ResetPasswordMailer.reset_password(@user).deliver_later
flash[:success] = Settings.reset_password.sending_email_success flash[:success] = Settings.user.reset_password.success
redirect_to reset_password_step1_path
end end
redirect_to reset_password_step1_path
end end
def edit def edit
@user = User.find_by(remember_token: params[:token]) @user = User.find_by(remember_token: params[:token])
return redirect_to reset_password_step1_path unless @user && params[:token] return redirect_to reset_password_step1_path unless @user
if @user.token_expired? if @user.token_expired?
flash[:danger] = Settings.user.expiration flash[:danger] = Settings.user.expiration
redirect_to register_step1_path redirect_to register_step1_path
...@@ -28,18 +28,22 @@ class ResetPasswordsController < ApplicationController ...@@ -28,18 +28,22 @@ class ResetPasswordsController < ApplicationController
def update def update
@user = User.find_by(email: params[:user][:email]) @user = User.find_by(email: params[:user][:email])
unless @user.update_attributes(forgot_pass_params) if @user.update_attributes(forgot_pass_params)
flash[:danger] = Settings.reset_password.update_reset_pass
redirect_to reset_password_final_path(token: @user.remember_token)
else
sign_in @user sign_in @user
flash[:success] = Settings.general_notify.update_success flash[:success] = Settings.general_notify.update_success
redirect_to my_page_path redirect_to my_page_path
else
flash[:danger] = Settings.user.reset_password.update_reset_pass
redirect_to reset_password_final_path(token: @user.remember_token)
end end
end end
private private
def find_token_param
return redirect_to reset_password_step1_path unless params[:token]
end
def forgot_pass_params def forgot_pass_params
params.require(:user).permit( :password, :password_confirmation) params.require(:user).permit( :password, :password_confirmation)
end end
......
...@@ -10,7 +10,7 @@ class SessionsController < ApplicationController ...@@ -10,7 +10,7 @@ class SessionsController < ApplicationController
sign_in user sign_in user
redirect_to my_page_path redirect_to my_page_path
else else
flash.now[:danger] = Settings.sign_in.sign_in_failed flash.now[:danger] = Settings.user.sign_in.failed
render 'new' render 'new'
end end
end end
......
...@@ -13,10 +13,6 @@ class Confirmation < ApplicationRecord ...@@ -13,10 +13,6 @@ class Confirmation < ApplicationRecord
Digest::SHA1.hexdigest(token.to_s) Digest::SHA1.hexdigest(token.to_s)
end end
def token_expired?
updated_at <= 24.hours.ago
end
private private
def create_confirm_token def create_confirm_token
......
...@@ -28,10 +28,10 @@ Rails.application.routes.draw do ...@@ -28,10 +28,10 @@ Rails.application.routes.draw do
get 'jobs/company/:converted_name', to: 'jobs#company_jobs', as: :company_jobs get 'jobs/company/:converted_name', to: 'jobs#company_jobs', as: :company_jobs
resources :reset_passwords, only: [:edit, :update] resources :reset_passwords, only: [:edit, :update]
resources :confirmations resources :confirmations, only: [:new]
resources :top_pages resources :top_pages, only: [:index]
resources :industries resources :industries, only: [:index]
resources :cities resources :cities, only: [:index]
root to: "top_pages#index" root to: "top_pages#index"
end end
......
...@@ -6,15 +6,15 @@ user: ...@@ -6,15 +6,15 @@ user:
password_mismatch: 'Password is mismatch' password_mismatch: 'Password is mismatch'
warning_signin: 'Please Sign In...' warning_signin: 'Please Sign In...'
reset_password: reset_password:
sending_email_failed: 'Your Email invalid or not register' failed: 'Your Email invalid or not register'
sending_email_success: 'Please check your email to change your password' success: 'Please check your email to change your password'
update_reset_pass: 'Password or Password Confirmation is mismatch' update_reset_pass: 'Password or Password Confirmation is mismatch'
sign_in: sign_in:
sign_in_failed: 'Invalid email or password' failed: 'Invalid email or password'
sign_up: sign_up:
email_existed: 'Email existed. Please change !!!' existed: 'Email existed. Please change !!!'
email_format_failed: 'Email formated invalid' format_failed: 'Email formated invalid'
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