update client key encryption

This commit is contained in:
Thein Lin Kyaw
2023-08-17 15:53:13 +06:30
parent d2b9a9e61f
commit 019902872b
3 changed files with 80 additions and 76 deletions

View File

@@ -24,11 +24,10 @@ class ClientsController < ApplicationController
# POST /clients
# POST /clients.json
def create
@client = Client.new(client_params)
@client = Client.new(client_params)
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
key=cipher.random_key
secrect_key= Base64.encode64(key)
@client.secrect_key=secrect_key
secrect_key = cipher.random_key
@client.secrect_key = secrect_key
respond_to do |format|
if @client.save
@@ -68,7 +67,7 @@ class ClientsController < ApplicationController
# DELETE /clients/1.json
def destroy
message="Client was successfully destroyed."
find_batch=Batch.find_by_id(@client.id)
if !find_batch.nil?
message='Unable to delete client named '+ @client.name.to_s+'.'
@@ -90,6 +89,6 @@ class ClientsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def client_params
params.require(:client).permit(:name,:email, :phone, :address,:location_code)
params.require(:client).permit(:name,:email, :phone, :address,:location_code)
end
end