public function doAddUser() { //参数合法性检查 $required_field = array('email' => 'Email', 'password' => '密码', 'uname' => '姓名'); foreach ($required_field as $k => $v) { if (empty($_POST[$k])) { $this->error($v . '不可为空'); } } if (!isValidEmail($_POST['email'])) { $this->error('Email格式错误,请重新输入'); } if (strlen($_POST['password']) < 6 || strlen($_POST['password']) > 16) { $this->error('密码必须为6-16位'); } if (!isEmailAvailable($_POST['email'])) { $this->error('Email已经被使用,请重新输入'); } if (!isLegalUsername(t($_POST['uname']))) { $this->error('昵称格式不正确'); } $haveName = M('User')->where("`uname`='" . t($_POST['uname']) . "'")->find(); if (is_array($haveName) && sizeof($haveName) > 0) { $this->error('昵称已被使用'); } //注册用户 $_POST['uname'] = escape(h(t($_POST['uname']))); $_POST['password'] = md5($_POST['password']); $_POST['domain'] = h($_POST['domain']); $_POST['ctime'] = time(); $_POST['is_active'] = intval($_POST['is_active']); $_POST['sex'] = intval($_POST['sex']); $_POST['is_init'] = '1'; $_LOG['uid'] = $this->mid; $_LOG['type'] = '1'; $data[] = '用户 - 用户管理 '; if ($_POST['__hash__']) { unset($_POST['__hash__']); } $data[] = $_POST; $_LOG['data'] = serialize($data); $_LOG['ctime'] = time(); M('AdminLog')->add($_LOG); $uid = M('user')->add($_POST); if (!$uid) { $this->error('抱歉:注册失败,请稍后重试'); exit; } //添加用户组信息 model('UserGroup')->addUserToUserGroup($uid, t($_POST['user_group_id'])); $this->success('注册成功'); }
public function login_register_on_client() { if (!in_array($_POST['type'], array('douban', 'sina', 'qq'))) { $this->_loginFailureOnClient('参数错误'); } if (!isLegalUsername(t($_POST['uname']))) { $this->_loginFailureOnClient('昵称格式不正确'); } $haveName = M('User')->where("`uname`='" . t($_POST['uname']) . "'")->find(); if (is_array($haveName) && count($haveName) > 0) { $this->_loginFailureOnClient('昵称已被使用'); } $type = $_POST['type']; $this->_loadTypeLogin($type); $platform = new $type(); $userinfo = $platform->userInfo(); // 检查是否成功获取用户信息 if (empty($userinfo['id']) || empty($userinfo['uname'])) { $this->_loginFailureOnClient('获取用户信息失败'); } // 检查是否已加入本站 $map['type_uid'] = $userinfo['id']; $map['type'] = $type; if (($local_uid = M('login')->where($map)->getField('uid')) && M('user')->where('uid=' . $local_uid)->find()) { $this->_loginSuccessOnClient($local_uid, $type); } // 初使化用户信息, 激活帐号 $data['uname'] = t($_POST['uname']) ? t($_POST['uname']) : $userinfo['uname']; $data['province'] = intval($userinfo['province']); $data['city'] = intval($userinfo['city']); $data['location'] = $userinfo['location']; $data['sex'] = intval($userinfo['sex']); $data['is_active'] = 1; $data['is_init'] = 1; $data['ctime'] = time(); $data['is_synchronizing'] = $type == 'sina' ? '1' : '0'; // 是否同步新浪分享. 目前仅能同步新浪分享 if ($id = M('user')->add($data)) { // 记录至同步登录表 $syncdata['uid'] = $id; $syncdata['type_uid'] = $userinfo['id']; $syncdata['type'] = $type; $syncdata['oauth_token'] = $_SESSION[$type]['access_token']['oauth_token']; $syncdata['oauth_token_secret'] = $_SESSION[$type]['access_token']['oauth_token_secret']; M('login')->add($syncdata); // 转换头像 if ($_POST['type'] != 'qq') { // 暂且不转换QQ头像: QQ头像的转换很慢, 且会拖慢apache D('Avatar')->saveAvatar($id, $userinfo['userface']); } // 将用户添加到myop_userlog,以使漫游应用能获取到用户信息 $userlog = array('uid' => $id, 'action' => 'add', 'type' => '0', 'dateline' => time()); M('myop_userlog')->add($userlog); service('Passport')->loginLocal($id); $this->registerRelation($id); $this->_loginSuccessOnClient($id, $type); } else { $this->_loginFailureOnClient('同步帐号发生错误'); } }
function isValidUname($uname) { return isLegalUsername($uname); }
/** * uc登陆或者注册。返回数组 * $result['user'] 用户信息。用于ts系统使用 * $result['login'] 同步登陆是否成功 * @param unknown_type $username * @param unknown_type $password */ public function ucLogin($username, $password) { if (isValidEmail($username)) { $user = service('Passport')->getLocalUser($username, $password); if (UC_SYNC && $user['uid']) { $uc_user_ref = ts_get_ucenter_user_ref($user['uid']); if ($uc_user_ref['uc_uid']) { $uc_user = uc_user_login($uc_user_ref['uc_uid'], $password, 1); if ($uc_user[0] == -1 || $uc_user[0] == -2) { $uc_user_ref = array(); } } else { if ($user['uname']) { $res_checkname = uc_user_checkname($user['uname']); if ($res_checkname >= -3 && $res_checkname <= -1) { $error_param = L('username'); } $res_checkemail = uc_user_checkemail($username); if ($res_checkemail >= -6 && $res_checkemail <= -4) { $error_param = $error_param ? $error_param . L('and_email') : 'Email'; } if ($error_param) { $message_data['title'] = L('sync_ucenter') . $error_param . L('sign_in_failed'); $message_data['content'] = L('you_of_site') . $error_param . L('ucenter_sign_in_failed') . $error_param . L('ucenter_clash') . U('home/Account/security') . L('ucenter_reset') . $error_param . '。'; $message_data['to'] = $user['uid']; model('Message')->postMessage($message_data, M('user')->getField('uid', 'admin_level=1')); } else { $uc_uid = uc_user_register($user['uname'], $password, $username); ts_add_ucenter_user_ref($user['uid'], $uc_uid, $user['uname']); $uc_user[0] = $uc_uid; } } } } } else { if (UC_SYNC) { $uc_user = uc_user_login($username, $password); if ($uc_user[0] > 0) { $uc_user_ref = ts_get_ucenter_user_ref('', $uc_user[0]); if (!$uc_user_ref) { // 注册 if ($this->isValidEmail($uc_user['3']) && $this->isEmailAvailable($uc_user['3'])) { $user['email'] = $uc_user['3']; } else { $message_data['title'] = L('ucenter_sync_email_clash'); $message_data['content'] = L('ucenter_email_used') . U('home/Account/bind') . L('ucenter_reset_email'); } if (isLegalUsername($uc_user['1']) && !M('user')->where("uname='{$uc_user['1']}'")->count()) { $user['uname'] = $uc_user['1']; } $user['password'] = md5($uc_user['2']); $user['ctime'] = time(); $user['is_active'] = 1; $user['uid'] = M('user')->add($user); if ($user['uid']) { $reg_from_ucenter = 1; ts_add_ucenter_user_ref($user['uid'], $uc_user['0'], $uc_user['1']); // 将用户添加到myop_userlog,以使漫游应用能获取到用户信息 $userlog = array('uid' => $user['uid'], 'action' => 'add', 'type' => '0', 'dateline' => time()); M('myop_userlog')->add($userlog); if (isset($message_data) && !empty($message_data)) { $message_data['to'] = $user['uid']; model('Message')->postMessage($message_data, M('user')->getField('uid', 'admin_level=1')); } //关联操作 //$this->registerRelation($user['uid']); } else { $user = array(); } } else { if ($username != $uc_user_ref['uc_username']) { ts_update_ucenter_user_ref('', $uc_user_ref['uc_uid'], $username); } $user = M('user')->where("uid={$uc_user_ref['uid']}")->find(); if (md5($password) != $user['password']) { M('user')->where("uid={$uc_user_ref['uid']}")->setField('password', md5($password)); } } } } else { $uc_user_ref = ts_get_ucenter_user_ref('', '', $username); if ($uc_user_ref['uid']) { $user = service('Passport')->getLocalUser($uc_user_ref['uid'], $password); } } } $result['login'] = ''; if ($user) { $result['login'] = UC_SYNC && $uc_user[0] ? uc_user_synlogin($uc_user[0]) : ''; } $result['user'] = $user; $result['reg_from_ucenter'] = $reg_from_ucenter; return $result; }
public function doModifyUCenter() { include_once SITE_PATH . '/api/uc_client/uc_sync.php'; if (UC_SYNC) { $uc_user_ref = ts_get_ucenter_user_ref($this->mid); if (!$uc_user_ref) { $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; if (uc_user_checkname($username) != 1 || !isLegalUsername($username) || M('user')->where("uname='{$username}' AND uid<>{$this->mid}")->count()) { $this->error('Tên tài khoản không hợp lệ hoặc đã tồn tại, hãy nhập lại'); } if (uc_user_checkemail($email) != 1 || M('user')->where("uname='{$email}' AND uid<>{$this->mid}")->count()) { $this->error('Email không hợp lệ hoặc đã tồn tại, hãy nhập lại'); } global $ts; if (md5($password) != $ts['user']['password']) { $this->error(L('password_error_retype')); } $uc_uid = uc_user_register($username, $password, $email); if ($uc_uid > 0) { ts_add_ucenter_user_ref($this->mid, $uc_uid, $username); $this->assign('jumpUrl', U('home/Account/security')); $this->success(L('ucenter_setting_success')); } else { $this->error(L('ucenter_setting_error')); } } else { redirect(U('home/Account/security')); } } else { redirect(U('home/Account/security')); } }
public function isValidNickName($name) { $return_type = empty($name) ? 'ajax' : 'return'; $name = empty($name) ? t($_POST['nickname']) : $name; if (UC_SYNC) { $uc_res = uc_user_checkname($name); if ($uc_res == -1 || !isLegalUsername($name)) { if ($return_type === 'ajax') { echo L('username_rule'); return; } else { return false; } } } else { if (!isLegalUsername($name)) { if ($return_type === 'ajax') { echo L('username_rule'); return; } else { return false; } } } if ($this->mid) { $res = M('user')->where("uname='{$name}' AND uid<>{$this->mid}")->count(); $nickname = M('user')->getField('uname', "uid={$this->mid}"); if (UC_SYNC && ($uc_res == -2 || $uc_res == -3) && $nickname != $name) { $res = 1; } } else { $res = M('user')->where("uname='{$name}'")->count(); if (UC_SYNC && ($uc_res == -2 || $uc_res == -3)) { $res = 1; } } if (!$res) { if ($return_type === 'ajax') { echo 'success'; } else { return true; } } else { if ($return_type === 'ajax') { echo L('username_used'); } else { return false; } } }
D('Atme', 'weibo')->where($map)->delete(); D('Comment', 'weibo')->where($map)->delete(); D('Favorite', 'weibo')->where($map)->delete(); D('Follow', 'weibo')->where(array('uid' => array('IN', $uids), 'follow_id' => array('IN', $uids), '_logic' => 'OR'))->delete(); D('FollowGroup', 'weibo')->where(array('uid' => array('IN', $uids), 'follow_id' => array('IN', $uids), '_logic' => 'OR'))->delete(); M('follow_group_link')->where($map)->delete(); D('Star', 'weibo')->where($map)->delete(); //删除用户附件 $all_attach = M('Attach')->where(array('userId' => array('IN', $uids)))->findAll(); foreach ($all_attach as $v) { unlink(UPLOAD_PATH . '/' . $v['savepath'] . $v['savename']); } $result = M('attach')->where(array('userId' => array('IN', $uids)))->delete(); if ($result) { echo 'delete succesful!'; } } return $res; } /** * 更新操作 * * @param string $type 操作 * @return boolean */ function upDate($type) { return $this->{$type}(); } /** * 更新基本信息 * * @return array */ private function upbase() {