public function login()
 {
     Session::set('admin_lock_url', null);
     $loginForm = new KForm();
     $loginForm->addField(FormFieldBase::createByType('login', FormFieldBase::Type_Text)->setRules('required')->setLabel('请输入工号'));
     $loginForm->addField(FormFieldBase::createByType('password', FormFieldBase::Type_Password)->setRules('required')->setLabel('请输入密码'));
     if (AuthModel::user() !== null) {
         return Redirect::action('admin.index');
     }
     if (Request::isMethod('POST')) {
         //是管理员登陆请求
         if ($loginForm->validation()) {
             $login = $loginForm->value('login');
             $password = $loginForm->value('password');
             if (AuthModel::attempt(['employee_id' => $login, 'password' => $password])) {
                 $admin = AuthModel::getUser();
                 $admin->last_login = new \Carbon\Carbon();
                 $admin->save();
                 return Redirect::action('admin.index');
             } else {
                 $loginForm->set_error('password', '错误的用户名或密码');
             }
         } else {
             //
         }
     }
     $this->layout = View::make('laravel-cms::admin-lte/login')->with('form', $loginForm);
 }
 protected function imageAvatar()
 {
     $path = 'upload/' . date('Ym/d/');
     $filename = KRandom::getRandStr() . '.jpg';
     if (!File::exists(public_path($path))) {
         File::makeDirectory(public_path($path), 493, true);
     }
     while (File::exists(public_path($path) . $filename)) {
         $filename = KRandom::getRandStr() . '.jpg';
     }
     $this->image->resize(new \Imagine\Image\Box(300, 300))->save(public_path($path) . $filename);
     ImageModel::createUploadedImage($path . $filename, URL::asset($path . $filename));
     $user = AuthModel::user();
     $url = URL::asset($path . $filename);
     if ($user) {
         if ($user->profile) {
             $user->profile->avatar = $url;
             $user->profile->save();
         } else {
             ProfileModel::create(array('user_id' => $user->id, 'avatar' => $url));
         }
     } else {
     }
     return $url;
 }
 protected function operator()
 {
     if (null == static::getOperator()) {
         return AuthModel::user();
     } else {
         return static::getOperator();
     }
 }
示例#4
0
 public function filter(\Illuminate\Routing\Route $route, $request)
 {
     $user = AuthModel::user();
     if (null == $user) {
         //用户未登录
         return Redirect::action($this->login_page);
     } else {
         //用户已登录,检查权限
         if (false == $this->rightsFilter($user, $route)) {
             return Redirect::action($this->forbidden_page);
         } else {
             //检查是否锁屏
             $as = Route::current()->getName();
             if (Session::get('admin_lock_url') && !in_array($as, ['admin.logout', 'admin.lock', 'admin.unlock'])) {
                 return Redirect::action('admin.lock');
             }
         }
     }
 }
 protected function setupLayout()
 {
     $this->layout = View::make('laravel-cms::layouts/admin-lte');
     $this->layout->content = '';
     $this->layout->title = '';
     $this->layout->site_name = Config::get('laravel-cms::site.name');
     $this->layout->css = [];
     $this->layout->js = [];
     $user = AuthModel::getUser();
     $menu = new AdminMenu($user);
     if (isset(static::$menu_name)) {
         $menu_name = static::$menu_name;
     } elseif (isset(static::$name)) {
         $menu_name = static::$name;
     } else {
         $menu_name = null;
     }
     $this->layout->shortcuts = $menu->getCurrentSubMenu($menu_name);
     $menu = $menu->getMenu();
     $this->layout->navbar = View::make('laravel-cms::admin-lte/navbar')->with('menu', $menu);
     $this->layout->usermenu = View::make('laravel-cms::admin-lte/user_menu')->with('user', AuthModel::getUser());
 }
示例#6
0
 public static function checkMe($action, $parameters = null)
 {
     return static::check(AuthModel::getUser(), $action, $parameters);
 }