Ejemplo n.º 1
0
 protected function landingPage($_user_type = false)
 {
     if ($_user_type === false) {
         $_user_type = 0;
         // Try to use the current logged in user(if any) details //
         if (session()->has('current_user_type')) {
             $_user_type = session()->get('current_user_type');
         }
     }
     $user_type = intval($_user_type);
     if ($user_type === 1) {
         // Admin user
         // TODO: add admin landing uri
         return url();
     } else {
         if ($user_type === 0) {
             // Normal user
             // TODO: change this to real landing page
             return route('my_account', ['uid' => App\Crypt::urlencode(session()->get('current_user')->id)]);
         } else {
             return url();
         }
     }
     // If all else fails.. redirect to home page
 }
Ejemplo n.º 2
0
 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');
     });
 }
Ejemplo n.º 3
0
 public function signUpConfirmation(Request $request, $uid)
 {
     if (Auth::check()) {
         return redirect($this->landingPage());
     }
     // If already logged then redirect to landing page
     $data = [];
     $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 (intval($user_details->status) === 1) {
         // If already confirmed then redirect to landing page //
         return redirect(url());
     }
     App\Cb\Users::confirmAccount($uid);
     // Confirm account here
     // Send success message //
     $request->session()->flash('sys_message', ['message' => 'Successfully activated your account. You may now login by clicking the link below.', 'redirect' => ['Sign In' => route('login')]]);
     return redirect(route('sys_message'));
 }
Ejemplo n.º 4
0
 protected function userAuthenticate($_post)
 {
     $p = $_post;
     $this->req($p, ['email', 'password', 'token', 'os']);
     $auth_response = App\Cb\Users::authenticate($p['email'], $p['password'], true);
     $uid;
     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)]);
             $uid = $auth_response;
         } else {
             $this->error('Invalid email or password');
         }
     } else {
         $uid = $auth_response->id;
         App\Cb\Users\Presence::setOnline($uid);
         // Set presence as online
     }
     // Save the token for this user //
     App\Cb\Devices::add($uid, $p['token'], $p['os']);
     xplog('Registered device token "' . $p['token'] . '" for user "' . $uid . '" for os "' . $p['os'] . '"', __METHOD__);
     $user_details = App\Cb\Users::getDetailsById($uid);
     if (!$user_details) {
         $this->error('Unable to find user details.');
     }
     if (isset($resend_link)) {
         $user_details->resend_link = $resend_link;
     }
     return ['api_name' => $_post['api_name'], 'payload' => $user_details];
 }
Ejemplo n.º 5
0
 public static function newUser($data, $type = 'C')
 {
     $validate = self::validateUser($data, $type);
     if ($validate->fails()) {
         $response['messages'] = $validate->messages()->toArray();
         $response['return_code'] = 406;
         return $response;
     }
     $user = new self();
     if (!empty($data['password'])) {
         $data['password'] = bcrypt($data['password']);
     }
     $user->fill($data);
     $user->save();
     $user->token = \Crypt::encrypt(['id_users' => $user->id_users]);
     $response = ['user' => $user, 'return_code' => 201];
     return $response;
 }
Ejemplo n.º 6
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();
 }