function updateContact($id) { $request = Slim\Slim::getInstance()->request(); $id = intval($id); verifyRequiredParams(array(CONTACTS::NAME, CONTACTS::NUMBER)); $name = trim($request->put(CONTACTS::NAME)); $email = strtolower(trim($request->put(CONTACTS::EMAIL))); $number = $request->put(CONTACTS::NUMBER); $is_favourite = $request->put(CONTACTS::IS_FAVOURITE); $is_favourite = $is_favourite === 'true' ? true : false; $contact = array(CONTACTS::NAME => $name, CONTACTS::EMAIL => $email, CONTACTS::NUMBER => $number, CONTACTS::IS_FAVOURITE => $is_favourite); $contact = removeEmptyFields($contact); $query = new QueryHandler(); $response = $query->updateContact($id, $contact); echoRespnse($response); }
} else { if ($res == ISSUE_LOG_FAILED) { $response["error"] = true; $response["message"] = 'Oops! We are unable to log an issue for this spot.'; } else { if ($res == ISSUE_FOR_SPOT_ALREADY_EXISTS) { $response["error"] = true; $response["message"] = 'An issue has already been logged for this spot'; } } } // echo json response echoRespnse(201, $response); }); $app->post('/addSpotRequest', function () use($app) { verifyRequiredParams(array('userId', 'spotName', 'regionName', 'country')); $response = array(); // reading post params //$email = $app->request()->post('email'); //$user_id = $app->request()->post('userId'); $spotName = $app->request()->post('spotName'); $regionName = $app->request()->post('regionName'); $country = $app->request()->post('country'); //global $user_id; $db = new DbHandler(); $user = $db->getUserById($user_id); global $EmailAdmin; global $EmailFrom; $EmailTo = $EmailAdmin; $Subject = "A user has submitted a request to Add a Spot"; // prepare email body text
echoRespnse(201, $response); } else { $response["error"] = true; $response["message"] = "Failed to create contact. Please try again"; echoRespnse(200, $response); } }); /** * Updating existing contact * method PUT * params contact, status * url - /contacts/:id */ $app->put('/contacts/:id', 'authenticate', function ($contact_id) use($app) { // check for required params verifyRequiredParams(array('contact', 'status')); global $user_id; $contact = $app->request->put('contact'); $status = $app->request->put('status'); $db = new DbHandler(); $response = array(); // updating task $result = $db->updateTask($user_id, $contact_id, $contact, $status); if ($result) { // contact updated successfully $response["error"] = false; $response["message"] = "Contact updated successfully"; } else { // contact failed to update $response["error"] = true; $response["message"] = "Contact failed to update. Please try again!";
$response["createdAt"] = $result["created_at"]; echoRespnse(200, $response); } else { $response["error"] = true; $response["message"] = "The requested resource doesn't exists"; echoRespnse(404, $response); } }); /** * Adding sample data points to Journeys data table * method PUT * url - //:id */ $app->post('/journey/:id', 'authenticate', function ($journey_id) use($app) { // check for required params verifyRequiredParams(array('x_gps', 'y_gps', 'x_acl', 'y_acl', 'z_acl', 'timestamp', 'sample_no')); // reading post params $x_gps = $app->request->post('x_gps'); $y_gps = $app->request->post('y_gps'); $x_acl = $app->request->post('x_acl'); $y_acl = $app->request->post('y_acl'); $z_acl = $app->request->post('z_acl'); $timestamp = $app->request->post('timestamp'); $sample_no = $app->request->post('sample_no'); $response = array(); global $user_id; // Admin is user 1. Special privedges // but cant post sample points if ($user_id == 1) { $response["error"] = false; $response["message"] = "Admin can only view journeys";
$_SESSION['email'] = $email; $_SESSION['name'] = $user['name']; } else { $response['status'] = "error"; $response['message'] = 'Login failed. Incorrect credentials'; } } else { $response['status'] = "error"; $response['message'] = 'No such user is registered'; } echoResponse(200, $response); }); $app->post('/signUp', function () use($app) { $response = array(); $r = json_decode($app->request->getBody()); verifyRequiredParams(array('email', 'name', 'password'), $r->user); require_once 'passwordHash.php'; $db = new DbHandler(); $phone = $r->user->phone; $name = $r->user->name; $email = $r->user->email; $address = $r->user->address; $password = $r->user->password; $isUserExists = $db->getOneRecord("select 1 from users where phone='{$phone}' or email='{$email}'"); if (!$isUserExists) { $r->user->password = passwordHash::hash($password); $tabble_name = "users"; $column_names = array('phone', 'name', 'email', 'password', 'city', 'address'); $result = $db->insertIntoTable($r->user, $column_names, $tabble_name); if ($result != NULL) { $response["status"] = "success";
$response["code"] = $status; $response["message"] = "Contingent {$contingent->getId()} updated successfully."; } else { $status = 200; $response["code"] = $status; $response["error"] = 1; $response["error_message"] = "Some error occured while updating contingent {$contingent->getId()}."; } } else { $response["error"] = 1; $response["error_message"] = "Invalid ID,Expecting numeric ID"; } print json_encode($response); }); $app->put('/event/:id', function ($id) use($app, $eventMapper) { verifyRequiredParams(array('id', 'logo')); $event = new Event(); $event->setId($id); $event->setName($app->request()->put('name')); $event->setDetails($app->request()->put('details')); $event->setSlogan($app->request()->put('slogan')); $event->setCategory($app->request()->put('type')); $event->setRules($app->request()->put('rules')); $event->setStartDate($app->request()->put('start_date')); $event->setEndDate($app->request()->put('end_date')); $event->setStartTime($app->request()->put('start_time')); $event->setEndTime($app->request()->put('end_time')); $event->setGroupSize($app->request()->put('group_size')); $event->setLogo($app->request()->put('logo')); # --Getting the put vars and typecasting to int. Blehhh. Can't help, its PHP xD $feeHome = $app->request()->put('fee_home');
if ($res == USER_CREATE_FAILED) { $response["error"] = true; $response["message"] = "Oops! An error occurred while registereing"; echoRespnse(200, $response); } else { if ($res == USER_ALREADY_EXISTED) { $response["error"] = true; $response["message"] = "Sorry, this email already existed"; echoRespnse(200, $response); } } } }); $app->post('/addproject', function () use($app) { // check for required params verifyRequiredParams(array('name', 'start_date', 'end_date', 'description', 'team_lead', 'target_audience', 'estimated_funds')); $response = array(); $name = $app->request->post('name'); $start_date = $app->request->post('start_date'); $end_date = $app->request->post('end_date'); $description = $app->request->post('description'); $team_lead = $app->request->post('team_lead'); $target_audience = $app->request->post('target_audience'); $estimated_funds = $app->request->post('estimated_funds'); $db = new DbHandler(); $res = $db->addProject($name, $start_date, $end_date, $description, $team_lead, $target_audience, $estimated_funds); if ($res != PROJECT_CREATE_FAILED) { $response["error"] = false; $response["message"] = "project successfully registered with id" + $res; echoRespnse(201, $response); } else {
} } else { // user credentials are wrong $response['error'] = true; $response['message'] = 'Login failed. Incorrect credentials'; } echoRespnse(200, $response); }); /** * Listing single task of list mk * method GET * url /listmk * Will return 404 if the task doesn't belongs to user */ $app->get('/listmk/:id', function ($id) { verifyRequiredParams(array('id')); // reading post params // $id = $app->request()->get('id'); $response = array(); $db = new DbHandler(); // fetch task $result = $db->getMK($id); // looping through result and preparing tasks array while ($task = $result->fetch_assoc()) { $tmp = array(); $tmp["id"] = $task["id"]; $tmp["task"] = $task["task"]; $tmp["status"] = $task["status"]; $tmp["createdAt"] = $task["created_at"]; array_push($response["listmk"], $tmp); }
break; case USER_CREATED_SUCCESSFULLY: $response["error"] = false; $response["message"] = "You are successfully registered"; echoResponse(201, $response); break; default: $response["error"] = true; $response["message"] = "An error occurred while registering"; echoResponse(200, $response); break; } }); $app->post('/login', function () use($app) { // check for required params verifyRequiredParams(array('email', 'password')); // reading post params $body = json_decode($app->request->getBody(), true); $email = $body['email']; $password = $body['password']; $response = array(); $db = new DbHandler(); // check for correct email and password if ($db->checkLogin($email, $password)) { // get the user by email $response = $db->getUserByEmail($email); if ($response != NULL) { $response["error"] = false; } else { // unknown error occurred $response['error'] = true;
* error: false * message: "Benutzer wurde erfolgreich hinzugefügt" * } * @apiSuccessExample Error (Beispiel): * { * error: true * message: 'Fehler! Benutzer/Kartensatz konnte nicht gefunden werden.' * } * * @apiSuccessExample CURL Beispiel: * curl -H "Authorization: ce0783ccae32b2eddf9d49a6c8592dfb" -X POST -d "username=vogt" -d "persmission=1" http://karta.dima23.de/api/index.php/permission/12 */ $app->post('/permission/:cardsetid', 'authenticate', function ($cardsetid) use($app) { $response = array(); verifyRequiredParams(array('username')); verifyRequiredParams(array('permission')); $username = $app->request->post('username'); $permission = $app->request->post('permission'); $db = new DBHandler(); $userid = $db->getUser($username); $result = $db->assignUserCardset($userid['userid'], $cardsetid, $permission); if ($result != NULL) { $response["error"] = false; $response['message'] = "Benutzer wurde erfolgreich hinzugefügt"; echoRespnse(200, $response); } else { $response["error"] = true; $response["message"] = "Fehler! Benutzer/Kartensatz konnte nicht gefunden werden." . $result; echoRespnse(201, $response); } });
$response['error'] = FALSE; $response['message'] = "successfully Liked"; } else { $response['error'] = TRUE; $response['message'] = "Unsuccessful like addition"; } } else { $response['error'] = TRUE; $response['message'] = "No previous value to dislike or bad value"; } } echoRespnse(200, $response); }); /* add/update rating to tv_series */ $app->post('/collection/:id/rating', 'authenticate', function ($id_tv_series) use($app) { verifyRequiredParams(array('rating_value')); $rating_value = $app->request()->post('rating_value'); global $user_id; $response = []; $db = new DbHandler(); $rating_id = $db->isRatingAvailable($id_tv_series, $user_id); if ($rating_value <= 5 && $rating_value >= 0) { if ($rating_id) { if ($db->updateRating($rating_id["id_rating"], $rating_value)) { $response['error'] = FALSE; $response['message'] = "successfully updated rating"; } else { $response['error'] = TRUE; $response['message'] = "Updating rating unsuccessful"; } } else {
} else { $response['status'] = "info"; $response['message'] = 'No fue posible agregar los datos'; } } else { $response['status'] = "info"; $response['message'] = 'El usuario ya existe'; } echoResponse(200, $response); }); // $app->post('/userU', 'sessionAlive', function () use($app) { // Recupera los datos de la forma // $r = json_decode($app->request->getBody()); verifyRequiredParams(array('id', 'nombre', 'nombres', 'apellidos', 'idrol', 'idorganizacion', 'estado', 'email', 'cargo'), $r->user); // $id = $r->user->id; $nombre = $r->user->nombre; $nombres = $r->user->nombres; $apellidos = $r->user->apellidos; $idrol = $r->user->idrol; $idorganizacion = $r->user->idorganizacion; $estado = $r->user->estado; $email = $r->user->email; $cargo = $r->user->cargo; $response = array(); // // // Ejemplo de uso de un insert: //
<?php $app->get('/event/external/:eventId', function ($eventId) use($app) { // check for required params verifyRequiredParams(array('source')); $source = $app->request->params('source'); $model = new findEventModel($eventId, $source, $app); $json_response = $model->getJsonWithChecksum(); $app->contentType('application/json'); echo $json_response; });
<?php /** * Creating new call in db * method POST * params - name * url - /calls/ */ $app->post('/calls', 'authenticate', function () use($app) { // check for required params verifyRequiredParams(array('call')); $response = array(); $call = $app->request->post('call'); global $user_id; $db = new Calls(); // creating new call $call_id = $db->createCall($user_id, $call); if ($call_id != NULL) { $response["error"] = false; $response["message"] = "Call created successfully"; $response["call_id"] = $call_id; } else { $response["error"] = true; $response["message"] = "Failed to create call. Please try again"; } echoRespnse(201, $response); }); /** * Listing all calls of particual user * method GET * url /calls
echoRespnse(200, $response); } else { $response["error"] = true; $response["message"] = "The requested resource doesn't exists"; echoRespnse(404, $response); } }); /** * Updating existing task * method PUT * params task, status * url - /tasks/:id */ $app->put('/tasks/:id', 'authenticate', function ($task_id) use($app) { // check for required params verifyRequiredParams(array('task', 'status'), $app->request->put()); global $user_id; $task = $app->request->put('task'); $status = $app->request->put('status'); $db = new DbHandler(); $response = array(); // updating task $result = $db->updateTask($user_id, $task_id, $task, $status); if ($result) { // task updated successfully $response["error"] = false; $response["message"] = "Task updated successfully"; } else { // task failed to update $response["error"] = true; $response["message"] = "Task failed to update. Please try again!";
echoRespnse(201, $response); } else { $response["error"] = true; $response["message"] = "Failed to create company. Please try again"; echoRespnse(200, $response); } }); /** * Updating existing company * method PUT * params company, status * url - /companies/:id */ $app->put('/companies/:id', 'authenticate', function ($company_id) use($app) { // check for required params verifyRequiredParams(array('name', 'status')); global $user_id; $name = $app->request->put('name'); $status = $app->request->put('status'); $db = new DbHandler(); $response = array(); // updating company $result = $db->updateCompany($company_id, $name, $status); if ($result) { // company updated successfully $response["error"] = false; $response["message"] = "company updated successfully"; } else { // company failed to update $response["error"] = true; $response["message"] = "company failed to update. Please try again!";
echoResponse(200, $response); } else { $response["status"] = "error"; $response["message"] = "Failed to create customer. Please try again"; echoResponse(201, $response); } } else { $response["status"] = "error"; $response["message"] = "An user with the provided phone or email exists!"; echoResponse(201, $response); } }); $app->post('/forgotPassword', function () use($app) { $response = array(); $r = json_decode($app->request->getBody()); verifyRequiredParams(array('email'), $r->customer); require_once 'passwordHash.php'; $db = new DbHandler(); $email = $r->customer->email; /* Checking existing email address in database */ $isUserExists = $db->getOneRecord("select 1 from customers_auth where email='{$email}'"); if ($isUserExists) { if ($email) { $response["status"] = "success"; $response["message"] = "Thank you. We have sent you password on your email address " . $email; echoResponse(200, $response); $to = '*****@*****.**'; // this is your Email address $from = $email; // this is the sender's Email address $subject = "Password for login";
echoRespnse(201, $response); } else { $response["error"] = true; $response["message"] = "Failed to create alert. Please try again"; echoRespnse(200, $response); } }); /** * Updating existing alert * method PUT * params alert, status * url - /alerts/:id */ $app->put('/alerts/:id', 'authenticate', function ($alert_id) use($app) { // check for required params verifyRequiredParams(array('alert', 'status')); global $user_id; $alert = $app->request->put('alert'); $status = $app->request->put('status'); $db = new DbHandler(); $response = array(); // updating alert $result = $db->updatealert($user_id, $alert_id, $alert, $status); if ($result) { // alert updated successfully $response["error"] = false; $response["message"] = "alert updated successfully"; } else { // alert failed to update $response["error"] = true; $response["message"] = "alert failed to update. Please try again!";
validateEmail($admin_email); $query = $db->admin_restoran->where("admin_username LIKE ?", $admin_email); if ($query->count("*") < 1) { $add = $db->admin_restoran->insert(array("restoran_id" => $restoran_id, "admin_username" => $admin_username, "admin_email" => $admin_email, "admin_password" => $password_hash, "admin_api" => $admin_api)); if ($add != null) { echo json_encode(array("status" => true, "message" => "success add new admin")); } else { echo json_encode(array("status" => false, "message" => "failed to add new admin")); } } else { echo json_encode(array("status" => false, "message" => "email is already exist")); } }); /* login (admin restoran)*/ $app->post('/admin_restoran', function () use($app, $db) { verifyRequiredParams(array('admin_email', 'admin_api')); $admin_email = $app->request->post('admin_email'); $admin_api = $app->request->post('admin_api'); $query = $db->admin_restoran->where("admin_username LIKE ?", $admin_email); if ($query->count("*") > 0) { foreach ($query as $value) { echo json_encode(array("status" => true, "message" => "success login")); } } else { echo json_encode(array("status" => false, "message" => "email is not exist")); } }); $app->put('/admin_restoran/:key', function ($key) use($app, $db) { $query = $db->admin_restoran->where("admin_id", $key); if ($query->fetch()) { $post = $app->request->put();
function updateRememberMeField($fieldName) { $response = array(); global $app; verifyRequiredParams(array('fieldValue')); $fieldValue = $app->request->params('fieldValue'); $db = new RememberMeDbHandler(); $result = $db->updateRememberMeField($fieldName, $fieldValue); if ($result) { $response["error"] = false; $response["message"] = "RememberMe field : " . $fieldName . " updated successfully"; } else { $response["error"] = true; $response["message"] = "RememberMe field : " . $fieldName . " was NOT updated because it was not found. Please try again!"; } echoResponse(200, $response); }
$tmp["proyectoID"] = $project["proyectoID"]; $tmp["categoria"] = $project["categoria"]; $tmp["ciudad"] = $project["ciudad"]; $tmp["estado"] = $project["estado"]; $tmp["usuarioID"] = $project["usuarioID"]; $tmp["usuario"] = $project["usuario"]; $tmp["urlImage"] = $project["url_image"]; array_push($response["message"], $tmp); } echoRespnse(200, $response); }); //crear nuevo proyecto // $app->post('/projects', function () use($app) { // check for required params verifyRequiredParams(array('task')); $response = array(); $projectID = $app->request->post('proyectoID'); $nombre = $app->request->post('nombre'); $descripcionLarga = $app->request->post('descripcionLarga'); $descripcionCorta = $app->request->post('descripcionCorta'); $monto = $app->request->post('monto'); $diasvigencia = $app->request->post('diasvigencia'); $urlImage = $app->request->post('urlImage'); $categoria = $app->request->post('categoria'); $ciudad = $app->request->post('ciudad'); $estado = $app->request->post('estado'); $socialID = $app->request->post('socialID'); $db = new DbHandler(); // creating new task $task_id = $db->createProject($projectID, $nombre, $descripcionLarga, $descripcionCorta, $monto, $diasvigencia, $urlImage, $categoria, $ciudad, $estado, $socialID);
die('Error:' . mysqli_error($con)); } // echo json response echoRespnse(201, $response); }); /************************************************************** * Update heart beat * url - /hb * method - PUT * params: data **************************************************************/ $app->put('/hb', 'authenticate', function () use($app) { global $con, $host, $user, $password, $db, $valid_chars, $user_id; $response = array(); // check for required params verifyRequiredParams(array('data')); $data = mysqli_real_escape_string($con, $app->request->post('data')); $query = "UPDATE sensors SET Data = '" . $data . "', Date = NOW() WHERE Type = 'HB' AND users_UserID = '" . $user_id . "' AND Date >= '" . date('Y-m-d') . ' 00:00:00' . "' AND Date < '" . date('Y-m-d') . ' 23:59:59' . "'"; //Execute Query if (mysqli_query($con, $query)) { $response["error"] = false; $response["message"] = "Record was updated successfully."; } else { $response["error"] = true; $response["message"] = "An error occured try again."; } echoRespnse(200, $response); }); /************************************************************** * Delete heart beat * url - /hb
} } else { echo json_encode(array('status' => false, 'Message' => 'User is not Correct')); } } else { echo json_encode(array('status' => false, 'Message' => 'Login not Successfull')); } }); $app->post('/cashwithdraw', function () use($app) { $app->response()->header("Content-Type", "application/json"); $name = $app->request->post('name'); $password = $app->request->post('password'); $user_id = $app->request->post('userId'); $pin = $app->request->post('pin'); $amount = $app->request->post('amount'); verifyRequiredParams(array('name', 'password', 'userId', 'pin', 'amount')); $status = login($name, $password); if ($status) { $status = verifyUser($user_id); if ($status) { $status = VerifyPin($user_id, $pin); if ($status) { $status = cashWithDraw($user_id, $amount); if ($status) { echo json_encode(array('status' => true, 'Message' => 'Case withdraw successfull')); } else { echo json_encode(array('status' => false, 'Message' => 'Case withdraw not successfull')); } } else { echo json_encode(array('status' => false, 'Message' => 'Pin is not correct')); }
echoRespnse(200, $response); } else { $response["error"] = true; $response["message"] = "The requested resource doesn't exists"; echoRespnse(404, $response); } }); /** * Updating existing task * method PUT * params task, status * url - /tasks/:id */ $app->put('/tasks/:id', 'authenticate', function ($task_id) use($app) { // check for required params verifyRequiredParams(array('task', 'status')); global $user_id; $task = $app->request->put('task'); $status = $app->request->put('status'); $db = new DbHandler(); $response = array(); // updating task $result = $db->updateTask($user_id, $task_id, $task, $status); if ($result) { // task updated successfully $response["error"] = false; $response["message"] = "Task updated successfully"; } else { // task failed to update $response["error"] = true; $response["message"] = "Task failed to update. Please try again!";
$_SESSION['name'] = $user['name']; $_SESSION['role'] = $user['role']; } else { $response['status'] = "error"; $response['message'] = 'Login failed. Incorrect credentials'; } } else { $response['status'] = "error"; $response['message'] = 'User is unregistered or inactive. Check email if registered.'; } echoResponse(200, $response); }); $app->post('/signUp', function () use($app) { $response = array(); $r = json_decode($app->request->getBody()); verifyRequiredParams(array('email', 'name', 'password', 'work_phone', 'DOB', 'role', 'companyname'), $r->customer); require_once 'passwordHash.php'; $db = new DbHandler(); try { $work_phone = $r->customer->work_phone; } catch (Exception $e) { $work_phone = ""; } try { $mobile_phone = $r->customer->mobile_phone; } catch (Exception $e) { $mobile_phone = ""; } $format = 'm/d/Y'; $DOB = $r->customer->DOB; $d = DateTime::createFromFormat($format, $DOB);
function updateSportTypeById($id) { verifyRequiredParams(array('name')); global $app; $name = $app->request->params('name'); $db = new SportTypeDbHandler(); $response = array(); $user = array(); $user["id"] = $id; $user["name"] = $name; $result = $db->updateSportType($user); if ($result) { $response["error"] = false; $response["message"] = "Sport type with id: " . $id . " was updated successfully"; } else { $response["error"] = true; $response["message"] = "Sport type with id: " . $id . "was NOT updated because it was not found. Please try again!"; } echoResponse(200, $response); }
} else { // category failed to delete $response["error"] = true; $response["message"] = "Category failed to delete. Please try again!"; } echoRespnse(200, $response); }); /** * Create Articles * url - /articles * method - POST * params - category_name, category_description */ $app->post('/categories/:id/articles', 'authenticate', function ($cat_id) use($app) { // check for required params verifyRequiredParams(array('article_title', 'article_image', 'author_name', 'article_content')); // reading post params $article_title = $app->request()->post('article_title'); $article_image = $app->request()->post('article_image'); $author_name = $app->request()->post('author_name'); // $date_published = $app->request()->post('date_published'); $article_content = $app->request()->post('article_content'); $response = array(); $db = new DbHandler(); $res = $db->createArticle($cat_id, $article_title, $article_image, $author_name, $article_content); if ($res == 0) { $response["error"] = false; $response["message"] = "Article successfully created"; } else { if ($res == 1) { $response["error"] = true;
<?php /** * Register a new user * * By Kai Rune Orten */ $app->post('/register', function () use($app) { $r = json_decode($app->request->getBody()); verifyRequiredParams(array('phone', 'birth'), $r->user); validateRequest($r->user); $db = new DbHandler(); $tabble_name = "user"; $phone = $r->user->phone; $birth = $r->user->birth; //We need to format the date to MySQL standard yyyy-mm-dd. $r->user->birth = Date('Y-m-d', strtotime($birth)); //If we dont care if the user register multiple time, remove the following function and condition $userExists = $db->getOneRecord("select 1 from {$tabble_name} where phone='{$phone}'"); if (!$userExists) { $column_names = array('first_name', 'last_name', 'email', 'phone', 'birth'); $result = $db->insertIntoTable($r->user, $column_names, $tabble_name); if ($result !== NULL) { $response["status"] = "success"; $response["message"] = array("Registrering fullført"); echoResponse(200, $response); } else { $response["status"] = "error"; $response["message"] = array("En feil oppstod i registreringen, vennligst prøv igjen"); echoResponse(200, $response); }
// Params: userid (required, passed as :userid in URL) // lastname, firstname, phone1, phone2, phone3, email, adminowndevices, // readaccess, writeaccess, deleteaccess, contactadmin, rackrequest, // rackadmin, siteadmin // Returns: record as created // $app->put('/people/:userid', function ($userid) use($app, $person) { if (!$person->ContactAdmin) { $response['error'] = true; $response['errorcode'] = 400; $response['message'] = "Insufficient privilege level"; echoResponse(200, $response); $app->stop(); } // Only one field is required - all others are optional verifyRequiredParams(array('UserID')); $response = array(); $p = new People(); $p->UserID = $app->request->put('UserID'); if ($p->GetPersonByUserID()) { $response['error'] = true; $response['errorcode'] = 403; $response['message'] = __("UserID already in database. Use the update API to modify record."); echoResponse(200, $response); } else { // Slim Framework will simply return null for any variables that were not passed, so this is safe to call without blowing up the script foreach ($p as $prop) { $p->{$prop} = $app->request->put($prop); } $p->Disabled = false; $p->CreatePerson();
/** * Creating new generator in db * method POST * params - name * url - /generators/ */ function createAGenerator() { $app = \Slim\Slim::getInstance(); // check for required params verifyRequiredParams(array('name', 'ramp', 'dc', 'onbar')); $response = array(); $name = json_decode($app->request()->getBody())->name; $ramp = json_decode($app->request()->getBody())->ramp; $dc = json_decode($app->request()->getBody())->dc; $onbar = json_decode($app->request()->getBody())->onbar; $db = new DbHandler(); // creating new name $gen_id = $db->createAGeneratorName($name, $ramp, $dc, $onbar); if ($gen_id != NULL) { $response["error"] = false; $response["message"] = "Generator created successfully"; $response["name_id"] = $gen_id; echoResponse(201, $response); } else { $response["error"] = true; $response["message"] = "Failed to create generator. Please try again"; echoResponse(200, $response); } }