Jump to content

HappyAlligator

Members
  • Posts

    14
  • Joined

  • Last visited

Reputation Activity

  1. Like
    HappyAlligator reacted to PotatoMato in Default random password for users   
    Hi,  @HappyAlligator. You should use a field from your table instead of using a Virtual field where you will save the initial password. Hope this  helps.
    -Potato 
  2. Like
    HappyAlligator reacted to GoodBoy in Default random password for users   
    Hello! Just to add on this, you can implement this article as well so they can already change their default password upon their initial login to your application.
    - https://howto.caspio.com/tech-tips-and-articles/advanced-customizations/changing-password-on-initial-login/
    Cheers!
  3. Thanks
    HappyAlligator reacted to autonumber in Default random password for users   
    Hi @HappyAlligator! Yes. It is possible. Add a text field in your table, set it as Autovalue (Random Password) on the Submission Form, then enable the Acknowledgement Email and add the field on the message body. After submitting the form, they will receive the random password via email.

     
    In addition to this, I found this Appointment Scheduling template that shows what you're trying to accomplish. I believe you can request it here so you check
    https://www.caspio.com/apps/appointment-scheduling/
     
    I hope this helps. 
  4. Thanks
    HappyAlligator reacted to gsgriffin in API sample code for updating a field value   
    Since it appears nobody has done this before and support from Caspio isn't willing to make their documentation clear enough to figure this out, I spent many hours in trial and error to figure out how the API works and to do so with PHP...which everyone on the web should know.  Below is the code sample that when called through a URL with query values will:
    1) attempt to get a file which will store the auth token in a function
    2) if there is no file, get a new auth token and then store it in a bearer file in a function
    3) attempt to write the value to the field in the table
    4) if unsuccessful, try renewing the token, store the new token, and write to the table again.
    This should hopefully live forever and never need me to go and renew the tokens, which is a pain and prone to messing up the program someday.
    This is what I was looking for all over the forums. Hopefully this will help someone someday:
    <?php $bearer_filename="bearer.php"; //file to hold function which responds to request for current auth token $sub_domain="c1eib....";//replace with the subdomain Caspio assigns to your url for token auth $client_id='e16e1a....replace with your client id 51ade07'; $client_secret='e235b22....replace with your secret.......d4b3d9c1e6d8a5'; function getBearer(){ global $sub_domain; global $client_id; global $client_secret; $body="grant_type=client_credentials&client_id=".$client_id."&client_secret=".$client_secret; $grant_type='grant_type=client_credentials'; $auth_url='https://'.$sub_domain.'.caspio.com/oauth/token'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $auth_url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); if(!$result){return "Connection Failure";} curl_close($curl); return $result; } function updateTable($table,$id,$matching,$field,$value,$auth){ global $sub_domain; $auth=json_decode($auth); $url = 'https://'.$sub_domain.'.caspio.com/rest/v2/tables/'.$table.'/records?q.where='.$id.'%3D'.$matching; $update=array($field => $value); $postdata=json_encode($update); $auth = 'bearer '.$auth->access_token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "PUT", CURLOPT_POSTFIELDS => $postdata, CURLOPT_HTTPHEADER => array( "Authorization:" . $auth, "accept: application/json", "cache-control: no-cache", "content-type: application/json", 'Content-Length: ' . strlen($postdata) ) )); $results=curl_exec($curl); curl_close($curl); echo $results; $response=json_decode($results); if($response->RecordsAffected==1){ echo "<br>Updated 1 row successfully"; }else{ //get the auth key and try again } return $response; } function createBearer(){ global $bearer_filename; $new_auth = getBearer(); //get new bearer tokens $code='<'.'?php function getAuth(){return \''.$new_auth.'\';} ?'.'>'; //code for file with function to return values file_put_contents($bearer_filename,$code); return $new_auth; } if(!file_exists($bearer_filename)){ //create new bearer file and get auth $auth = createBearer(); }else{ //file exists with function to give auth include $bearer_filename; $auth = getAuth(); } //get values from URL for posting to table $table=$_GET["Table"]; $id=$_GET["ID"]; $matching=$_GET["Matching"]; $field=$_GET["Field"]; $value=$_GET["Value"]; $results = updateTable($table,$id,$matching,$field,$value,$auth); if($results->Message=="Authorization has been denied for this request."){ echo "<br>Problem with update. Try getting new bearer and try again"; $auth = createBearer(); //could be that the token has expired. create new one, save the file and try again with fresh token $results = updateTable($table,$id,$matching,$field,$value,$auth); echo "Results after retry:".$results; } ?> Wherever you place this on your server, you can call it directly using:
    https://...your url to this php file...?Table=YOUR_TABLE&ID=FIELD_NAME_IN_TABLE_FOR_MATCHING_ID&Matching=VALUE_TO_MATCH_ID&Field=FIELD_YOU_WANT_TO_UPDATE&Value=VALUE_YOU_WANT_IN_THE_FIELD
    This was design for a single field update in a single row.  You will need to adapt for any other use, but at least I will hopefully never have to worry about an auth token ever again and my program will be stable.
  5. Thanks
    HappyAlligator reacted to AndrewCHughes in PHP Caspio REST API library   
    This may be of use to people. This is pulled out of a project I'm working on. It's a PHP library that manages the low-level integration with the Caspio REST API. If I have time I'll pull more classes out of the project that might be helpful and integrate them into this library. But it demonstrates the basics of interacting with the Caspio REST API via PHP.
    https://github.com/moksamedia/caspio-rest-api-lib
×
×
  • Create New...