public function __construct() { $this->db = Loader::model('member_model'); $this->verify_db = Loader::model('member_verify_model'); if (ucenter_exists()) { $this->uc = Loader::lib('member:uc_client'); } }
public function __construct() { self::check_ip(); if (method_exists($this, '_initialize')) { $this->_initialize(); } // 控制器初始化 $http_user_agent = str_replace('7.0', '8.0', $_SERVER['HTTP_USER_AGENT']); $this->auth_key = md5(C('config', 'auth_key') . $http_user_agent); $this->db = Loader::model('member_model'); // ajax验证信息不需要登录 if (substr(ACTION, 0, 7) != 'public_') { $this->check_member(); } if (ucenter_exists()) { $this->uc = Loader::lib('member:uc_client'); } }
/** * 用户登陆 * * @param string $username 用户名或邮箱 * @param string $password 密码 * @return array userid 大于 0:返回用户 ID,表示用户登录成功 -1:用户不存在,或者被删除 -2:密码错 * -3:安全提问错 -4 用户被锁定 */ public function login($username, $password) { $field = strpos($username, '@') ? 'email' : 'username'; // 判断是否是邮箱 $res = $this->get_user($username, $field); if (!$res) { return array('userid' => -1); // 用户不存在 } $pwd = password($password, $res['encrypt']); if ($res['password'] != $pwd) { return array('userid' => -2); // 密码错误 } $res['password'] = $pwd; if ($res['islock'] == 1) { return array('userid' => -4); // 用户被锁定 } if (ucenter_exists()) { // UCenter登录 $ucuid = Loader::lib('member:uc_client')->uc_user_login($username, $password); if ($ucuid < 0) { return array('userid' => $ucuid); } $res['synloginstr'] = Loader::lib('member:uc_client')->uc_user_synlogin($ucuid); } $updatearr = array('lastip' => IP, 'lastdate' => TIME); // 检查用户积分,更新新用户组,除去邮箱认证、禁止访问、游客组用户、vip用户 if ($res['point'] >= 0 && !in_array($res['groupid'], array('1', '2', '3')) && empty($res['vip'])) { $check_groupid = $this->_get_usergroup_bypoint($res['point']); if ($check_groupid != $res['groupid']) { $updatearr['groupid'] = $groupid = $check_groupid; } } $this->update($updatearr, array('userid' => $res['userid'])); return $res; }
/** * 获取用户头像 * * @param $uid 默认为userid * @param $size 头像大小有四种[30x30 45x45 90x90 180x180] 默认30 */ function get_memberavatar($userid, $size = '30') { $memberinfo = Loader::model('member_model')->getby_userid($userid); if (!$memberinfo) { return false; } if (ucenter_exists() && isset($memberinfo['ucenterid'])) { $avatar = Loader::lib('member:uc_client')->uc_get_avatar($memberinfo['ucenterid']); } else { if (!$memberinfo['avatar']) { return false; } $dir1 = ceil($userid / 10000); $dir2 = ceil($userid % 10000 / 1000); $url = C('attachment', 'avatar_url') . $dir1 . '/' . $dir2 . '/' . $userid . '/'; $avatar = array('180' => $url . '180x180.jpg', '90' => $url . '90x90.jpg', '45' => $url . '45x45.jpg', '30' => $url . '30x30.jpg'); } if (isset($avatar) && !$size) { return $avatar; } else { if (isset($avatar[$size])) { return $avatar[$size]; } else { return false; } } }
/** * delete member */ public function delete() { $uidarr = isset($_POST['userid']) ? $_POST['userid'] : showmessage(L('illegal_parameters'), HTTP_REFERER); $userids = implode(',', $uidarr); $where = array('userid' => array('in', $userids)); if (ucenter_exists()) { $uc_client = Loader::lib('member:uc_client'); $userinfo = $this->db->where($where)->listinfo(); if (is_array($userinfo)) { foreach ($userinfo as $v) { $status = $uc_client->uc_user_delete($v['ucenterid']); if ($status < 1) { showmessage(L('operation_failure'), HTTP_REFERER); } } } } if ($this->db->where($where)->delete()) { Loader::model('member_bind_model')->where($where)->delete(); showmessage(L('operation_success'), HTTP_REFERER); } else { showmessage(L('operation_failure'), HTTP_REFERER); } }
/** * 测试邮件配置 */ public function send_newmail() { $_username = cookie('_regusername'); $_userid = cookie('_reguserid'); $newemail = isset($_GET['newemail']) ? $_GET['newemail'] : exit('2'); $check = $this->api->check_email($newemail); if ($check != 1) { exit((string) $check); } $userinfo = $this->db->getby_username($_username); if ($userinfo) { if (!isset($userinfo['userid']) || $userinfo['userid'] != intval($_userid)) { exit('-6'); } } else { exit('-6'); } $yuncms_auth_key = md5(C('config', 'auth_key')); $code = String::authcode($_userid . '|' . $yuncms_auth_key, 'ENCODE', $yuncms_auth_key); $url = SITE_URL . "index.php?app=member&controller=passport&action=verify&code={$code}&verify=1"; $message = $this->member_setting['registerverifymessage']; $message = str_replace(array('{click}', '{url}', '{username}', '{email}'), array('<a href="' . $url . '">' . L('please_click') . '</a>', $url, $_username, $newemail), $message); if (sendmail($newemail, L('reg_verify_email'), $message)) { // 更新新的邮箱,用来验证 $this->db->where(array('userid' => $_userid))->update(array('email' => $newemail)); if (ucenter_exists()) { Loader::lib('member:uc_client')->uc_user_edit($_username, '', '', $newemail, 1); } $return = '1'; } else { $return = '2'; } echo $return; }
/** * 修改邮箱密码 */ public function account_manage_password() { if (isset($_POST['dosubmit'])) { if (!Validate::is_password($_POST['info']['password'])) { showmessage(L('password_format_incorrect'), HTTP_REFERER); } if ($this->memberinfo['password'] != password($_POST['info']['password'], $this->memberinfo['encrypt'])) { showmessage(L('old_password_incorrect'), HTTP_REFERER); } // 修改会员邮箱 if ($this->memberinfo['email'] != $_POST['info']['email'] && Validate::is_email($_POST['info']['email'])) { $email = $_POST['info']['email']; $updateinfo['email'] = $_POST['info']['email']; } else { $email = ''; } $newpassword = password($_POST['info']['newpassword'], $this->memberinfo['encrypt']); $updateinfo['password'] = $newpassword; $this->db->where(array('userid' => $this->memberinfo['userid']))->update($updateinfo); if (ucenter_exists()) { $res = Loader::lib('Ucenter')->uc_user_edit($this->memberinfo['username'], $_POST['info']['password'], $_POST['info']['newpassword'], '', $this->memberinfo['encrypt'], 1); } showmessage(L('operation_success'), HTTP_REFERER); } else { $show_validator = true; $memberinfo = $this->memberinfo; include template('member', 'account_manage_password'); } }