Ejemplo n.º 1
0
 public function login(Request $request)
 {
     if (Auth::check()) {
         // If the user is already logged in then redirect to landing page.
         return redirect($this->landingPage());
     }
     $p = ['email' => '', 'password' => ''];
     $data = [];
     view()->share(['title' => 'Log In', 'CB_PAGE_JS' => [url('/js/mods/Cb.Notify.js')]]);
     if ($request->isMethod('post') && $request->has('submit')) {
         $p = $request->all();
         // See: https://github.com/Respect/Validation/blob/master/docs/README.md
         $checks = [];
         $checks['email'] = Valid::email()->notEmpty()->validate($p['email']);
         $checks['password'] = Valid::string()->notEmpty()->validate($p['password']);
         try {
             if (in_array(false, $checks)) {
                 throw new Exception('Some required field have invalid values');
             }
             $auth_response = App\Cb\Users::authenticate($p['email'], $p['password']);
             if (!is_object($auth_response)) {
                 if (is_numeric($auth_response)) {
                     // $auth_response <-- is user id in this context
                     $resend_link = route('resend_signup_confirmation', ['uid' => App\Crypt::urlencode($auth_response)]);
                     throw new Exception('Please verify your account. Click <a href="' . $resend_link . '">here</a> to resend the confirmation email');
                 }
                 throw new Exception('Invalid email or password');
             }
             // Successfully authenticated, save some details to session for faster access //
             $request->session()->put('current_user', $auth_response);
             $request->session()->put('current_user_type', $auth_response->type);
             App\Cb\Users\Presence::setOnline($auth_response->id);
             // Set presence as online
             return redirect($this->landingPage($auth_response->type));
         } catch (Exception $err) {
             cb_set_message($err->getMessage(), 0);
         }
     }
     $data['post'] = $p;
     return View::make('user_login', $data)->render();
 }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
 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();
 }