/**
  * To edit member profile action
  * AccountController::postIndex()
  *
  * @return
  */
 public function postIndex()
 {
     $this->userService = new UserAccountService();
     $success_message = "";
     $user = CUtil::getAuthUser();
     $logged_user_id = $user->id;
     $input = \Input::all();
     $input['user_id'] = $logged_user_id;
     $input['email'] = $user['email'];
     if (\Input::has('edit_basic')) {
         $rules = array();
         $messages = array();
         if (\Input::has('new_email') && \Input::get('new_email') != $user['email']) {
             $rules['new_email'] = $this->userService->getValidatorRule('email');
         }
         if (\Input::get('password') != "" || \Input::get('password_confirmation') != "") {
             $rules['Oldpassword'] = '******';
         }
         if (\Input::has('Oldpassword') && \Input::has('password') && \Input::get('password') != "" && \Input::get('Oldpassword') != \Input::get('password')) {
             $rules['Oldpassword'] = $this->userService->getValidatorRule('Oldpassword');
             $messages['Oldpassword.is_valid_old_password'] = trans("myaccount/form.edit-profile.wrong_password");
             $rules['password'] = $this->userService->getValidatorRule('password');
             $rules['password_confirmation'] = 'Required|same:password';
         }
         $validator = \Validator::make(\Input::all(), $rules, $messages);
         if ($validator->fails()) {
             return \Redirect::back()->withInput()->withErrors($validator);
         } else {
             $credential = array('email' => \Sentry::getUser()->email, 'password' => \Input::get('Oldpassword'));
             try {
                 $user = \Sentry::findUserByCredentials($credential);
                 $success_message = $this->userService->updateBasicDetails($input);
             } catch (sentrycheck $e) {
                 return \Redirect::back()->withInput()->with('valid_user', \Lang::get('webshopauthenticate::myaccount/form.current_password'));
             }
         }
     } else {
         if (\Input::has('edit_personal')) {
             $rules = array();
             $rules['first_name'] = $this->userService->getValidatorRule('first_name');
             $rules['last_name'] = $this->userService->getValidatorRule('last_name');
             $messages = array();
             $validator = \Validator::make(\Input::all(), $rules, $messages);
             if ($validator->fails()) {
                 return \Redirect::back()->withInput()->withErrors($validator);
             }
             $this->userService->updateUserPersonalDetails($input);
             $success_message = \Lang::get('webshopauthenticate::myaccount/form.edit-profile.personal_details_update_sucess');
         }
     }
     return \Redirect::to(\Config::get('webshopauthenticate::uri') . '/myaccount')->with('success_message', $success_message);
 }
 public function uploadUserImage($file, $image_ext, $image_name, $destinationpath, $user_id = 0)
 {
     $config_path = Config::get('generalConfig.user_image_folder');
     $this->chkAndCreateFolder($config_path);
     $logged_user_id = $user_id;
     if (!$logged_user_id && isset(getAuthUser()->id)) {
         $logged_user_id = getAuthUser()->id;
     }
     // open file a image resource
     Image::make($file->getRealPath())->save(Config::get("generalConfig.user_image_folder") . $image_name . '_O.' . $image_ext);
     list($width, $height) = getimagesize($file);
     list($upload_img['width'], $upload_img['height']) = getimagesize(base_path() . '/public/' . $config_path . $image_name . '_O.' . $image_ext);
     $large_width = Config::get('generalConfig.user_image_large_width');
     $large_height = Config::get('generalConfig.user_image_large_height');
     if (isset($large_width) && isset($large_height)) {
         $img_size = CUtil::DISP_IMAGE($large_width, $large_height, $upload_img['width'], $upload_img['height'], true);
         Image::make($file->getRealPath())->resize($large_width, $large_height, true, false)->save($config_path . $image_name . '_L.' . $image_ext);
     }
     $small_width = Config::get("generalConfig.user_image_small_width");
     $small_height = Config::get("generalConfig.user_image_small_height");
     if (isset($small_width) && isset($small_height)) {
         $simg_size = CUtil::DISP_IMAGE($small_width, $small_height, $upload_img['width'], $upload_img['height'], true);
         Image::make($file->getRealPath())->resize($small_width, $small_height, true, false)->save($config_path . $image_name . '_S.' . $image_ext);
     }
     $thumb_width = Config::get("generalConfig.user_image_thumb_width");
     $thumb_height = Config::get("generalConfig.user_image_thumb_height");
     if (isset($thumb_width) && isset($thumb_height)) {
         $timg_size = CUtil::DISP_IMAGE($thumb_width, $thumb_height, $upload_img['width'], $upload_img['height'], true);
         Image::make($file->getRealPath())->resize($thumb_width, $thumb_height, true, false)->save($config_path . $image_name . '_T.' . $image_ext);
     }
     $img_path = Request::root() . '/' . $config_path;
     list($upload_input['small_width'], $upload_input['small_height']) = getimagesize($img_path . $image_name . '_S.' . $image_ext);
     list($upload_input['thumb_width'], $upload_input['thumb_height']) = getimagesize($img_path . $image_name . '_T.' . $image_ext);
     list($upload_input['large_width'], $upload_input['large_height']) = getimagesize($img_path . $image_name . '_L.' . $image_ext);
     $user_image = new UserImage();
     $user_data = array('image_ext' => $image_ext, 'image_name' => $image_name, 'image_server_url' => $destinationpath, 'large_height' => $upload_input['large_height'], 'large_width' => $upload_input['large_width'], 'small_width' => $upload_input['small_width'], 'small_height' => $upload_input['small_height'], 'thumb_width' => $upload_input['thumb_width'], 'thumb_height' => $upload_input['thumb_height']);
     $user_image_details = UserImage::where('user_id', $logged_user_id)->first();
     if (count($user_image_details) > 0) {
         $this->deleteImageFiles($user_image_details->image_name, $user_image_details->image_ext, $config_path);
         UserImage::where('user_id', $logged_user_id)->update($user_data);
         $id = $user_image_details->image_id;
     } else {
         $user_data['date_added'] = new DateTime();
         $user_data['user_id'] = $logged_user_id;
         $id = $user_image->insertGetId($user_data);
     }
     return $id;
 }