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(); } }
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'); } } } }