|
|
@ -41,6 +41,7 @@ post "/login" do |context| |
|
|
|
user_file.tokens = user_file.tokens.not_nil!.last(5) |
|
|
|
end |
|
|
|
File.write(Statics.data_path+"user/"+user_file.email,user_file.to_json) |
|
|
|
context.response.content_type = "application/json" |
|
|
|
token.to_json |
|
|
|
end |
|
|
|
|
|
|
@ -49,6 +50,7 @@ post "/logout" do |context| |
|
|
|
user_file = User.from_json File.read(Statics.data_path+"user/"+user.email) |
|
|
|
user_file.tokens=user_file.tokens.not_nil!-user.tokens.not_nil! |
|
|
|
File.write(Statics.data_path+"user/"+user_file.email,user_file.to_json) |
|
|
|
context.response.content_type = "application/json" |
|
|
|
"OK".to_json |
|
|
|
end |
|
|
|
|
|
|
@ -57,6 +59,7 @@ post "/logout-all" do |context| |
|
|
|
user_file = User.from_json File.read(Statics.data_path+"user/"+user.email) |
|
|
|
user_file.tokens=Array(UUID).new |
|
|
|
File.write(Statics.data_path+"user/"+user_file.email,user_file.to_json) |
|
|
|
context.response.content_type = "application/json" |
|
|
|
"OK".to_json |
|
|
|
end |
|
|
|
|
|
|
@ -74,9 +77,54 @@ post "/user" do |context| |
|
|
|
raise Exception.new("Bad email address") |
|
|
|
end |
|
|
|
File.write(Statics.data_path+"user/"+user.email,user.to_json) |
|
|
|
context.response.content_type = "application/json" |
|
|
|
"OK".to_json |
|
|
|
end |
|
|
|
|
|
|
|
get "/user/tokens" do |context| |
|
|
|
user = authenticate!(context.request.headers["user"],UUID.new(context.request.headers["api_token"])) |
|
|
|
context.response.content_type = "application/json" |
|
|
|
user.tokens.to_json |
|
|
|
end |
|
|
|
|
|
|
|
get "/user/address" do |context| |
|
|
|
user = authenticate!(context.request.headers["user"],UUID.new(context.request.headers["api_token"])) |
|
|
|
context.response.content_type = "application/json" |
|
|
|
user.addresses.to_json |
|
|
|
end |
|
|
|
|
|
|
|
post "/user/address" do |context| |
|
|
|
user = authenticate!(context.request.headers["user"],UUID.new(context.request.headers["api_token"])) |
|
|
|
addresses = Array(Address).from_json(context.request.body.not_nil!).not_nil! |
|
|
|
user_file = User.from_json File.read(Statics.data_path+"user/"+user.email) |
|
|
|
old_list=user_file.addresses |
|
|
|
if old_list.nil? |
|
|
|
else |
|
|
|
addresses=old_list+addresses |
|
|
|
end |
|
|
|
user_file.addresses=addresses |
|
|
|
File.write(Statics.data_path+"user/"+user.email,user_file.to_json) |
|
|
|
context.response.content_type = "application/json" |
|
|
|
"OK".to_json |
|
|
|
end |
|
|
|
|
|
|
|
delete "/user/address" do |context| |
|
|
|
user = authenticate!(context.request.headers["user"],UUID.new(context.request.headers["api_token"])) |
|
|
|
addresses = Array(Address).from_json(context.request.body.not_nil!).not_nil! |
|
|
|
user_file = User.from_json File.read(Statics.data_path+"user/"+user.email) |
|
|
|
old_list=user_file.addresses |
|
|
|
if old_list.nil? |
|
|
|
addresses=Array(Address).new |
|
|
|
else |
|
|
|
addresses=old_list-addresses |
|
|
|
end |
|
|
|
user_file.addresses=addresses |
|
|
|
File.write(Statics.data_path+"user/"+user.email,user_file.to_json) |
|
|
|
context.response.content_type = "application/json" |
|
|
|
"OK".to_json |
|
|
|
end |
|
|
|
|
|
|
|
get "/user" do |context| |
|
|
|
context.response.content_type = "application/json" |
|
|
|
authenticate!(context.request.headers["user"],UUID.new(context.request.headers["api_token"])).to_json |
|
|
|
end |