1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-27 07:33:05 +00:00

fix update

This commit is contained in:
nishiki 2015-02-01 12:23:50 +01:00
parent 9921d3057f
commit 446faf704e
3 changed files with 30 additions and 36 deletions

View file

@ -24,8 +24,7 @@ module MPW
attr_accessor :created
def initialize(options={})
if not defined?(options[:id]) or not options[:id].to_s.empty? or
not defined?(options[:created]) or not options[:created].to_s.empty?
if not options.has_key?(:id) or options[:id].to_s.empty? or not options.has_key?(:created) or options[:created].to_s.empty?
@id = generate_id
@created = Time.now.to_i
else
@ -37,19 +36,19 @@ module MPW
end
def update(options={})
if defined?(options[:name]) and options[:name].to_s.empty?
if options.has_key?(:name) and options[:name].to_s.empty?
@error_msg = I18n.t('error.update.name_empty')
return false
end
@name = options[:name] if defined?(options[:name])
@group = options[:group] if defined?(options[:group])
@host = options[:host] if defined?(options[:host])
@protocol = options[:protocol] if defined?(options[:protocol])
@user = options[:user] if defined?(options[:user])
@password = options[:password] if defined?(options[:password])
@port = options[:port].to_i if defined?(options[:port])
@comment = options[:comment] if defined?(options[:comment])
@name = options[:name] if options.has_key?(:name)
@group = options[:group] if options.has_key?(:group)
@host = options[:host] if options.has_key?(:host)
@protocol = options[:protocol] if options.has_key?(:protocol)
@user = options[:user] if options.has_key?(:user)
@password = options[:password] if options.has_key?(:password)
@port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty?
@comment = options[:comment] if options.has_key?(:comment)
@last_edit = Time.now.to_i
return true
@ -63,16 +62,6 @@ module MPW
return false
end
private
def set_name(name)
if name.to_s.empty?
return false
end
@name = name
return true
end
private
def generate_id
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join

View file

@ -40,7 +40,7 @@ module MPW
group: d['group'],
host: d['host'],
protocol: d['protocol'],
user: d['login'],
user: d['user'],
password: d['password'],
port: d['port'],
comment: d['comment'],
@ -62,9 +62,10 @@ module MPW
# @rtrn: true if the file has been encrypted
def encrypt
FileUtils.cp(@file_gpg, "#{@file_gpg}.bk") if File.exist?(@file_gpg)
data_to_encrypt = {}
@data.each do |item|
puts item.class
next if item.empty?
data_to_encrypt.merge!(item.id => {'id' => item.id,

View file

@ -233,7 +233,7 @@ class Cli
options[:host] = ask(I18n.t('form.add.server')).to_s
options[:protocol] = ask(I18n.t('form.add.protocol')).to_s
options[:user] = ask(I18n.t('form.add.login')).to_s
options[:passwd] = ask(I18n.t('form.add.password')).to_s
options[:password] = ask(I18n.t('form.add.password')).to_s
options[:port] = ask(I18n.t('form.add.port')).to_s
options[:comment] = ask(I18n.t('form.add.comment')).to_s
@ -246,7 +246,7 @@ class Cli
puts "#{I18n.t('display.error')} #12: #{@mpw.error_msg}".red
end
else
puts "#{I18n.t('display.error')} #13: #{@mpw.error_msg}".red
puts "#{I18n.t('display.error')} #13: #{item.error_msg}".red
end
end
@ -255,19 +255,23 @@ class Cli
def update(id)
item = @mpw.search_by_id(id)
if not row.empty?
if not item.nil?
options = {}
puts I18n.t('form.update.title')
puts '--------------------'
name = ask(I18n.t('form.update.name' , name: item.name)).to_s
group = ask(I18n.t('form.update.group' , group: item.group)).to_s
server = ask(I18n.t('form.update.server' , server: item.host)).to_s
protocol = ask(I18n.t('form.update.protocol', protocol: item.protocol)).to_s
login = ask(I18n.t('form.update.login' , login: item.user)).to_s
passwd = ask(I18n.t('form.update.password')).to_s
port = ask(I18n.t('form.update.port' , port: item.port)).to_s
comment = ask(I18n.t('form.update.comment' , comment: item.comment)).to_s
options[:name] = ask(I18n.t('form.update.name' , name: item.name)).to_s
options[:group] = ask(I18n.t('form.update.group' , group: item.group)).to_s
options[:host] = ask(I18n.t('form.update.server' , server: item.host)).to_s
options[:protocol] = ask(I18n.t('form.update.protocol', protocol: item.protocol)).to_s
options[:user] = ask(I18n.t('form.update.login' , login: item.user)).to_s
options[:password] = ask(I18n.t('form.update.password')).to_s
options[:port] = ask(I18n.t('form.update.port' , port: item.port)).to_s
options[:comment] = ask(I18n.t('form.update.comment' , comment: item.comment)).to_s
options.delete_if { |k,v| v.empty? }
if @mpw.update(name, group, server, protocol, login, passwd, port, comment, id)
if item.update(options)
if @mpw.encrypt
sync
puts "#{I18n.t('form.update.valid')}".green
@ -275,7 +279,7 @@ class Cli
puts "#{I18n.t('display.error')} #14: #{@mpw.error_msg}".red
end
else
puts "#{I18n.t('display.error')} #15: #{@mpw.error_msg}".red
puts "#{I18n.t('display.error')} #15: #{item.error_msg}".red
end
else
puts I18n.t('display.nothing')