Exemple #1
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['phone'] = $validator->validate('phone');
     $input['address'] = $validator->validate('address');
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     $authSupplierUser = AuthHelper::getAuthUser();
     $supplierUserService = new SupplierUserService();
     // 验证用户登陆
     $supplierUser = $supplierUserService->loadSupplierById($authSupplierUser['suppliers_id']);
     if ($supplierUser->isEmpty()) {
         $this->addFlashMessage("非法登陆用户");
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$supplierUserService->verifyPassword($authSupplierUser['suppliers_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out;
     }
     // 更新数据
     unset($input['oldpassword']);
     $supplierUserService->updateSupplier($supplierUser, $input);
     // 记录用户的登陆信息
     $supplierUserInfo = $supplierUser->toArray();
     unset($supplierUserInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($supplierUserInfo);
     $this->addFlashMessage("修改资料成功");
     $smarty->assign($supplierUserInfo);
     out:
     // 从这里出去
     $smarty->display('my_profile.tpl');
 }
Exemple #2
0
 /**
  * 供货商详情显示
  */
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_supplier_edit_get');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $suppliers_id = $validator->digits()->min(1)->validate('suppliers_id');
     $suppliers_id = $suppliers_id > 0 ? $suppliers_id : 0;
     if (!$this->validate($validator)) {
         goto out;
     }
     // 查询供货商信息
     $supplierUserService = new SupplierUserService();
     $supplier = $supplierUserService->loadSupplierById($suppliers_id);
     if (0 != $suppliers_id && $supplier->isEmpty()) {
         // 不存在的供货商
         $this->addFlashMessage('供货商不存在');
         goto out;
     }
     if ($supplier->isEmpty()) {
         // 新建供货商账号,权限检查
         $this->requirePrivilege('manage_account_supplier_create');
     }
     if (!$f3->get('POST')) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     // 用户提交了更新请求,这里做供货商信息更新
     // 权限检查
     $this->requirePrivilege('manage_account_supplier_edit_post');
     // 参数验证
     $inputArray = array();
     $validator = new Validator($f3->get('POST'));
     $inputArray['suppliers_account'] = $validator->required()->minlength(4)->validate('suppliers_account');
     $inputArray['suppliers_name'] = $validator->required()->minlength(4)->validate('suppliers_name');
     $inputArray['phone'] = $validator->validate('phone');
     $inputArray['address'] = $validator->validate('address');
     $inputArray['suppliers_desc'] = $validator->validate('suppliers_desc');
     $password = $validator->validate('password');
     if (!Utils::isBlank($password)) {
         // 权限检查
         $this->requirePrivilege('manage_account_supplier_edit_change_account_password');
         $inputArray['password'] = $password;
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     // 确认供货商账号没有重复
     if (!empty($inputArray['suppliers_account'])) {
         $tmpSupplierUser = $supplierUserService->loadSupplierBySupplierAccount($inputArray['suppliers_account']);
         if (0 == $suppliers_id && !$tmpSupplierUser->isEmpty() || !$tmpSupplierUser->isEmpty() && $tmpSupplierUser['suppliers_id'] != $suppliers_id) {
             $this->addFlashMessage('供货商账号 ' . $inputArray['suppliers_account'] . ' 已经存在');
             goto out;
         }
     }
     // 如果供货商账号发生了变化
     if ($supplier['suppliers_account'] != $inputArray['suppliers_account']) {
         // 权限检查
         $this->requirePrivilege('manage_account_supplier_edit_change_account_password');
     }
     // 更新供货商信息
     $supplierUserService->updateSupplier($supplier, $inputArray);
     $this->addFlashMessage('供货商信息更新成功');
     out_display:
     //给 smarty 模板赋值
     $smarty->assign($supplier->toArray());
     out:
     $smarty->display('account_supplier_edit.tpl');
 }