mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 05:47:53 +00:00
clean error message with the server
This commit is contained in:
parent
a8b4ca29c9
commit
e2839d136c
4 changed files with 58 additions and 54 deletions
|
@ -19,6 +19,7 @@ en:
|
|||
name_empty: "You must define a name!"
|
||||
sync:
|
||||
connection: "Connection fail!"
|
||||
communication: "A communication problem with the server is appeared!"
|
||||
no_data: "Nothing data!"
|
||||
not_authorized: "You haven't the access to remote file!"
|
||||
unknown: "An unknown error is occured!"
|
||||
|
@ -117,6 +118,11 @@ en:
|
|||
connect: "Connection to:"
|
||||
nothing: "Nothing result!"
|
||||
server:
|
||||
error:
|
||||
client:
|
||||
unknown: "An unknown error is appeared!"
|
||||
no_authorized: "You haven't access to remote file!"
|
||||
no_data: "Nothing data has been sent!"
|
||||
option:
|
||||
usage: "Usage"
|
||||
config: "Specifie the configuration file"
|
||||
|
|
10
i18n/fr.yml
10
i18n/fr.yml
|
@ -18,8 +18,9 @@ fr:
|
|||
update:
|
||||
name_empty: "Vous devez définir un nom!"
|
||||
sync:
|
||||
connection: "La connexion n'a pu être établie"
|
||||
no_data: "Aucune data!"
|
||||
connection: "La connexion n'a pu être établie!"
|
||||
communication: "Un problème de communication avec le serveur est apparu!"
|
||||
no_data: "Aucune donnée!"
|
||||
not_authorized: "Vous n'avez pas les autorisations d'accès au fichier distant!"
|
||||
unknown: "Une erreur inconnue est survenue!"
|
||||
cli:
|
||||
|
@ -117,6 +118,11 @@ fr:
|
|||
connect: "Connexion à:"
|
||||
nothing: "Aucun résultat!"
|
||||
server:
|
||||
error:
|
||||
client:
|
||||
unknown: "Une erreur inconnue est apparue!"
|
||||
no_authorized: "Vous n'avez pas les accès au fichier distant!"
|
||||
no_data: "Aucune donnée n'a été transmise!"
|
||||
option:
|
||||
usage: "Utilisation"
|
||||
config: "Spécifie le fichier de configuration"
|
||||
|
|
|
@ -43,7 +43,10 @@ class Server
|
|||
when 'close'
|
||||
closeConnection(client)
|
||||
else
|
||||
client.puts 'Unknown command'
|
||||
send_msg = {:action => 'unknown',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:error => 'server.error.client.unknown'}
|
||||
client.puts send_msg
|
||||
closeConnection(client)
|
||||
end
|
||||
end
|
||||
|
@ -72,20 +75,18 @@ class Server
|
|||
if isAuthorized?(msg['password'], salt, hash)
|
||||
send_msg = {:action => 'get',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'done',
|
||||
:data => data}
|
||||
:data => data,
|
||||
:error => nil}
|
||||
else
|
||||
send_msg = {:action => 'get',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'fail',
|
||||
:error => 'not_authorized'}
|
||||
:error => 'server.error.client.no_authorized'}
|
||||
end
|
||||
else
|
||||
send_msg = {:action => 'get',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:data => '',
|
||||
:msg => 'fail',
|
||||
:error => 'file_not_exist'}
|
||||
send_msg = {:action => 'get',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:data => '',
|
||||
:error => nil}
|
||||
end
|
||||
|
||||
return send_msg.to_json
|
||||
|
@ -101,8 +102,7 @@ class Server
|
|||
if data.nil? || data.empty?
|
||||
send_msg = {:action => 'update',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'fail',
|
||||
:error => 'no_data'}
|
||||
:error => 'server.error.client.no_data'}
|
||||
|
||||
return send_msg.to_json
|
||||
end
|
||||
|
@ -133,20 +133,18 @@ class Server
|
|||
file << config.to_yaml
|
||||
end
|
||||
|
||||
send_msg = {:action => 'update',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'done'}
|
||||
send_msg = {:action => 'update',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:error => nil}
|
||||
rescue Exception => e
|
||||
send_msg = {:action => 'update',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'fail',
|
||||
:error => 'server_error'}
|
||||
:error => 'server.error.client.unknown'}
|
||||
end
|
||||
else
|
||||
send_msg = {:action => 'update',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'fail',
|
||||
:error => 'not_autorized'}
|
||||
:error => 'server.error.client.no_authorized'}
|
||||
end
|
||||
|
||||
return send_msg.to_json
|
||||
|
@ -167,8 +165,7 @@ class Server
|
|||
if !File.exist?(file_gpg)
|
||||
send_msg = {:action => 'delete',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'delete_fail',
|
||||
:error => 'file_not_exist'}
|
||||
:error => nil}
|
||||
|
||||
return send_msg.to_json
|
||||
end
|
||||
|
@ -183,18 +180,16 @@ class Server
|
|||
|
||||
send_msg = {:action => 'delete',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'delete_done'}
|
||||
:error => nil}
|
||||
rescue Exception => e
|
||||
send_msg = {:action => 'delete',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'delete_fail',
|
||||
:error => e}
|
||||
:error => 'server.error.client.unknown'}
|
||||
end
|
||||
else
|
||||
send_msg = {:action => 'delete',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:msg => 'delete_fail',
|
||||
:error => 'not_autorized'}
|
||||
:error => 'server.error.client.no_authorized'}
|
||||
end
|
||||
|
||||
return send_msg.to_json
|
||||
|
@ -285,7 +280,7 @@ class Server
|
|||
file << config.to_yaml
|
||||
end
|
||||
rescue Exception => e
|
||||
puts "#{I18n.t('server.formsetup.not_valid')}\n#{e}"
|
||||
puts "#{I18n.t('server.form.setup.not_valid')}\n#{e}"
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
47
lib/Sync.rb
47
lib/Sync.rb
|
@ -55,16 +55,18 @@ class Sync
|
|||
return nil
|
||||
end
|
||||
|
||||
send_msg = {:action => 'get',
|
||||
:gpg_key => @gpg_key,
|
||||
:password => @password,
|
||||
:suffix => @suffix}
|
||||
send_msg = {:action => 'get',
|
||||
:gpg_key => @gpg_key,
|
||||
:password => @password,
|
||||
:suffix => @suffix}
|
||||
|
||||
@socket.puts send_msg.to_json
|
||||
msg = JSON.parse(@socket.gets)
|
||||
|
||||
case msg['error']
|
||||
when nil, 'file_not_exist'
|
||||
if !msg['error']
|
||||
@error_msg = I18n.t('error.sync.communication')
|
||||
return nil
|
||||
elsif msg['error'].nil?
|
||||
tmp_file = "/tmp/mpw-#{MPW.generatePassword()}.gpg"
|
||||
File.open(tmp_file, 'w') do |file|
|
||||
file << msg['data']
|
||||
|
@ -76,15 +78,12 @@ class Sync
|
|||
end
|
||||
|
||||
File.unlink(tmp_file)
|
||||
|
||||
return @mpw.search()
|
||||
when 'not_authorized'
|
||||
@error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}"
|
||||
else
|
||||
@error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}"
|
||||
@error_msg = I18n.t(msg['error'])
|
||||
return nil
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
# Update the remote data
|
||||
|
@ -95,29 +94,27 @@ class Sync
|
|||
return true
|
||||
end
|
||||
|
||||
send_msg = {:action => 'update',
|
||||
:gpg_key => @gpg_key,
|
||||
:password => @password,
|
||||
:suffix => @suffix,
|
||||
:data => data}
|
||||
send_msg = {:action => 'update',
|
||||
:gpg_key => @gpg_key,
|
||||
:password => @password,
|
||||
:suffix => @suffix,
|
||||
:data => data}
|
||||
|
||||
@socket.puts send_msg.to_json
|
||||
msg = JSON.parse(@socket.gets)
|
||||
|
||||
case msg['error']
|
||||
when nil
|
||||
if !msg['error']
|
||||
@error_msg = I18n.t('error.sync.communication')
|
||||
return false
|
||||
elsif msg['error'].nil?
|
||||
return true
|
||||
when 'not_authorized'
|
||||
@error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}"
|
||||
when 'no_data'
|
||||
@error_msg = "#{I18n.t('error.sync.no_data')}\n#{e}"
|
||||
else
|
||||
@error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}"
|
||||
@error_msg = I18n.t(msg['error'])
|
||||
return false
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
# TODO
|
||||
def delete()
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue