Check if Data value already exists in a json file with liquid - html

I created a form to collect user data
Then I used an Api to get the user data
And so far I have been successful ( I displayed the data on my site using jekyll-json-get plugin)
Where the problem is users could be able to register with multiple emails...
The file looks like this
json file
{created" => “date”,
“data” => "{
“first name” => “me”,
“email” => “me#me.com”
},
“folder” => “null”
}
{ “created” => “date”,
data" => "{
“first name” => “me2”,
“email” => “me#me.com”
},
“folder” => “null”
}
… And so on
What I want to do is..
On form submission if the email entered as been used by anyone else stop form submission and ask for another email.
How do I go about this(am kinda new)

Related

How do I update an eloquent json column from validation data without over writing what's stored in the column?

I'm hoping for a straight-forward solution to do this, but so far I've been coming up empty...
I have a front end vue app/form that sends data back to my laravel backend - I have a controller that validates and saves the request (not looking for feedback on this architecture at the moment unless it actually solves the problem - that's a task for another day...)
I've added a json column called "custom_redeem_fields"
For context, it's to support more flexibility and accepts key/val pairs to use in another field called "custom_redeem_instructions" that has text with delimiters for each of the keys from "custom_redeem_fields", although, I'd prefer to keep from defining these keys statically because the whole point is to be able to add new keys at will. So custom_redeem_instructions will read something like "please visit {•URL•} and enter code {•CODE•}..." and those values will come from the custom_redeem_fields json field.
In the model, I have "custom_redeem_fields" in the fillable array, as well as set as castable to json.
protected $fillable = ['custom_redeem_fields'];
protected $casts = ['custom_redeem_fields' => 'json'];
In the controller, I have ~20 additional columns (not really relevant here, so I've only included two) so I'm trying not to call them out individually beyond their validation rules. The request typically sends one field at a time, so the user can update and save each field as they go. This was working appropriately for all the other fields I had before I added the "custom_redeem_fields.xxxx" to the mix.
$validatedData = $request->validate([
'title' => 'sometimes|required|max:255',
'text' => 'sometimes|required_unless:redeem_type,9|max:255',
'custom_redeem_fields.email' => 'sometimes|email',
'custom_redeem_fields.phone' => ['sometimes', new ValidPhone],
'custom_redeem_fields.code' => 'sometimes',
'custom_redeem_fields.url' => 'sometimes|url'
]);
$ticket = Ticket::find($id)
$ticket->update($validatedData);
Now, with the "custom_redeem_fields.xxxxx" this falls apart - the entire json object stored in "custom_redeem_fields" is overwritten with the most recent update, rather than just updating the key included in the validatedData array. So if I save:
[
"title" => "Monty Pythons Flying Circus"
"text" => "Monty Pythons Flying Circus is a British surreal sketch comedy series created by and starring the comedy group Monty Python, consisting of Graham Chapman, ..."
"custom_redeem_fields" => [
"email" => "bob#example.com",
"phone" => "503.555.5555",
"code" => "1xoicvjq",
"url" => "https://example.com/"
]
]
and then I send:
"custom_redeem_fields" => ["email" => "pat#example.com"]
the custom redeem fields returns:
"custom_redeem_fields" => ["email" => "pat#example.com"]
rather than:
"custom_redeem_fields" => ["email" => "pat#example.com", "phone" => "503.555.5555", "code" => "1xoicvjq", "url" => "https://example.com/"]
It seems that validation rules need json keys to be notated with dot syntax (custom_redeem_fields.url), and eloquent needs arrow syntax (custom_redeem_fields->url), but I'm not sure what's the most straightforward way to transition between the two, which seems very not-laravel, and the documentation is certainly lacking in this department...
Any help would be appreciated.
Thanks!
Wouldn't array_merge() solve your problem, it would overwrite values you provide with the second parameter. If you give it the already existing ones as the first, it would combine the two as you want.
$customRedeemInput = [...];
$model->custom_redeem_fields = array_merge($model->custom_redeem_fields, $customRedeemInput);
$model->save();

Search and view Elasticsearch results from an HTML

I am currently working on a project and as the title suggests, what I want to do is to be able to search from an HTML a cluster already uploaded on elasticsearch and preview the results back in the HTML.
I thought of using Logstash to send the search input from HTML to elasticsearch but I can't figure a way of viewing those results back in the HTML. In general what I want to do, is to be able to work with elasticsearch the way kibana does, but from a website.
Appreciate any possible help :)
use php-elastic official library(https://github.com/elastic/elasticsearch-php).
You can use the following code to get the search result:
$this->client = ClientBuilder::create()->setHosts(["ELASTICSEARCH_HOST:ELASTICSEARCH_PORT"])->build();
$queryBody = ["match_all" => new \stdClass()];
if($search) {
$queryBody = [
"match" => [
"_all" => $search
]
];
}
$params = [
"from" => $page * $this->pageSize, // if you want data for pagination
"size" => $this->pageSize, // if you want data for pagination
"index" => $index,
"type" => $type,
"_source_include" => $fields, // Your required field array
"body" => [
"query" => $queryBody
]
];
//Get the search result
$response = $this->client->search($params);

CakePHP redirect with form parameter

In CakePHP 3.1 I am redirecting to login page after a database update and I want to pass back the email so that form input is already populated.
I can do it the standard way with using the controller and action in the redirect.
Instead I am using just a url string
return $this->redirect('/login',['?' => ['email' => $email]]);
This gives me the error Unknown status code
The redirect method expects a status code as the second parameter. You will need to provide and array-based URL as the first parameter or append the query var to the current string.
return $this->redirect('/login?email=' . $email);
return $this->redirect([
'controller' => 'Users',
'action' => 'login',
'?' => [
'email' => $email
]
]);

populating fullcalendar with json data through sinatra url

We am trying to get a json feed to populate a FullCalendar application. We are using sintara and by implementing the sinatra-contrib gem we are creating a url which contains the relevant json data.
Below is the code we are using for FullCalendar in our index.erb file.
$('#calendar').fullCalendar({
events: '/example.json'
});
and this is the code in the sinatra server file we are using to test with, as eventually we want to populate by using data in a postgres database.
get '/example.json' do
json :title => 'paul', :id => "1", :start => "2015-03-11T15:25:00", :end => '2015-03-11T15:55:00'
end
When we run this we get the following message in the terminal, which would suggest the call was successfully made, but the calendar does not get populated with the test event.
[11/Mar/2015:18:46:41 +0000] "GET /example.json?start=2015-03-08&end=2015-03-15&_=1426099601014
We are able to populate the calendar manually by adding the start, end, and title details to the events FullCalendar section.
Thanks
Have you tried like that :
require 'json'
get '/example.json', :provides => :json do
{:title => 'paul', :id => "1", :start => "2015-03-11T15:25:00", :end => '2015-03-11T15:55:00'}.to_json()
end

How to get First Data JSON response object properties?

I am using the VinceG\FirstDataApi in the First Data demo mode account fairly successfully. That is, I send a simulated credit card payment, and I receive a full JSON object, error=0, approved=1, etc.
Within this set is some of the information I want to use to construct the "thank you" page or the "Something went wrong" page:
[arrayResponse:protected] => stdClass Object
(
[transaction_error] => 0
[transaction_approved] => 1
[exact_resp_code] => 00
[exact_message] => Transaction Normal
[bank_resp_code] => 100
[bank_message] => Approved
[sequence_no] => 000008
[cvv2] => I
[retrieval_ref_no] => 4241673
[merchant_name] => MY COMPANY NAME
[merchant_address] => MY COMPANY ADDRESS
[merchant_city] => MY COMPANY CITY
[merchant_province] => MY COMPANY STATE
[merchant_country] => United States
[merchant_postal] => MY COMPANY ZIPCODE
[merchant_url] => https:/my.website.com
I have tried to access the properties within the array:
echo "<pre>";
print_r($firstData->arrayResponse);
...and the output is "Cannot access protected property FirstData::$arrayResponse".
Ok, this looks wierd to me, but the answer is:
echo "<pre>";
print_r($firstData->getarrayResponse());
...Appending the word get in front of the protected property arrayResponse to make getarrayResponse(). Looks like a horrible method invention, but there you have it.