Exemplo n.º 1
0
 /**
  * 
  * 用户注册方法
  * @param array $data
  */
 public function doAddUser($data)
 {
     #非法操作,踢出去
     if (empty($username = $data['username']) || empty($password = $data['password'])) {
         echo parent::errorEcho('请正确填写用户名和密码', 'Users/addUser');
         exit;
     }
     if ($password !== $data['chkPass']) {
         echo parent::errorEcho('两次输入的密码不一致', 'Users/addUser');
         exit;
     }
     unset($data['chkPass']);
     #实例化Users模型
     $userMod = new UsersModel();
     //如果用户已经存在,则输出错误
     if ($userMod->where('username="******"', $username)->field("username")->find()) {
         echo parent::errorEcho('用户名:' . $username . '已经存在了', 'Users/addUser');
         exit;
     }
     #给users表插入新用户数据
     $data['password'] = md5($data['password']);
     $data['regtime'] = time();
     $uid = $userMod->add($data);
     $data['uid'] = $uid;
     #实例化UserInfo模型
     $userInfoMod = new UserinfoModel();
     if ($userInfoMod->add($data)) {
         echo parent::errorEcho('注册成功', 'Users/addUser');
         exit;
     }
 }
Exemplo n.º 2
0
 /**
  * 
  * 获得文章作者
  * @param $post (array) 文章参数 
  */
 public function getForumAuthor($post)
 {
     $infoModel = new userinfo();
     foreach ($post as $k => &$item) {
         if (is_array($item)) {
             $uid = $item['author_id'];
             $info = $infoModel->where('uid=%d', $uid)->field('niconame')->find();
             $item['author'] = $info['niconame'];
         } else {
             $uid = $post['author_id'];
             $info = $infoModel->where('uid=%d', $uid)->field('niconame')->find();
             $post['author'] = $info['niconame'];
             return $post;
         }
     }
     return $post;
 }