/** * 登录帐号 */ public function login() { $data['user_account'] = $this->isP('account', '请填写帐号'); $data['user_password'] = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $this->isP('password', '请提交密码'), 'PRIVATE_KEY'); $check = $this->db('user')->where('user_account = :user_account AND user_password = :user_password AND user_status = 1 ')->find($data); if (empty($check)) { $this->error('帐号不存在或者密码错误'); } $this->setLogin($check); $this->success('登录成功', $this->url('/d/manage', true)); }
/** * 添加内容 */ public function action($jump = TRUE, $commit = TRUE) { if ($this->p('password')) { $password = $this->p('password'); if ($password != $this->p('confirm_password')) { $this->error('两次输入的密码不一致'); } $_POST['password'] = (string) \Core\Func\CoreFunc::generatePwd($this->isP('account', '请提交帐号') . $password, 'PRIVATE_KEY'); } parent::action(); }
public function index() { $data['user_account'] = $data['user_mail'] = $this->isP('account', '请提交账号信息'); $data['user_password'] = \Core\Func\CoreFunc::generatePwd($this->isP('passwd', '请提交密码')); $login = $this->db('user')->where('(user_account = :user_account OR user_mail = :user_mail ) AND user_password = :user_password ')->find($data); if (empty($login)) { $this->error('帐号或者密码错误'); } $this->setLogin($login); $this->success('登录成功', $this->url(GROUP . '-Index-index')); }
public function before() { if (METHOD == 'POST') { $this->isP('password', '请填写密码'); } if (empty($_POST['password'])) { $_POST['password'] = \Model\Content::findContent('user', $_POST['id'], 'user_id')['user_password']; } else { $_POST['password'] = (string) \Core\Func\CoreFunc::generatePwd($this->p('password')); } }
/** * 更新用户 */ public function action($jump = TRUE, $commit = TRUE) { $user = \Model\Content::findContent('user', (int) $_POST['id'], 'user_id'); if (empty($user)) { $this->error('不存在的用户'); } if ($this->p('password')) { $password = $this->p('password'); if ($password != $this->p('confirm_password')) { $this->error('两次输入的密码不一致'); } $_POST['password'] = (string) \Core\Func\CoreFunc::generatePwd($this->isP('account', '请提交帐号') . $password, 'PRIVATE_KEY'); } parent::action(); }
/** * 注册帐号 */ public function signup() { if (\Model\Option::findOption('signup')['value'] == '0') { $this->error('本系统没有开启注册。'); } $data['user_account'] = $this->isP('account', '请填写帐号'); $existAccount = \Model\Content::findContent('user', $data['user_account'], 'user_account'); if (!empty($existAccount)) { $this->error('帐号已存在'); } $data['user_password'] = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $this->isP('password', '请填写密码'), 'PRIVATE_KEY'); $repwd = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $this->isP('repassword', '请填写密码'), 'PRIVATE_KEY'); if ($data['user_password'] != $repwd) { $this->error('两次密码不一致'); } $data['user_mail'] = $this->isP('mail', '请填写帐号'); $existEmail = \Model\Content::findContent('user', $data['user_mail'], 'user_mail'); if (!empty($existEmail)) { $this->error('邮箱地址已存在'); } \Core\Func\CoreFunc::$defaultPath = false; require PES_PATH . '/Expand/Identicon/autoload.php'; $identicon = new \Identicon\Identicon(); $imageDataUri = $identicon->getImageDataUri($data['user_mail']); $data['user_name'] = $this->isP('name', '请填写帐号'); $data['user_status'] = '1'; $data['user_createtime'] = time(); $data['user_department_id'] = '2'; //人事部 $data['user_group_id'] = '2'; //普通用户 $data['user_head'] = $imageDataUri; $addResult = $this->db('user')->insert($data); if (empty($addResult)) { $this->error('注册失败'); } unset($data['user_password']); $data['user_id'] = $addResult; $this->setLogin($data); $this->success('注册成功!', $this->url(GROUP . '-Index-index')); }
/** * 导入数据库 */ public function import() { $title = $this->isP('title', '请填写系统的标题'); $urlModel = $this->isP('urlModel', '请选择URL模式', FALSE); $data['user_account'] = $this->isP('account', '请填写管理员帐号'); $data['user_password'] = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $this->isP('passwd', '请填写管理员密码'), 'PRIVATE_KEY'); $data['user_name'] = $this->isP('name', '请填写管理员名称'); $data['user_mail'] = $this->isP('mail', '请填写管理员邮箱'); //读取数据库文件 $sqlFile = file_get_contents(PES_PATH . '/Install/InstallDb/team.sql'); if (empty($sqlFile)) { $this->error('无法读取安装SQL文件'); } //配置PDO信息 $config = \Core\Func\CoreFunc::loadConfig(); try { $db = new \PDO("mysql:host={$config['DB_HOST']};port={$config['DB_PORT']};dbname={$config['DB_NAME']}", $config['DB_USER'], $config['DB_PWD']); } catch (\PDOException $e) { $this->error($e->getMessage()); } //安装数据库文件 $db->exec($sqlFile); \Core\Func\CoreFunc::$defaultPath = false; require PES_PATH . '/Expand/Identicon/autoload.php'; $identicon = new \Identicon\Identicon(); $imageDataUri = $identicon->getImageDataUri($data['user_mail']); $data['user_head'] = $imageDataUri; $data['user_department_id'] = $data['user_status'] = $data['user_group_id'] = '1'; //写入管理员帐号 $this->db('user')->insert($data); //更新系统配置 \Model\Option::update('sitetitle', $title); \Model\Option::update('urlModel', $urlModel); //更新根目录的index.php $readWriteFile = file_get_contents(PES_PATH . '/Install/Write/index.php'); $fopen = fopen(PES_PATH . '/index.php', 'w+'); fwrite($fopen, $readWriteFile); fclose($fopen); //标记程序已安装和移除安装数据库文件 unlink(PES_PATH . '/Install/index.php'); unlink(PES_PATH . '/Install/InstallDb/team.sql'); fclose(fopen(PES_PATH . '/Install/install.txt', 'w+')); fclose(fopen(PES_PATH . '/Install/index.html', 'w+')); $this->success('安装完成!'); }
/** * 导入数据库 */ public function import() { $title = $this->isP('title', '请填写系统的标题'); $urlModel = $this->isP('urlModel', '请选择URL模式', FALSE); $data['user_account'] = $this->isP('account', '请填写管理员帐号'); $data['user_password'] = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $this->isP('passwd', '请填写管理员密码'), 'PRIVATE_KEY'); $data['user_name'] = $this->isP('name', '请填写管理员名称'); $data['user_mail'] = $this->isP('mail', '请填写管理员邮箱'); //读取数据库文件 $sqlFile = file_get_contents(PES_PATH . '/Install/InstallDb/doc.sql'); if (empty($sqlFile)) { $this->error('无法读取安装SQL文件'); } //配置PDO信息 $config = \Core\Func\CoreFunc::loadConfig(); try { //创建数据库 $tmp = new \PDO("mysql:host={$config['DB_HOST']};port={$config['DB_PORT']}", $config['DB_USER'], $config['DB_PWD']); $createDb = "CREATE DATABASE IF NOT EXISTS {$config['DB_NAME']} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"; $tmp->exec($createDb); //连接数据库 $db = new \PDO("mysql:host={$config['DB_HOST']};port={$config['DB_PORT']};dbname={$config['DB_NAME']}", $config['DB_USER'], $config['DB_PWD']); } catch (\PDOException $e) { $this->error($e->getMessage()); } //安装数据库文件 $db->exec($sqlFile); $data['user_status'] = '1'; //写入管理员帐号 $this->db('user')->insert($data); //更新运行的配置文件 $config = (require PES_PATH . '/Install/Config/config_tmp.php'); $fopen = fopen(PES_PATH . '/Config/config.php', 'w+'); if (!$fopen) { $this->error('文件无法打开,请检测程序目录是否设置足够的权限'); } $str = "<?php\n \$config = array(\n"; $str .= "'SITETITLE' => '{$title}',\n"; foreach (array_merge($config, json_decode($urlModel, true)) as $key => $value) { if (is_array($value)) { $str .= "'{$key}' => array(\n"; foreach ($value as $ik => $iv) { $str .= "'{$ik}' => '{$iv}',\n"; } $str .= "),"; } else { $str .= "'{$key}' => '{$value}',\n"; } } $str .= ");\n"; $str .= file_get_contents(PES_PATH . '/Config/config_same.php'); fwrite($fopen, $str); fclose($fopen); //更新根目录的index.php $readWriteFile = file_get_contents(PES_PATH . '/Install/Write/index.php'); $fopen = fopen(PES_PATH . '/index.php', 'w+'); fwrite($fopen, $readWriteFile); fclose($fopen); //标记程序已安装和移除安装数据库文件 unlink(PES_PATH . '/Install/index.php'); unlink(PES_PATH . '/Install/InstallDb/doc.sql'); fclose(fopen(PES_PATH . '/Install/install.txt', 'w+')); fclose(fopen(PES_PATH . '/Install/index.html', 'w+')); $this->success('安装完成!'); }
/** * 菜单基础表单 */ public static function baseFrom() { $fieldPrefix = "user_"; $model = \Model\Model::findModel('user', 'model_name'); $field = \Model\Field::fieldList($model['model_id'], '1'); if (self::p('method') == 'PUT') { if (!($data['noset']['user_id'] = self::isP('user_id'))) { return self::error($GLOBALS['_LANG']['USER']['LOST_USER_ID']); } if (!self::findUser($data['noset']['user_id'])) { return self::error($GLOBALS['_LANG']['USER']['NOT_EXITS_USER']); } } elseif (self::p('method') == 'POST') { $data['user_createtime'] = time(); } foreach ($field as $value) { /** * 判断提交的字段是否为数组 */ if (is_array($_POST[$value['field_name']])) { $_POST[$fieldPrefix . $value['field_name']] = implode(',', $_POST[$fieldPrefix . $value['field_name']]); } /** * 时间转换为时间戳 */ if ($value['field_type'] == 'date') { $_POST[$fieldPrefix . $value['field_name']] = strtotime($_POST[$fieldPrefix . $value['field_name']]); } if ($value['field_required'] == '1') { if (!($data[$fieldPrefix . $value['field_name']] = self::isP($fieldPrefix . $value['field_name'])) && !is_numeric($data[$fieldPrefix . $value['field_name']])) { return self::error($value['display_name'] . $GLOBALS['_LANG']['COMMON']['REQUIRED']); } } else { if (!($data[$fieldPrefix . $value['field_name']] = self::p($fieldPrefix . $value['field_name']))) { $data[$fieldPrefix . $value['field_name']] = $value['field_default']; } } } /** * 先移除密码 */ unset($data['user_password']); if (self::p('user_password')) { $password = self::p('user_password'); if ($password != self::p('confirm_password')) { return self::error($GLOBALS['_LANG']['USER']['CONFIRM_PASSWORD_ERROR']); } $data['user_password'] = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $password, 'PRIVATE_KEY'); } elseif (self::p('method') == 'POST' && !self::p('user_password')) { return self::error($GLOBALS['_LANG']['USER']['ENTER_PASSWORD']); } return self::success($data); }