/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { // LM: 09-02-2015 // See: http://stackoverflow.com/questions/29115184/laravel-catch-tokenmismatchexception if ($e instanceof \Illuminate\Session\TokenMismatchException) { // If the erros is a token mismatch xplog('A token mismatch error happend', __METHOD__); /* @BOOKMARK: TODO For now just log the user out when a token mismatch happens */ return redirect(route('logout')); } // See: https://mattstauffer.co/blog/bringing-whoops-back-to-laravel-5 if ($this->isHttpException($e)) { // See: https://laracasts.com/discuss/channels/requests/laravel-5-404-page-driving-me-crazy switch ($e->getStatusCode()) { case '404': return \Response::view('errors.custom.404'); break; /* case '500': return \Response::view('errors.custom.500'); break; */ /* case '500': return \Response::view('errors.custom.500'); break; */ default: return $this->renderHttpException($e); break; } } if (config('app.debug')) { return $this->renderExceptionWithWhoops($e); } return parent::render($request, $e); }
protected function save($_property_id, $_files_array = []) { $pid = intval($_property_id); if ($pid <= 0) { xplog('Invalid property id given', __METHOD__); return false; } return App\Cb\Properties\Files::save($pid, $_files_array, 'image'); }
protected function deleteAllInstance($_path) { if (!App\Files::isFile($_path)) { xplog('File "' . $_path . '" cannot be found while trying to delete', __METHOD__); return false; } App\Files::delete($_path); $filename = basename($_path); // TODO: delete on other directories code goes here // }
protected function signUpConfirmation($_params = []) { $uid = intval($_params['uid']); if ($uid < 1) { xplog('Invalid user id "' . $uid . '"', __METHOD__); return false; } $data = ['fname' => $_params['fname'], 'email' => $_params['email'], 'confirmation_link' => route('signup_confirmation', ['uid' => App\Crypt::urlencode($uid)])]; return Mail::send('emails.signup_confirmation', $data, function ($m) use($_params) { $m->to($_params['email'], $_params['fname'])->subject('AuctionApp - verify your email address'); $m->from('*****@*****.**', 'AcutionApp'); }); }
protected function add($_user_id, $_params = []) { $uid = intval($_user_id); if ($uid < 1) { return false; } $p = array_merge(['users_id' => $uid, 'short_desc' => '', 'description' => '', 'street' => '', 'city' => '', 'state' => '', 'postcode' => '', 'lat' => '', 'lng' => '', 'num_bedrooms' => '0', 'num_bathrooms' => '0', 'num_garage' => '0', 'landarea' => '', 'floorarea' => '', 'type' => ''], $_params); $property_id = DB::table('properties')->insertGetId(['users_id' => $uid, 'short_desc' => strip_tags(trim($p['short_desc'])), 'description' => strip_tags(trim($p['description'])), 'street' => $p['street'], 'city' => $p['city'], 'state' => $p['state'], 'postcode' => $p['postcode'], 'lat' => $p['lat'], 'lng' => $p['lng'], 'num_bedrooms' => intval($p['num_bedrooms']), 'num_bathrooms' => intval($p['num_bathrooms']), 'num_garage' => intval($p['num_garage']), 'landarea' => $p['landarea'], 'floorarea' => $p['floorarea'], 'type' => $p['type']]); if (!$property_id) { xplog('Unable to add property for user"' . $uid . '"', __METHOD__); return false; } return $property_id; }
protected function add($_user_id, $_token, $_os = 'android') { $uid = intval($_user_id); $token = trim($_token); $os = trim(strtolower($_os)); if ($uid < 1) { return false; } if ($token === '') { xplog('Empty token was passed', __METHOD__); return false; } $device_id = DB::table('device_tokens')->insertGetId(['users_id' => $uid, 'token' => $token, 'os' => $os]); if (!$device_id) { xplog('Unable to add token for user "' . $uid . '"', __METHOD__); return false; } return $device_id; }
private function _getFileLastModifiedTimesIndentifier($_file_paths = array()) { // Creates a unique string identifier representing the modified times of files // passed to it as a parameter. $_file_paths = !is_array($_file_paths) ? array($_file_paths) : $_file_paths; $iden = ''; foreach ($_file_paths as $file) { if (App\Files::exists($file)) { $time = App\Files::lastModified($file); if ($time === false) { xplog('Unable to get the last modified time of file "' . $file . '"', __METHOD__); continue; } $iden .= $time; } else { xplog('Found that file "' . $file . '" does not exist when trying to get its last modified time.', __METHOD__); } } return md5($iden); }
public function message(Request $request) { $data = []; $session = $request->session(); if (!$session->has('sys_message')) { // If no message was found then redirect to homepage // xplog('No message was passed', __METHOD__); return redirect(url()); } $msg_details = $session->get('sys_message'); $data['sys_message'] = $msg_details['message']; $data['sys_message_label'] = 'Okay'; if (isset($msg_details['redirect'])) { $data['sys_message_link'] = $msg_details['redirect']; if (is_array($msg_details['redirect'])) { foreach ($msg_details['redirect'] as $label => $link) { // TODO: maybe not use a foreach here $data['sys_message_link'] = $link; $data['sys_message_label'] = $label; } } } return View::make('sys.message', $data)->render(); }
public function resendSignUpConfirmation(Request $request, $uid) { if (Auth::check()) { return redirect($this->landingPage()); } $uid = intval(App\Crypt::urldecode($uid)); if ($uid < 1) { abort(404); } // Redirect to 404 page if id is unknown $user_details = App\Cb\Users::getDetailsById($uid); if (!$user_details) { abort(404); } // Send confimation email here // $confirmation_sent = App\Cb\Notifications\Email::signUpConfirmation(['uid' => $user_details->id, 'fname' => $user_details->fname, 'email' => $user_details->email]); if (!$confirmation_sent) { xplog('Unable to send confirmation email for user "' . $user_details->id . '"'); return redirect(url() . '?00'); } // Send success message // $request->session()->flash('sys_message', ['message' => 'A verification email has been sent to ' . $user_details->email, 'redirect' => ['Sign In' => route('login')]]); return redirect(route('sys_message')); }
protected function updateUser($_post) { $p = $_post; // Fields that must be set // App\Cb\Api::mustSet($p, ['user_id', 'fname', 'lname', 'phone', 'cell', 'company_name', 'company_street', 'company_state', 'company_phone', 'company_abn', 'company_city', 'company_postcode', 'company_color']); $uid = intval($p['user_id']); if ($uid < 1) { App\Cb\Api::error('Invalid user id sent'); } $user_details = App\Cb\Users::getDetailsById($uid); if (!$user_details) { App\Cb\Api::error('Unable to find user details.'); } // See: https://github.com/Respect/Validation/blob/master/docs/VALIDATORS.md $checks = []; $checks['fname'] = Valid::string()->notEmpty()->validate($p['fname']); $checks['lname'] = Valid::string()->notEmpty()->validate($p['lname']); if (in_array(false, $checks)) { App\Cb\Api::error('Some required field(s) have invalid values.'); } // Check the logo file passed // if (isset($p['company_logo'])) { if (App\Json::isValid($p['company_logo'])) { // See: http://www.opinionatedgeek.com/dotnet/tools/Base64Encode/ $logo_details = (object) App\Json::decode($p['company_logo']); if (isset($logo_details->base64)) { // Check if file is a valid image // if (!in_array($logo_details->extension, config('cleverbons.files.allowed_images'))) { App\Cb\Api::error('Please upload a valid logo'); } $has_uploaded_a_logo = true; } } else { xplog('Invalid JSON string passed |' . $p['company_logo'] . '|', __METHOD__); } } // Update user details // $updated_user_details = App\Cb\Users::update($user_details->id, ['fname' => $p['fname'], 'lname' => $p['lname'], 'phone' => $p['phone'], 'cellphone' => $p['cell']]); if (!$updated_user_details) { App\Cb\Api::error('Unable to save user details'); } // Update user company details // $updated_company_details = App\Cb\Users\Company::update($user_details->id, ['name' => $p['company_name'], 'abn' => $p['company_abn'], 'street' => $p['company_street'], 'city' => $p['company_city'], 'state' => $p['company_state'], 'postcode' => $p['company_postcode'], 'phone' => $p['company_phone'], 'primary_color' => $p['company_color']]); if (!$updated_company_details) { App\Cb\Api::error('Unable to save company details'); } if (isset($has_uploaded_a_logo)) { // Save the uploaded logo for his/her company // // See: http://www.opinionatedgeek.com/dotnet/tools/Base64Encode/ if (!App\Cb\Users\Company::saveLogo($user_details->id, $logo_details, true)) { xplog('Unable to save logo file for user "' . $uid . '"', __METHOD__); } } // Requery the newly updated user details // $user_details = App\Cb\Users::getDetailsById($user_details->id); $res = ['api_name' => $_post['api_name'], 'payload' => ['user_details' => $user_details]]; $user_company_details = App\Cb\Users\Company::getDetailsByUserId($user_details->id); if (!!$user_company_details) { $res['payload']['company_details'] = $user_company_details; } return $res; }
protected function isMaxExceeded($_property_id, $_type = 'doc') { $pid = intval($_property_id); $type = trim(strtolower($_type)); if ($pid <= 0) { xplog('Invalid property id given', __METHOD__); return true; } $count = DB::table('property_files')->where('properties_id', $pid)->where('type', $type)->count(); return $count >= $this->num_max_file_per_type; }
public function addProperty(Request $request) { if (!Auth::check()) { return redirect(route('logout')); } if (!$request->session()->has('current_user')) { return redirect(route('logout')); } $current_user = $request->session()->get('current_user'); $data = []; view()->share(['title' => 'Add Property', 'CB_PAGE_JS' => [url('/js/mods/Cb.Notify.js')]]); $p = ['property_street' => '', 'property_state' => 'ACT', 'property_city' => '', 'property_postcode' => '', 'property_phone' => '', 'property_short_desc' => '', 'property_description' => '', 'property_type' => '', 'property_bedrooms' => '0', 'property_bathrooms' => '0', 'property_landarea' => '', 'property_floorarea' => '', 'property_garage' => '0', 'property_lat' => '00000', 'property_lng' => '00000', 'property_terms' => '1']; $data['aus_states'] = config('cleverbons.aus_states'); $data['property_types'] = App\Cb\Properties::getTypes(); if ($request->isMethod('post') && $request->has('submit')) { $p = $request->all(); // See: https://github.com/Respect/Validation/blob/master/docs/VALIDATORS.md $checks = []; $checks['property_street'] = Valid::string()->notEmpty()->validate($p['property_street']); $checks['property_state'] = Valid::string()->notEmpty()->validate($p['property_state']); $checks['property_city'] = Valid::string()->notEmpty()->validate($p['property_city']); $checks['property_postcode'] = Valid::string()->notEmpty()->validate($p['property_postcode']); $checks['property_phone'] = Valid::string()->notEmpty()->validate($p['property_phone']); $checks['property_short_desc'] = Valid::string()->notEmpty()->validate($p['property_short_desc']); $checks['property_description'] = Valid::string()->notEmpty()->validate($p['property_description']); $checks['property_type'] = Valid::string()->notEmpty()->validate($p['property_type']); $checks['property_bedrooms'] = Valid::int()->notEmpty()->validate($p['property_bedrooms']); $checks['property_bathrooms'] = Valid::int()->notEmpty()->validate($p['property_bathrooms']); $checks['property_landarea'] = Valid::string()->notEmpty()->validate($p['property_landarea']); $checks['property_floorarea'] = Valid::string()->notEmpty()->validate($p['property_floorarea']); $checks['property_garage'] = Valid::int()->notEmpty()->validate($p['property_garage']); $checks['property_lat'] = Valid::string()->notEmpty()->validate($p['property_lat']); $checks['property_lng'] = Valid::string()->notEmpty()->validate($p['property_lng']); $checks['property_terms'] = isset($p['property_terms']); try { if (in_array(false, $checks)) { throw new Exception('Some required field(s) have invalid values.'); } // Floorplan Files // if (isset($_FILES['property_floorplan_files']['name'])) { $floorplan_file_arr = App\Upload::reArrayFiles($_FILES['property_floorplan_files']); if (!App\Cb\Properties\Docs::isAllowed($floorplan_file_arr)) { throw new Exception('One or more of the floor plan files are supported'); } } // Property Images // if (isset($_FILES['property_images']['name'])) { $images_file_arr = App\Upload::reArrayFiles($_FILES['property_images']); if (!App\Cb\Properties\Images::isAllowed($images_file_arr)) { throw new Exception('One or more of the images is not supported'); } } $property_id = App\Cb\Properties::add($current_user->id, ['short_desc' => $p['property_short_desc'], 'description' => $p['property_description'], 'street' => $p['property_street'], 'city' => $p['property_city'], 'state' => $p['property_state'], 'postcode' => $p['property_postcode'], 'lat' => $p['property_lat'], 'lng' => $p['property_lng'], 'num_bedrooms' => $p['property_bedrooms'], 'num_bathrooms' => $p['property_bathrooms'], 'num_garage' => $p['property_garage'], 'landarea' => $p['property_landarea'], 'floorarea' => $p['property_floorarea'], 'type' => $p['property_type']]); if (!$property_id) { throw new Exception('Unable to add property. Please check your connection and try again.'); } // Save the floorplan docs // if (isset($floorplan_file_arr) && !App\Cb\Properties\Docs::save($property_id, $floorplan_file_arr)) { xplog('Unable to save some floor plan files for property "' . $property_id . '"', __METHOD__); } // Save the images // if (isset($images_file_arr) && !App\Cb\Properties\Images::save($property_id, $images_file_arr)) { xplog('Unable to save some images for property "' . $property_id . '"', __METHOD__); } cb_set_message('Successfully added property to your account', 1); return redirect(route('my_properties')); } catch (Exception $err) { cb_set_message($err->getMessage(), 0); } } $data['post'] = $p; return View::make('add_property', $data)->render(); }
public function myAccount(Request $request, $uid) { if (!Auth::check()) { return redirect(route('logout')); } // Make sure user is already logged in $uid = intval(App\Crypt::urldecode($uid)); if ($uid < 1) { abort(404); } // Redirect to 404 page if user id is unknown $user_details = App\Cb\Users::getDetailsById($uid); if (!$user_details) { abort(404); } // Make sure user details is available $p = ['fname' => $user_details->fname, 'lname' => $user_details->lname, 'email' => $user_details->email, 'phone' => $user_details->phone, 'cell' => $user_details->cellphone, 'company_name' => '', 'company_street' => '', 'company_state' => '', 'company_phone' => '', 'company_abn' => '', 'company_city' => '', 'company_postcode' => '', 'company_color' => '']; $company_details = App\Cb\Users\Company::getDetailsByUserId($user_details->id); if ($company_details) { $company_info = ['company_name' => $company_details->name, 'company_street' => $company_details->street, 'company_state' => $company_details->state, 'company_phone' => $company_details->phone, 'company_abn' => $company_details->abn, 'company_city' => $company_details->city, 'company_postcode' => $company_details->postcode, 'company_color' => $company_details->primary_color, 'company_logo_filename' => $company_details->logo]; $p = array_merge($p, $company_info); } //_pr($company_details); $data = []; view()->share(['title' => 'My Account', 'CB_PAGE_JS' => [url('/js/mods/Cb.Notify.js')], 'CB_JS_TRANSPORT' => ['testing' => [1, 2, 3]]]); $data['aus_states'] = config('cleverbons.aus_states'); if ($request->isMethod('post') && $request->has('submit')) { $p = $request->all(); // See: https://github.com/Respect/Validation/blob/master/docs/VALIDATORS.md $checks = []; $checks['fname'] = Valid::string()->notEmpty()->validate($p['fname']); $checks['lname'] = Valid::string()->notEmpty()->validate($p['lname']); //$checks['email'] = Valid::email()->notEmpty()->validate($p['email']); $checks['phone'] = Valid::string()->notEmpty()->validate($p['phone']); $checks['cell'] = Valid::string()->notEmpty()->validate($p['cell']); if (isset($p['company_name']) && trim($p['company_name']) !== '') { $checks['company_name'] = Valid::string()->notEmpty()->validate($p['company_name']); $checks['company_street'] = Valid::string()->notEmpty()->validate($p['company_street']); $checks['company_state'] = Valid::string()->notEmpty()->validate($p['company_state']); $checks['company_phone'] = Valid::string()->notEmpty()->validate($p['company_phone']); $checks['company_abn'] = Valid::string()->notEmpty()->validate($p['company_abn']); $checks['company_city'] = Valid::string()->notEmpty()->validate($p['company_city']); $checks['company_postcode'] = Valid::string()->notEmpty()->validate($p['company_postcode']); $checks['company_color'] = Valid::string()->notEmpty()->validate($p['company_color']); } try { if (in_array(false, $checks)) { throw new Exception('Some required field(s) have invalid values.'); } if (trim($p['email']) !== $user_details->email) { if (App\Cb\Users::emailExists($p['email'])) { throw new Exception('Sorry the email address your provided is already registered in our system.'); } } if (isset($_FILES['company_logo']['name']) && trim($_FILES['company_logo']['name']) !== '') { $uploaded_image_ext = App\Upload::getExtension($_FILES['company_logo']); // Check if file is a valid image // if (!in_array($uploaded_image_ext, config('cleverbons.files.allowed_images'))) { throw new Exception('Please upload a valid logo.'); } $has_uploaded_a_logo = true; } // Update user details // $updated_user_details = App\Cb\Users::update($user_details->id, ['fname' => $p['fname'], 'lname' => $p['lname'], 'phone' => $p['phone'], 'cellphone' => $p['cell']]); if (!$updated_user_details) { throw new Exception('Unable to save your details. Please reload your page and try again.'); } // Update user company details // $updated_company_details = App\Cb\Users\Company::update($user_details->id, ['name' => $p['company_name'], 'abn' => $p['company_abn'], 'street' => $p['company_street'], 'city' => $p['company_city'], 'state' => $p['company_state'], 'postcode' => $p['company_postcode'], 'phone' => $p['company_phone'], 'primary_color' => $p['company_color']]); if (!$updated_company_details) { throw new Exception('Unable to save your company details. Please reload your page and try again.'); } // Update the user's logo file here // if (isset($has_uploaded_a_logo)) { // Save the uploaded logo for his/her company // $logo_filename = App\Cb\Users\Company::saveLogo($user_details->id, $_FILES['company_logo']); if (!$logo_filename) { xplog('Unable to save logo file for user "' . $user_details->id . '"', __METHOD__); } $p['company_logo_filename'] = $logo_filename; } // Successfully updated everything // cb_set_message('Successfully updated your details', 1); } catch (Exception $err) { cb_set_message($err->getMessage(), 0); } } $data['logo_dir'] = App\Cb\Users\Company::getLogoDirBaseUri(); $data['post'] = $p; return View::make('myaccount', $data)->render(); }
protected function download($_path) { if (!App\Files::isReadable($_path)) { xplog('Unable to read file "' . $_path . '" when trying to download', __METHOD__); return ''; } $file_size = filesize($_path); $file_contents = App\Files::get($_path); $file_name = basename($_path); header("Content-length: " . $file_size); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $file_name . '"'); return $file_contents; }
public function log($_msg) { // See: https://github.com/pusher/pusher-http-php#debugging--logging xplog('PUSHER LOG: ' . $_msg, __METHOD__); }
<?php /* Cron sepcific routes only */ Route::group(['prefix' => 'cron'], function () { // Check if cron ran // Route::get('/attendance/log', function () { xplog('Cron ran!'); return 'Cron ran!'; }); });
protected function update($_user_id, $_data = []) { $uid = intval($_user_id); if ($uid < 1) { return false; } if (!$this->getDetailsByUserId($uid)) { // If user has not added any company details, then add a // row first before doing an update. DB::table('user_company_details')->insert(['users_id' => $uid, 'primary_color' => '#cccccc']); } $row = DB::table('user_company_details')->where('users_id', $uid)->update($_data); if (!is_numeric($row)) { xplog('Unable to update user_details table for user "' . $uid . '"', __METHOD__); return false; } return true; }
protected function testPusher($_post) { $p = $_post; $this->req($p, ['data']); // See: http://www.smashingmagazine.com/2012/05/building-real-time-commenting-system/ // See: https://github.com/pusher/pusher-http-php $app_id = '149666'; $app_key = '768422d844cb5acf6d6e'; $app_secret = '2f685782367009dec1bf'; $pusher = new Pusher($app_key, $app_secret, $app_id); // See: https://github.com/pusher/pusher-http-php#debugging--logging $pusher->set_logger(new App\Cb\RealTime\Logger()); $pusher->trigger('currentBID_channel', 'currentBID_event', App\Json::decode($p['data'])); xplog('API PUSHER TRIGGER: ' . App\Json::encode($p)); xplog('DATA: ' . $p['data']); xplog('API PUSHER CHANNELS: ' . App\Json::encode($pusher->get_channels())); return ['api_name' => $_post['api_name'], 'payload' => 1]; }
protected function update($_user_id, $_data = []) { $uid = intval($_user_id); if ($uid < 1) { return false; } // We only update the user_details table here as the users table should only be // updated by the code not the user. $row = DB::table('user_details')->where('users_id', $uid)->update($_data); if (!is_numeric($row)) { xplog('Unable to update user_details table for user "' . $uid . '"', __METHOD__); return false; } return true; }