Beispiel #1
0
 protected function doReset()
 {
     $validator = new Typecho_Validate();
     $validator->addRule('password', 'required', _t('必须填写密码'));
     $validator->addRule('password', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6);
     $validator->addRule('password', 'maxLength', _t('为了便于记忆, 密码长度请不要超过十八位'), 18);
     $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'password');
     $error = $validator->run($this->request->from('password', 'confirm'));
     /** 截获验证异常 */
     if ($error) {
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error, 'error');
         $this->response->goBack();
     }
     $password = $this->request->get('password');
     $hasher = new PasswordHash(8, true);
     $password = $hasher->HashPassword($password);
     //用户操作类
     $users = $this->widget('Widget_Abstract_Users');
     /** 更新数据 */
     $users->update(array('password' => $password), $this->db->sql()->where('uid = ?', $this->_user['uid']));
     /** 提示信息 */
     $this->widget('Widget_Notice')->set(_t('密码已经成功修改'), 'success');
     $this->widget('Some_Util_Verify')->setParams('type=reset')->delete($this->token);
     /** 转向登录页面 */
     $this->response->redirect($this->___loginUrl());
 }
Beispiel #2
0
 /**
  * 初始化函数
  *
  * @access public
  * @return void
  */
 public function action()
 {
     // protect
     $this->security->protect();
     /** 如果已经登录 */
     if ($this->user->hasLogin()) {
         /** 直接返回 */
         $this->response->redirect($this->options->index);
     }
     /** 初始化验证类 */
     $validator = new Typecho_Validate();
     $validator->addRule('name', 'required', _t('请输入用户名'));
     $validator->addRule('password', 'required', _t('请输入密码'));
     /** 截获验证异常 */
     if ($error = $validator->run($this->request->from('name', 'password'))) {
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error);
         $this->response->goBack();
     }
     /** 先验证动态密码 **/
     $user = $this->db->fetchRow($this->select()->where('name = ?', $this->request->name)->limit(1));
     if ($user['twoFactorAuthKey']) {
         if ($this->request->twoFactAuth) {
             if (!$this->widget('Widget_GoogleAuthenticator')->verifyCode($user['twoFactorAuthKey'], $this->request->twoFactAuth, 2)) {
                 $this->widget('Widget_Notice')->set(_t('动态密码不正确'));
                 $this->response->goBack();
             }
         } else {
             Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
             $this->response->redirect($this->options->adminUrl . 'login.php?requireTwoFactAuth=yes');
         }
     }
     /** 开始验证用户 **/
     $valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0);
     /** 比对密码 */
     if (!$valid) {
         /** 防止穷举,休眠3秒 */
         sleep(3);
         $this->pluginHandle()->loginFail($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember);
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         $this->widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error');
         $this->response->goBack('?referer=' . urlencode($this->request->referer));
     }
     $this->pluginHandle()->loginSucceed($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember);
     /** 跳转验证后地址 */
     if (NULL != $this->request->referer) {
         $this->response->redirect($this->request->referer);
     } else {
         if (!$this->user->pass('contributor', true)) {
             /** 不允许普通用户直接跳转后台 */
             $this->response->redirect($this->options->profileUrl);
         } else {
             $this->response->redirect($this->options->adminUrl);
         }
     }
 }
Beispiel #3
0
 /**
  * 评论处理函数
  *
  * @throws Typecho_Widget_Exception
  * @throws Exception
  * @throws Typecho_Exception
  */
 private function comment()
 {
     // modified_by_jiangmuzi 2015.09.23
     // 必须登录后才可以回复
     if (!$this->user->hasLogin()) {
         $this->widget('Widget_Notice')->set(_t('请先<a href="%s">登录</a>', $this->options->someUrl('login', null, false) . '?redir=' . $this->request->getRequestUrl()), NULL, 'success');
         $this->response->goBack();
     }
     // end modified
     // 使用安全模块保护
     $this->security->protect();
     $comment = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'comment', 'status' => !$this->_content->allow('edit') && $this->options->commentsRequireModeration ? 'waiting' : 'approved');
     //检验格式
     $validator = new Typecho_Validate();
     $validator->addRule('text', 'required', _t('必须填写评论内容'));
     $comment['text'] = $this->request->text;
     /** 记录登录用户的id */
     $comment['authorId'] = $this->user->uid;
     if ($error = $validator->run($comment)) {
         /** 记录文字 */
         Typecho_Cookie::set('__some_remember_text', $comment['text']);
         throw new Typecho_Widget_Exception(implode("\n", $error));
     }
     /** 生成过滤器 */
     try {
         $comment = $this->pluginHandle()->comment($comment, $this->_content);
     } catch (Typecho_Exception $e) {
         Typecho_Cookie::set('__some_remember_text', $comment['text']);
         throw $e;
     }
     // modified_by_jiangmuzi 2015.09.23
     // 解析@数据
     $atArr = $this->searchAt($comment);
     // end modified
     /** 添加评论 */
     $commentId = $this->insert($comment);
     Typecho_Cookie::delete('__some_remember_text');
     $this->db->fetchRow($this->select()->where('coid = ?', $commentId)->limit(1), array($this, 'push'));
     //更新最后评论人及时间
     $this->db->query($this->db->update('table.contents')->rows(array('lastUid' => $this->authorId, 'lastComment' => $this->created))->where('cid = ?', $this->cid));
     //提醒主题作者
     if ($comment['authorId'] != $comment['ownerId']) {
         $atArr[] = array('uid' => $comment['ownerId'], 'type' => 'comment');
     }
     if (!empty($atArr)) {
         foreach ($atArr as $v) {
             $this->widget('Widget_Users_Messages')->addMessage($v['uid'], $commentId, $v['type']);
         }
     }
     //触发评论积分规则
     Widget_Common::credits('reply', null, $commentId);
     /** 评论完成接口 */
     $this->pluginHandle()->finishComment($this);
     $this->response->goBack('#' . $this->theId);
 }
Beispiel #4
0
 /**
  * 初始化函数
  *
  * @access public
  * @return void
  */
 public function action()
 {
     /** 如果已经登录 */
     if ($this->user->hasLogin()) {
         /** 直接返回 */
         $this->response->redirect($this->options->index);
     }
     /** 初始化验证类 */
     $validator = new Typecho_Validate();
     $validator->addRule('name', 'required', _t('请输入用户名'));
     $validator->addRule('password', 'required', _t('请输入密码'));
     /** 截获验证异常 */
     if ($error = $validator->run($this->request->from('name', 'password'))) {
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error);
         $this->response->goBack();
     }
     /** 开始验证用户 **/
     $valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0);
     /** 比对密码 */
     if (!$valid) {
         /** 防止穷举,休眠3秒 */
         sleep(3);
         $this->pluginHandle()->loginFail($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember);
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         $this->widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error');
         $this->response->goBack('?referer=' . urlencode($this->request->referer));
     }
     $this->pluginHandle()->loginSucceed($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember);
     /** 跳转验证后地址 */
     if (NULL != $this->request->referer) {
         $this->response->redirect($this->request->referer);
     } else {
         if (!$this->user->pass('contributor', true)) {
             /** 不允许普通用户直接跳转后台 */
             $this->response->redirect($this->options->siteUrl);
         } else {
             $this->response->redirect($this->options->adminUrl);
         }
     }
 }
Beispiel #5
0
 protected function doLogin()
 {
     // protect
     $this->security->protect();
     /** 如果已经登录 */
     if ($this->user->hasLogin()) {
         /** 直接返回 */
         $this->response->redirect($this->options->index);
     }
     /** 初始化验证类 */
     $validator = new Typecho_Validate();
     $validator->addRule('name', 'required', _t('请输入用户名'));
     $validator->addRule('password', 'required', _t('请输入密码'));
     /** 截获验证异常 */
     if ($error = $validator->run($this->request->from('name', 'password'))) {
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error);
         $this->response->goBack();
     }
     /** 开始验证用户 **/
     $valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0);
     /** 比对密码 */
     if (!$valid) {
         /** 防止穷举,休眠3秒 */
         sleep(3);
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         $this->widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error');
         $this->response->goBack('?referer=' . urlencode($this->request->referer));
     }
     $this->widget('Widget_Notice')->set('已成功登录!', 'notice');
     //登录积分
     Forum_Common::credits('login');
     /** 跳转验证后地址 */
     $this->response->redirect($this->request->get('redir', $this->options->index));
 }
Beispiel #6
0
 public function resetPwd()
 {
     $token = $this->request->token;
     if (empty($token)) {
         throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404);
     }
     $verify = $this->widget('Util_Verify')->setParams('type=reset')->check($token);
     if (empty($verify) || empty($verify['uid'])) {
         throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404);
     }
     $validator = new Typecho_Validate();
     $validator->addRule('password', 'required', _t('必须填写密码'));
     $validator->addRule('password', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6);
     $validator->addRule('password', 'maxLength', _t('为了便于记忆, 密码长度请不要超过十八位'), 18);
     $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'password');
     $error = $validator->run($this->request->from('password', 'confirm'));
     /** 截获验证异常 */
     if ($error) {
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error, 'error');
         $this->response->goBack();
     }
     $password = $this->request->get('password');
     $hasher = new PasswordHash(8, true);
     $password = $hasher->HashPassword($password);
     /** 更新数据 */
     $this->update(array('password' => $password), $this->db->sql()->where('uid = ?', $verify['uid']));
     /** 提示信息 */
     $this->widget('Widget_Notice')->set(_t('密码已经成功修改,请重新登录'), 'success');
     $this->widget('Util_Verify')->setParams('type=reset')->delete($token);
     if ($this->user->hasLogin()) {
         $this->user->logout();
     }
     /** 转向登录页面 */
     $this->response->redirect(Typecho_Common::url('login', $this->options->index));
 }
Beispiel #7
0
 /**
  * 设置默认分类
  *
  * @access public
  * @return void
  */
 public function defaultCategory()
 {
     /** 验证数据 */
     $validator = new Typecho_Validate();
     $validator->addRule('mid', 'required', _t('分类主键不存在'));
     $validator->addRule('mid', array($this, 'categoryExists'), _t('分类不存在'));
     if ($error = $validator->run($this->request->from('mid'))) {
         $this->widget('Widget_Notice')->set($error, 'error');
     } else {
         $this->db->query($this->db->update('table.options')->rows(array('value' => $this->request->mid))->where('name = ?', 'defaultCategory'));
         $this->db->fetchRow($this->select()->where('mid = ?', $this->request->mid)->where('type = ?', 'category')->limit(1), array($this, 'push'));
         /** 设置高亮 */
         $this->widget('Widget_Notice')->highlight($this->theId);
         /** 提示信息 */
         $this->widget('Widget_Notice')->set(_t('<a href="%s">%s</a> 已经被设为默认分类', $this->permalink, $this->name), 'success');
     }
     /** 转向原页 */
     $this->response->redirect(Typecho_Common::url('manage-metas.php', $this->options->adminUrl));
 }
Beispiel #8
0
 protected function doBindRegister()
 {
     $validator = new Typecho_Validate();
     $validator->addRule('mail', 'required', _t('必须填写电子邮箱'));
     $validator->addRule('mail', array($this, 'mailExists'), _t('电子邮箱地址已经存在'));
     $validator->addRule('mail', 'email', _t('电子邮箱格式错误'));
     $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200);
     $validator->addRule('nickname', 'required', _t('必须填写昵称'));
     $validator->addRule('nickname', 'xssCheck', _t('请不要在昵称中使用特殊字符'));
     $validator->addRule('nickname', array($this, 'screenNameExists'), _t('昵称已经存在'));
     /** 截获验证异常 */
     if ($error = $validator->run($this->request->from('mail', 'nickname'))) {
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error, 'error');
         $this->response->goBack();
     }
     $mail = $this->request->get('mail');
     $nickname = $this->request->get('nickname');
     $data = array('mail' => $mail, 'screenName' => $nickname, 'created' => $this->options->gmtTime, 'group' => 'subscriber');
     $uid = $this->insert($data);
     $this->bindAuthUser($this->auth['openid'], $this->auth['type'], $uid);
     Typecho_Cookie::delete('__user_auth');
     $this->autoLogin($this->auth['openid'], $this->auth['type']);
 }
 /**
  * 初始化函数
  *
  * @access public
  * @return void
  */
 public function action()
 {
     // protect
     $this->security->protect();
     /** 如果已经登录 */
     if ($this->user->hasLogin() || !$this->options->allowRegister) {
         /** 直接返回 */
         $this->response->redirect($this->options->index);
     }
     /** 初始化验证类 */
     $validator = new Typecho_Validate();
     $validator->addRule('name', 'required', _t('必须填写用户名称'));
     $validator->addRule('name', 'minLength', _t('用户名至少包含2个字符'), 2);
     $validator->addRule('name', 'maxLength', _t('用户名最多包含32个字符'), 32);
     $validator->addRule('name', 'xssCheck', _t('请不要在用户名中使用特殊字符'));
     $validator->addRule('name', array($this, 'nameExists'), _t('用户名已经存在'));
     $validator->addRule('mail', 'required', _t('必须填写电子邮箱'));
     $validator->addRule('mail', array($this, 'mailExists'), _t('电子邮箱地址已经存在'));
     $validator->addRule('mail', 'email', _t('电子邮箱格式错误'));
     $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200);
     /** 如果请求中有password */
     if (array_key_exists('password', $_REQUEST)) {
         $validator->addRule('password', 'required', _t('必须填写密码'));
         $validator->addRule('password', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6);
         $validator->addRule('password', 'maxLength', _t('为了便于记忆, 密码长度请不要超过十八位'), 18);
         $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'password');
     }
     /** 截获验证异常 */
     if ($error = $validator->run($this->request->from('name', 'password', 'mail', 'confirm'))) {
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         Typecho_Cookie::set('__typecho_remember_mail', $this->request->mail);
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error);
         $this->response->goBack();
     }
     $hasher = new PasswordHash(8, true);
     $generatedPassword = Typecho_Common::randString(7);
     $dataStruct = array('name' => $this->request->name, 'mail' => $this->request->mail, 'screenName' => $this->request->name, 'password' => $hasher->HashPassword($generatedPassword), 'created' => $this->options->gmtTime, 'group' => 'subscriber');
     $dataStruct = $this->pluginHandle()->register($dataStruct);
     $insertId = $this->insert($dataStruct);
     $this->db->fetchRow($this->select()->where('uid = ?', $insertId)->limit(1), array($this, 'push'));
     $this->pluginHandle()->finishRegister($this);
     $this->user->login($this->request->name, $generatedPassword);
     Typecho_Cookie::delete('__typecho_first_run');
     Typecho_Cookie::delete('__typecho_remember_name');
     Typecho_Cookie::delete('__typecho_remember_mail');
     $this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $this->screenName, $generatedPassword), 'success');
     $this->response->redirect($this->options->adminUrl);
 }
Beispiel #10
0
 public function changePwd()
 {
     $validator = new Typecho_Validate();
     $validator->addRule('password', 'required', _t('必须填写旧密码'));
     $validator->addRule('newpassword', 'required', _t('必须填写新密码'));
     $validator->addRule('newpassword', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6);
     $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'newpassword');
     $error = $validator->run($this->request->from('password', 'newpassword', 'confirm'));
     /** 截获验证异常 */
     if ($error) {
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error, 'error');
         $this->response->goBack();
     }
     $data = $this->request->from('password', 'newpassword', 'confirm');
     $hasher = new PasswordHash(8, true);
     $hashValidate = $hasher->CheckPassword($data['password'], $this->user->password);
     if (!$hashValidate) {
         $this->widget('Widget_Notice')->set('原密码错误!', 'error');
         $this->response->goBack();
     }
     $password = $hasher->HashPassword($data['newpassword']);
     //用户操作类
     $users = $this->widget('Widget_Abstract_Users');
     /** 更新数据 */
     $users->update(array('password' => $password), $this->db->sql()->where('uid = ?', $this->user->uid));
     /** 提示信息 */
     $this->widget('Widget_Notice')->set(_t('密码已经成功修改'), 'success');
     /** 转向原页 */
     $this->response->goBack();
 }
Beispiel #11
0
 /**
  * 引用处理函数
  *
  * @access private
  * @return void
  */
 private function trackback()
 {
     /** 如果不是POST方法 */
     if (!$this->request->isPost() || $this->request->getReferer()) {
         $this->response->redirect($this->_content->permalink);
     }
     /** 如果库中已经存在当前ip为spam的trackback则直接拒绝 */
     if ($this->size($this->select()->where('status = ? AND ip = ?', 'spam', $this->request->getIp())) > 0) {
         /** 使用404告诉机器人 */
         throw new Typecho_Widget_Exception(_t('找不到内容'), 404);
     }
     $trackback = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'trackback', 'status' => $this->options->commentsRequireModeration ? 'waiting' : 'approved');
     $trackback['author'] = $this->request->filter('trim')->blog_name;
     $trackback['url'] = $this->request->filter('trim')->url;
     $trackback['text'] = $this->request->excerpt;
     //检验格式
     $validator = new Typecho_Validate();
     $validator->addRule('url', 'required', 'We require all Trackbacks to provide an url.')->addRule('url', 'url', 'Your url is not valid.')->addRule('url', 'maxLength', 'Your url is not valid.', 200)->addRule('text', 'required', 'We require all Trackbacks to provide an excerption.')->addRule('author', 'required', 'We require all Trackbacks to provide an blog name.')->addRule('author', 'xssCheck', 'Your blog name is not valid.')->addRule('author', 'maxLength', 'Your blog name is not valid.', 200);
     $validator->setBreak();
     if ($error = $validator->run($trackback)) {
         $message = array('success' => 1, 'message' => current($error));
         $this->response->throwXml($message);
     }
     /** 截取长度 */
     $trackback['text'] = Typecho_Common::subStr($trackback['text'], 0, 100, '[...]');
     /** 如果库中已经存在重复url则直接拒绝 */
     if ($this->size($this->select()->where('cid = ? AND url = ? AND type <> ?', $this->_content->cid, $trackback['url'], 'comment')) > 0) {
         /** 使用403告诉机器人 */
         throw new Typecho_Widget_Exception(_t('禁止重复提交'), 403);
     }
     /** 生成过滤器 */
     $trackback = $this->pluginHandle()->trackback($trackback, $this->_content);
     /** 添加引用 */
     $this->insert($trackback);
     /** 评论完成接口 */
     $this->pluginHandle()->finishTrackback($this);
     /** 返回正确 */
     $this->response->throwXml(array('success' => 0, 'message' => 'Trackback has registered.'));
 }
Beispiel #12
0
 public function action()
 {
     // protect
     $this->security->protect();
     /** 如果已经登录 */
     if ($this->user->hasLogin()) {
         /** 直接返回 */
         $this->response->redirect($this->options->index);
     }
     /** 如果未开启注册 */
     if (!$this->options->allowRegister) {
         /** 直接返回 */
         $this->widget('Widget_Notice')->set('未开启注册!', 'error');
         $this->response->redirect($this->options->index);
     }
     /** 初始化验证类 */
     $validator = new Typecho_Validate();
     $validator->addRule('captcha', 'required', _t('必须填写验证码'));
     $validator->addRule('captcha', array($this, 'checkCaptcha'), _t('验证码错误'));
     $validator->addRule('name', 'required', _t('必须填写用户名称'));
     $validator->addRule('name', 'minLength', _t('用户名至少包含2个字符'), 2);
     $validator->addRule('name', 'maxLength', _t('用户名最多包含32个字符'), 32);
     $validator->addRule('name', 'xssCheck', _t('请不要在用户名中使用特殊字符'));
     $validator->addRule('name', array($this, 'nameExists'), _t('用户名已经存在'));
     $validator->addRule('mail', 'required', _t('必须填写电子邮箱'));
     $validator->addRule('mail', array($this, 'mailExists'), _t('电子邮箱地址已经存在'));
     $validator->addRule('mail', 'email', _t('电子邮箱格式错误'));
     $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200);
     /** 如果请求中有password */
     $validator->addRule('password', 'required', _t('必须填写密码'));
     $validator->addRule('password', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6);
     $validator->addRule('password', 'maxLength', _t('为了便于记忆, 密码长度请不要超过十八位'), 18);
     $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'password');
     /** 截获验证异常 */
     if ($error = $validator->run($this->request->from('captcha', 'name', 'password', 'mail', 'confirm'))) {
         Typecho_Cookie::set('__typecho_remember_name', $this->request->name);
         Typecho_Cookie::set('__typecho_remember_mail', $this->request->mail);
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error, 'error');
         $this->response->goBack();
     }
     $hasher = new PasswordHash(8, true);
     //$generatedPassword = Typecho_Common::randString(7);
     $extend = array();
     $inviter = Typecho_Cookie::get('__typecho_inviter');
     if (!empty($inviter)) {
         $inviter = $this->widget('Widget_Users_Query@name_' . $inviter, 'name=' . $inviter);
         if ($inviter->have()) {
             $extend['inviter'] = $inviter->name;
         }
         Typecho_Cookie::delete('__typecho_inviter');
     }
     $dataStruct = array('name' => $this->request->name, 'mail' => $this->request->mail, 'screenName' => $this->request->name, 'password' => $hasher->HashPassword($this->request->password), 'created' => $this->options->gmtTime, 'group' => 'subscriber', 'extend' => empty($extend) ? '' : serialize($extend));
     $insertId = $this->insert($dataStruct);
     $this->db->fetchRow($this->select()->where('uid = ?', $insertId)->limit(1), array($this, 'push'));
     $this->user->login($this->request->name, $this->request->password);
     $params = array('uid' => $this->user->uid, 'confirm' => $this->user->mail, 'name' => $this->user->screenName, 'type' => 'register');
     //发送验证信息
     Widget_Common::sendVerify($params);
     //注册积分
     Widget_Common::credits('register');
     $this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册,请及时验证邮件', $this->screenName), 'success');
     $this->response->redirect($this->options->index);
 }
Beispiel #13
0
 /**
  * 评论处理函数
  *
  * @throws Typecho_Widget_Exception
  * @throws Exception
  * @throws Typecho_Exception
  */
 private function comment()
 {
     // modified_by_jiangmuzi 2015.09.23
     // 必须登录后才可以回复
     if (!$this->user->hasLogin()) {
         $this->widget('Widget_Notice')->set(_t('请先<a href="%s">登录</a>', $this->options->someUrl('login', null, false) . '?redir=' . $this->request->getRequestUrl()), NULL, 'success');
         $this->response->goBack();
     }
     // end modified
     // 使用安全模块保护
     $this->security->protect();
     $comment = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'comment', 'status' => !$this->_content->allow('edit') && $this->options->commentsRequireModeration ? 'waiting' : 'approved');
     /** 判断父节点 */
     /*
             if ($parentId = $this->request->filter('int')->get('parent')) {
                 if ($this->options->commentsThreaded && ($parent = $this->db->fetchRow($this->db->select('coid', 'cid')->from('table.comments')
                 ->where('coid = ?', $parentId))) && $this->_content->cid == $parent['cid']) {
                     $comment['parent'] = $parentId;
                 } else {
                     throw new Typecho_Widget_Exception(_t('父级评论不存在'));
                 }
             }*/
     //检验格式
     $validator = new Typecho_Validate();
     $validator->addRule('text', 'required', _t('必须填写评论内容'));
     $comment['text'] = $this->request->text;
     /** 记录登录用户的id */
     $comment['authorId'] = $this->user->uid;
     if ($error = $validator->run($comment)) {
         /** 记录文字 */
         Typecho_Cookie::set('__some_remember_text', $comment['text']);
         throw new Typecho_Widget_Exception(implode("\n", $error));
     }
     /** 生成过滤器 */
     try {
         $comment = $this->pluginHandle()->comment($comment, $this->_content);
     } catch (Typecho_Exception $e) {
         Typecho_Cookie::set('__some_remember_text', $comment['text']);
         throw $e;
     }
     // modified_by_jiangmuzi 2015.09.23
     // 解析@数据
     $search = $replace = $atMsg = array();
     $pattern = "/@([^@^\\s^:]{1,})([\\s\\:\\,\\;]{0,1})/";
     preg_match_all($pattern, $comment['text'], $matches);
     if (!empty($matches[1])) {
         $matches[1] = array_unique($matches[1]);
         foreach ($matches[1] as $name) {
             if (empty($name)) {
                 continue;
             }
             $atUser = $this->widget('Widget_Users_Query@name_' . $name, array('name' => $name));
             if (!$atUser->have()) {
                 continue;
             }
             $search[] = '@' . $name;
             $replace[] = '<a href="' . $atUser->ucenter . '" target="_blank">@' . $name . '</a>';
             //提醒at用户
             if ($comment['authorId'] != $atUser->uid && $atUser->uid != $comment['ownerId']) {
                 $atMsg[] = array('uid' => $atUser->uid, 'type' => 'at');
             }
         }
         if (!empty($search)) {
             $comment['text'] = str_replace(@$search, @$replace, $comment['text']);
         }
     }
     // end modified
     /** 添加评论 */
     $commentId = $this->insert($comment);
     Typecho_Cookie::delete('__some_remember_text');
     $this->db->fetchRow($this->select()->where('coid = ?', $commentId)->limit(1), array($this, 'push'));
     //更新最后评论人及时间
     $this->db->query($this->db->update('table.contents')->rows(array('lastUid' => $this->authorId, 'lastComment' => $this->created))->where('cid = ?', $this->cid));
     //提醒主题作者
     if ($comment['authorId'] != $comment['ownerId']) {
         $atMsg[] = array('uid' => $comment['ownerId'], 'type' => 'comment');
     }
     if (!empty($atMsg)) {
         foreach ($atMsg as $v) {
             $this->widget('Widget_Users_Messages')->addMessage($v['uid'], $commentId, $v['type']);
         }
     }
     //触发评论积分规则
     Widget_Common::credits('reply');
     /** 评论完成接口 */
     $this->pluginHandle()->finishComment($this);
     $this->response->goBack('#' . $this->theId);
 }
Beispiel #14
0
 /**
  * 同步插件设置
  *
  * @access public
  * @return void
  */
 public function syncsettings()
 {
     //验证组合表单
     $requests = array_merge($this->request->from('fixedwidth'), $this->request->from('fixedheight'), $this->request->from('fixedratio'));
     $validator = new Typecho_Validate();
     $validator->addRule('fixedwidth', 'isInteger', _t('固定宽度请输入整数数字'));
     $validator->addRule('fixedheight', 'isInteger', _t('固定高度请输入整数数字'));
     $validator->addRule('fixedratio', array(new HighSlide_Plugin(), 'ratioformat'), _t('固定比例请输入:与数字'));
     $validator->addRule('fixedwidth', 'required', _t('固定宽度不能为空'));
     $validator->addRule('fixedheight', 'required', _t('固定高度不能为空'));
     $validator->addRule('fixedratio', 'required', _t('固定比例不能为空'));
     if ($error = $validator->run($requests)) {
         $this->widget('Widget_Notice')->set($error, 'error');
         $this->response->goBack();
     }
     //构建同步数组
     $syncsets = array('qiniubucket', 'qiniudomain', 'qiniuaccesskey', 'qiniusecretkey', 'qiniuprefix', 'upyunbucket', 'upyundomain', 'upyunuser', 'upyunpwd', 'upyunkey', 'upyunprefix', 'bcsbucket', 'bcsapikey', 'bcssecretkey', 'bcsprefix', 'storage', 'local', 'thumbfix', 'fixedwidth', 'fixedheight', 'fixedratio', 'gallery');
     foreach ($syncsets as $syncset) {
         $result = $this->request->from($syncset);
         $datas[$syncset] = $result[$syncset];
     }
     //返回原页并提示信息
     Widget_Plugins_Edit::configPlugin('HighSlide', $datas);
     $this->widget('Widget_Notice')->set(_t('相册设置已保存'), NULL, 'success');
     $this->response->goBack();
 }
Beispiel #15
0
 protected function doCallbackReg()
 {
     $url = $this->request->get('url');
     $validator = new Typecho_Validate();
     $validator->addRule('mail', 'required', _t('必须填写电子邮箱'));
     $validator->addRule('mail', array($this, 'mailExists'), _t('电子邮箱地址已经存在'));
     $validator->addRule('mail', 'email', _t('电子邮箱格式错误'));
     $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200);
     $validator->addRule('screenName', 'required', _t('必须填写昵称'));
     $validator->addRule('screenName', 'xssCheck', _t('请不要在昵称中使用特殊字符'));
     $validator->addRule('screenName', array($this, 'screenNameExists'), _t('昵称已经存在'));
     if ($url) {
         $validator->addRule('url', 'url', _t('个人主页地址格式错误'));
     }
     /** 截获验证异常 */
     if ($error = $validator->run($this->request->from('mail', 'screenName', 'url'))) {
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($error);
         $this->response->goBack();
     }
     $dataStruct = array('mail' => $this->request->mail, 'screenName' => $this->request->screenName, 'created' => $this->options->gmtTime, 'group' => 'subscriber');
     $uid = $this->regConnectUser($dataStruct);
     if ($uid) {
         $this->widget('Widget_Notice')->set(array('已成功注册并登陆!'));
     }
 }