/**
  * 检查权限
  * @param DeepinAuthAdministrator $admin
  * @param DeepinAuthResource $resource
  * @return bool
  */
 private function checkPermission(DeepinAuthAdministrator $admin, DeepinAuthResource $resource)
 {
     if ($admin->isBan() == 1) {
         return redirect('/auth/logout');
         //如果是被禁用直接退出
     }
     if ($admin->gid() == 1) {
         return true;
         //超级管理员组免费权限资源的检查
     }
     //判断用户组是否被禁用
     $group = DeepinAuthGroup::find($admin->gid());
     if (!$group instanceof DeepinAuthGroup || $group->inuse() != 1) {
         //用户组都禁用
         return redirect('/auth/logout');
         //如果是被禁用直接退出
     }
     $resourceId = $resource->resourceId();
     if ($resource->inuse() != 1) {
         return true;
         //该资源部需要认证
     }
     $permission = DeepinAuthPermission::whereRaw("gid=:gid and resourceid=:resourceid", array(":gid" => $admin->gid(), ":resourceid" => $resourceId))->first();
     return $permission != null;
 }
 /**
  * 按照用户名查找
  * @param $username
  * @return DeepinAuthAdministrator
  */
 public function findByUser($username)
 {
     $user = DeepinAuthAdministrator::whereRaw("username=:username", array(":username" => $username))->first();
     return $user;
 }
 /**
  * 保存
  * @return \Illuminate\View\View
  * @throws DeepInHtmlException
  */
 public function save()
 {
     $userName = \Input::get("username", null);
     $password = \Input::get("password", null);
     $phone = \Input::get("phone", null);
     $gid = intval(\Input::get("gid"));
     $isBan = intval(\Input::get("isban"));
     $isBan = $isBan == 1 || 0;
     if (empty($userName) || empty($password) || empty($phone) || $gid < 1) {
         throw new DeepInHtmlException("参数不能为空~!");
     }
     if ($this->findByUser($userName) instanceof DeepinAuthAdministrator) {
         throw new DeepInHtmlException($userName . "已经存在~!");
     }
     if (strlen($password) < 6) {
         throw new DeepInHtmlException("密码至少为6位!");
     }
     $user = new DeepinAuthAdministrator();
     $salt = $user->generateSalt();
     $password = $user->generatePwd($password, $salt);
     $user->username($userName);
     $user->password($password);
     $user->salt($salt);
     $user->phone($phone);
     $user->gid($gid);
     $user->isBan($isBan);
     if ($user->save() == false) {
         throw new DeepInHtmlException("保存失败~!");
     }
     return $this->success("操作成功~!");
 }