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); }
/** * 生成新建或修改表单 * @param null $item * @param int $id * @return KForm */ protected function _form($id = 0, $item = null) { $roles = RoleModel::all(); $role_options = []; foreach ($roles as $role) { $role_options[$role->id] = $role->title; } $form = parent::_form($id, $item); $form->addField(FormFieldBase::createByType('username', FormFieldBase::Type_Text)->setRules('required')->setLabel('请输入用户名')->setCol(1 / 3)); $form->addField(FormFieldBase::createByType('password', FormFieldBase::Type_Text)->setRules('required')->setLabel('请输入密码')->setCol(1 / 3)); $form->addField(FormFieldBase::createByType('email', FormFieldBase::Type_Text)->setRules("required|unique:admins,email,{$id}")->setLabel('请输入邮箱')->setCol(1 / 3)); $form->newRow(); $form->addField(FormFieldBase::createByType('mobile', FormFieldBase::Type_Text)->setRules("required|unique:admins,mobile,{$id}|mobile")->setLabel('请输入手机')->setCol(1 / 2)); $form->addField(FormFieldBase::createByType('employee_id', FormFieldBase::Type_Text)->setRules("required|unique:admins,employee_id,{$id}")->setLabel('请输入工号')->setCol(1 / 2)); $form->newRow(); $form->addField(FormFieldBase::createByType('avatar', FormFieldBase::Type_Image)->setLabel('头像')->setCol(1 / 2)); $form->addField(FormFieldBase::createByType('role_id', FormFieldBase::Type_Select)->setOptions($role_options)->setRules('required')->setLabel('请选择角色')->setCol(1 / 2)); $form->newRow(); if ($id) { $form->modelToDefault($item); $form->setRules('password', ''); $form->setDefault('password', ''); } else { } return $form; }
public static function bindFormActionImageUpload($form, $item = null, $id = 0, $type = 'default') { if ('default' === 'type') { $label = '封面图'; } else { $label = $type; } $width = null; $height = null; if (isset(static::$imageType)) { $imageConfig = Config::get('images.' . static::$imageType); if ($imageConfig) { $label = $imageConfig[2]; $width = $imageConfig[0]; $height = $imageConfig[1]; } } $form->addField(FormFieldBase::createByType('image', FormFieldBase::Type_Image)->setLabel($label)->setType('default')->setDefault('')->setWidth($width)->setHeight($height)); $form->setSaveFunc('image', function ($item, $form, $field) use($type) { $url = $field->value(); $item->modifiedImage[$type] = $url; return $item; }); if ($id) { $form->setDefault('image', $item->getImage()); } return $form; }
public static function bindFormActionImageManyUpload($form, $item = null, $id = 0, $type = 'default') { $label = '其他图片'; $width = null; $height = null; if (isset(static::$imageManyType)) { $imageConfig = Config::get('images.' . static::$imageManyType); if ($imageConfig) { $label = $imageConfig[2]; $width = $imageConfig[0]; $height = $imageConfig[1]; } } $form->addField(FormFieldBase::createByType('images', FormFieldBase::Type_MultiImage)->setLabel($label)->setType('default')->setDefault([])->setWidth($width)->setHeight($height)); $form->setSaveFunc('images', function ($item, $form, $field) use($type) { $images = $field->value(); $item->modifiedImages[$type] = $images; return $item; }); if ($id) { $form->setDefault('images', $item->getImagesArray($type)); } return $form; }
public function addField(FormFieldBase $field) { $this->fields[$field->name()] = $field; $field->belongsToForm($this); return $field; }
/** * 生成新建或修改表单 * @param null $item * @param int $id * @return KForm */ protected function _form($id = 0, $item = null) { $form = parent::_form($id, $item); $form->addField(FormFieldBase::createByType('name', FormFieldBase::Type_Text)->setLabel('展示名称')->setRules('required')); $form->addField(FormFieldBase::createByType('title', FormFieldBase::Type_Text)->setLabel('职务')->setRules('required')); $form->addField(FormFieldBase::createByType('desc', FormFieldBase::Type_Text)->setLabel('角色简述')->setRules('required')); if ($item && $item->isRoot()) { } else { $form = $this->_rightsForm($form, $item); } if ($id) { $form->modelToDefault($item); $form->setRules('password', ''); $form->setDefault('password', ''); } else { } return $form; }