function __construct() { $this->member_db = pc_base::load_model('member_model'); pc_base::load_sys_class('uc_model', 'model', 0); $db_config = get_uc_database(); $this->uc_db = new uc_model($db_config); $this->applist = getcache('applist', 'admin'); }
/** * 用户登录 * @param string $username 用户名 * @param string $password 密码 * @return array {-2;密码错误;-1:用户不存在;array(userinfo):用户信息} */ public function login() { $this->password = isset($this->data['password']) ? $this->data['password'] : ''; $this->email = isset($this->data['email']) ? $this->data['email'] : ''; if($this->email) { $userinfo = $this->db->get_one(array('email'=>$this->email)); } else { $userinfo = $this->db->get_one(array('username'=>$this->username)); } if ($this->config['ucuse']) { pc_base::load_config('uc_config'); require_once PHPCMS_PATH.'api/uc_client/client.php'; list($uid, $uc['username'], $uc['password'], $uc['email']) = uc_user_login($this->username, $this->password, 0); } if($userinfo) { //ucenter登陆部份 if ($this->config['ucuse']) { if($uid == -1) { //uc不存在该用户,调用注册接口注册用户 $uid = uc_user_register($this->username , $this->password, $userinfo['email'], $userinfo['random']); if($uid >0) { $this->db->update(array('ucuserid'=>$uid), array('username'=>$this->username)); } } } } else { //用户在phpsso中不存在 //ucenter登陆部份 if ($this->config['ucuse']) { if ($uid < 0) { //用户不存在或者密码错误 exit('-1'); } else { //当前使用只在uc中存在,在PHPSSO中是不存在的。需要进行注册。 pc_base::load_sys_class('uc_model', 'model', 0); $db_config = get_uc_database(); $uc_db = new uc_model($db_config); //获取UC中用户的信息 $r = $uc_db->get_one(array('uid'=>$uid)); $datas = $data = array('username'=>$r['username'], 'password'=>$r['password'], 'random'=>$r['salt'], 'email'=>$r['email'], 'regip'=>$r['regip'], 'regdate'=>$r['regdate'], 'lastdate'=>$r['lastlogindate'], 'appname'=>'ucenter', 'type'=>'app'); $datas['ucuserid'] = $uid; $datas['lastip'] = $r['lastloginip']; if ($data['uid'] = $this->db->insert($datas, true)) { //向所有的应用中发布新用户注册通知 messagequeue::add('member_add', $data); } $userinfo = $data; } } else { exit('-1'); } } //如果开启phpcms_2008_sp4兼容模式,根据sp4规则验证密码,如果不成功再根据phpsso规则验证密码 $setting_sp4 = getcache('settings_sp4', 'admin'); if($setting_sp4['sp4use']) { if(!empty($userinfo) && $userinfo['password'] == md5($setting_sp4['sp4_password_key'].$this->password)) { //登录成功更新用户最近登录时间和ip $this->db->update(array('lastdate'=>SYS_TIME, 'lastip'=>ip()), array('uid'=>$userinfo['uid'])); exit(serialize($userinfo)); } } if(!empty($userinfo) && $userinfo['password'] == create_password($this->password, $userinfo['random'])) { //登录成功更新用户最近登录时间和ip $this->db->update(array('lastdate'=>SYS_TIME, 'lastip'=>ip()), array('uid'=>$userinfo['uid'])); exit(serialize($userinfo)); } else { exit('-2'); } }