Esempio n. 1
0
 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'));
 }
Esempio n. 2
0
 protected function addUser($_post)
 {
     $p = $_post;
     $defaults = ['fname' => '', 'lname' => '', 'email' => '', 'password' => '', 'cpassword' => '', 'phone' => '', 'cell' => '', 'is_agent' => '0', 'company_name' => '', 'company_street' => '', 'company_state' => 'ACT', 'company_phone' => '', 'company_abn' => '', 'company_city' => '', 'company_postcode' => '', 'company_color' => '', 'terms' => '0'];
     // Required user details //
     App\Cb\Api::req($p, ['email', 'password', 'cpassword', 'fname', 'lname', 'phone', 'terms']);
     $has_company = isset($p['company_name']) && trim($p['company_name']) !== '' || isset($p['is_agent']) && intval($p['is_agent']);
     if ($has_company) {
         // Required company details //
         App\Cb\Api::req($p, ['company_name', 'company_abn', 'company_phone']);
     }
     $p = array_merge($defaults, $p);
     // 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['password'] = Valid::string()->notEmpty()->validate($p['password']);
     $checks['cpassword'] = Valid::string()->notEmpty()->equals($p['password'])->validate($p['cpassword']);
     // Check password confirmation
     $checks['phone'] = Valid::string()->notEmpty()->validate($p['phone']);
     $checks['terms'] = isset($p['terms']) && intval($p['terms']);
     if (in_array(false, $checks)) {
         $err_msg = 'Some required field(s) have invalid values.';
         if ($checks['terms'] === false) {
             $err_msg = 'Terms and conditions need to be set';
         }
         if ($checks['cpassword'] === false && trim($p['password']) !== '') {
             $err_msg = 'Password mismatch.';
         }
         App\Cb\Api::error($err_msg);
     }
     if (App\Cb\Users::emailExists($p['email'])) {
         App\Cb\Api::error('Sorry the email address your provided is already registered in our system.');
     }
     // Check the logo file passed //
     if (isset($p['company_logo'])) {
         if (App\Json::isValid($p['company_logo'])) {
             $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__);
         }
     }
     $user_id = App\Cb\Users::add(['email' => $p['email'], 'password' => $p['password'], 'fname' => $p['fname'], 'lname' => $p['lname'], 'phone' => $p['phone'], 'cellphone' => $p['cell']]);
     if (!$user_id) {
         App\Cb\Api::error('Unable to save details.');
     }
     if ($has_company) {
         // Save the company details first //
         $company_details = App\Cb\Users\Company::add($user_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'], 'logo' => '', 'primary_color' => $p['company_color']]);
         if (!$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_id, $logo_details, true)) {
                 xplog('Unable to save logo file for user "' . $user_id . '"', __METHOD__);
             }
         }
     }
     // Send confimation email here //
     $confirmation_sent = App\Cb\Notifications\Email::signUpConfirmation(['uid' => $user_id, 'fname' => $p['fname'], 'email' => $p['email']]);
     if (!$confirmation_sent) {
         xplog('Unable to send confirmation email for user "' . $user_id . '"');
         App\Cb\Api::error('Unable to send your confirmation email.');
     }
     $user_details = App\Cb\Users::getDetailsById($user_id);
     $res = ['api_name' => $_post['api_name'], 'payload' => ['user_details' => $user_details]];
     if ($has_company) {
         $company_details = App\Cb\Users\Company::getDetailsByUserId($user_id);
         if (!$company_details) {
             xplog('Unable to find company details for user "' . $user_id . '"', __METHOD__);
         }
         $res['payload']['company_details'] = $company_details;
     }
     return $res;
 }
Esempio n. 3
0
 public function signup(Request $request)
 {
     if (Auth::check()) {
         // If the user is already logged in then redirect to landing page.
         return redirect($this->landingPage());
     }
     $p = ['fname' => '', 'lname' => '', 'email' => '', 'password' => '', 'cpassword' => '', 'phone' => '', 'cell' => '', 'is_agent' => '0', 'company_name' => '', 'company_street' => '', 'company_state' => 'ACT', 'company_phone' => '', 'company_abn' => '', 'company_city' => '', 'company_postcode' => '', 'company_color' => '', 'terms' => '1'];
     $data = [];
     view()->share(['title' => 'Sign Up', 'CB_PAGE_JS' => [url('/js/mods/Cb.Notify.js')]]);
     $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/README.md
         // 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['password'] = Valid::string()->notEmpty()->validate($p['password']);
         $checks['cpassword'] = Valid::string()->notEmpty()->equals($p['password'])->validate($p['cpassword']);
         // Check password confirmation
         $checks['phone'] = Valid::string()->notEmpty()->validate($p['phone']);
         $checks['cell'] = Valid::string()->notEmpty()->validate($p['cell']);
         if (isset($p['is_agent']) && intval($p['is_agent']) === 1) {
             $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']);
         }
         $checks['terms'] = isset($p['terms']);
         try {
             if (in_array(false, $checks)) {
                 $err_msg = 'Some required field(s) have invalid values.';
                 if ($checks['terms'] === false) {
                     $err_msg = 'You did not agree to the terms and conditions.';
                 }
                 if ($checks['cpassword'] === false && trim($p['password']) !== '') {
                     $err_msg = 'Password mismatch.';
                 }
                 throw new Exception($err_msg);
             }
             if (App\Cb\Users::emailExists($p['email'])) {
                 throw new Exception('Sorry the email address your provided is already registered in our system.');
             }
             if (isset($p['is_agent']) && intval($p['is_agent']) === 1) {
                 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;
                 }
             }
             $user_id = App\Cb\Users::add(['email' => $p['email'], 'password' => $p['password'], 'fname' => $p['fname'], 'lname' => $p['lname'], 'phone' => $p['phone'], 'cellphone' => $p['cell']]);
             if (!$user_id) {
                 throw new Exception('Unable to save your details. Please check your connection and try again.');
             }
             if (isset($p['is_agent']) && intval($p['is_agent']) === 1) {
                 // Save the company details first //
                 $company_details = App\Cb\Users\Company::add($user_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'], 'logo' => '', 'primary_color' => $p['company_color']]);
                 if (!$company_details) {
                     throw new Exception('Unable to save your company details. Please check your connection and try again.');
                 }
                 if (isset($has_uploaded_a_logo)) {
                     // Save the uploaded logo for his/her company //
                     if (!App\Cb\Users\Company::saveLogo($user_id, $_FILES['company_logo'])) {
                         xplog('Unable to save logo file for user "' . $user_id . '"', __METHOD__);
                     }
                 }
             }
             // Send confimation email here //
             $confirmation_sent = App\Cb\Notifications\Email::signUpConfirmation(['uid' => $user_id, 'fname' => $p['fname'], 'email' => $p['email']]);
             if (!$confirmation_sent) {
                 xplog('Unable to send confirmation email for user "' . $user_id . '"');
                 throw new Exception('Unable to send your confirmation email.');
             }
             // Send success message //
             $request->session()->flash('sys_message', ['message' => 'A verification email has been sent to ' . $p['email'], 'redirect' => ['Sign In' => route('login')]]);
             return redirect(route('sys_message'));
         } catch (Exception $err) {
             cb_set_message($err->getMessage(), 0);
         }
     }
     $data['post'] = $p;
     return View::make('user_signup', $data)->render();
 }