move text flash to yaml file

parent 5f7e6e42
Pipeline #976 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] = 'Email existed. Please change !!!' flash[:danger] = ENV['email_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] = "Email formated invalid" flash[:danger] = ENV['email_format_failed']
return redirect_to register_step1_path return redirect_to register_step1_path
end end
......
...@@ -6,22 +6,22 @@ class ResetPasswordsController < ApplicationController ...@@ -6,22 +6,22 @@ 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] = "Your Email invalid or not register" flash[:danger] = ENV['sending_email_failed']
redirect_to reset_password_step1_path 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] = "Please check your email to change your password" flash[:success] = ENV['sending_email_success']
redirect_to reset_password_step1_path redirect_to reset_password_step1_path
end end
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 return redirect_to reset_password_step1_path unless @user && params[:token]
if @user.token_expired? if @user.token_expired?
flash[:danger] = "Link Confirmation is expiration too 24 hours to confirm. Please update your Email again!" flash[:danger] = ENV['expiration']
redirect_to register_step1_path redirect_to register_step1_path
end end
end end
...@@ -29,11 +29,11 @@ class ResetPasswordsController < ApplicationController ...@@ -29,11 +29,11 @@ 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) unless @user.update_attributes(forgot_pass_params)
flash[:danger] = "Password or Password Confirmation is mismatch" flash[:danger] = ENV['update_reset_pass']
redirect_to reset_password_final_path(token: @user.remember_token) redirect_to reset_password_final_path(token: @user.remember_token)
else else
sign_in @user sign_in @user
flash[:success] = 'Updated Successfully' flash[:success] = ENV['update_success']
redirect_to my_page_path redirect_to my_page_path
end end
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] = 'Invalid email or password' flash.now[:danger] = ENV['sign_in_failed']
render 'new' render 'new'
end end
end end
......
...@@ -11,10 +11,10 @@ class UsersController < ApplicationController ...@@ -11,10 +11,10 @@ class UsersController < ApplicationController
if current_user.authenticate(params[:user][:password]) if current_user.authenticate(params[:user][:password])
return respond_to { |format| format.js } unless current_user.update_attributes(user_params) return respond_to { |format| format.js } unless current_user.update_attributes(user_params)
flash[:success] = 'Updated Successfully' flash[:success] = ENV['update_success']
redirect_to my_page_path redirect_to my_page_path
else else
flash.now[:danger] = 'Password is mismatch' flash.now[:danger] = ENV['password_mismatch']
end end
end end
...@@ -22,7 +22,7 @@ class UsersController < ApplicationController ...@@ -22,7 +22,7 @@ class UsersController < ApplicationController
@email = Confirmation.find_by(confirm_token: params[:code]) @email = Confirmation.find_by(confirm_token: params[:code])
return redirect_to register_step1_path unless @email return redirect_to register_step1_path unless @email
if @email.token_expired? if @email.token_expired?
flash[:danger] = "Link Confirmation is expiration too 24 hours to confirm. Please update your Email again!" flash[:danger] = ENV['expiration']
redirect_to register_step1_path redirect_to register_step1_path
else else
@user = User.new @user = User.new
...@@ -39,8 +39,8 @@ class UsersController < ApplicationController ...@@ -39,8 +39,8 @@ class UsersController < ApplicationController
private private
def sign_in_validation def sign_in_validation
return if signed_in? || params[:remember_token].blank? return if signed_in?
flash[:warning] = "Please Sign In..." flash[:warning] = ENV['warning_signin']
redirect_to login_path redirect_to login_path
end end
......
class ResetPassword < ApplicationRecord
before_save :create_remember_token
has_secure_password
PASSWORD_FORMAT = /\A(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/x
validates :password, format: { with: PASSWORD_FORMAT, message: "is too short or not strength" }
def self.new_remember_token
SecureRandom.urlsafe_base64
end
def self.digest(token)
Digest::SHA1.hexdigest(token.to_s)
end
private
def create_remember_token
self.remember_token = User.digest(User.new_remember_token)
end
end
...@@ -15,6 +15,11 @@ module Venjob ...@@ -15,6 +15,11 @@ module Venjob
YAML.load(File.open(env_file)).each do |key, value| YAML.load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value ENV[key.to_s] = value
end if File.exists?(env_file) end if File.exists?(env_file)
text_file = File.join(Rails.root, 'config', 'text_flash.yml')
YAML.load(File.open(text_file)).each do |key, value|
ENV[key.to_s] = value
end if File.exists?(text_file)
end end
# config.filter_parameter_logging << :oldpassword, :password # config.filter_parameter_logging << :oldpassword, :password
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
......
#GENERAL
update_success: 'Updated Successfully'
#TEXT OF USER
expiration: 'Link Confirmation is expiration too 24 hours to confirm. Please update your Email again!'
password_mismatch: 'Password is mismatch'
warning_signin: 'Please Sign In...'
#TEXT OF RESET PASSWORD
sending_email_failed: 'Your Email invalid or not register'
sending_email_success: 'Please check your email to change your password'
update_reset_pass: 'Password or Password Confirmation is mismatch'
#TEXT OF SIGN IN
sign_in_failed: 'Invalid email or password'
#TEXT OF SIGN UP
email_existed: 'Email existed. Please change !!!'
email_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