/** * 一键登录返回 */ public function callbackAction() { $oauthconfig = $this->loadOauth(); if (!$oauthconfig) { $this->memberMsg(lang('m-log-15')); } oauth_callback($oauthconfig); $oauth_data = $this->session->get('oauth_data'); $oauth_name = $this->session->get('oauth_name'); $memberinfo = get_user_info($oauthconfig, $oauth_data); if (empty($oauth_data['oauth_openid']) || empty($oauth_name)) { $this->memberMsg(lang('m-log-12')); } if (empty($memberinfo['name']) && empty($memberinfo['avatar'])) { $this->memberMsg(lang('a-mod-200')); } //查询是否已经绑定 $omember = $this->member->from('oauth')->where("oauth_openid = '" . $oauth_data['oauth_openid'] . "' AND oauth_name = '" . $oauth_name . "'")->select(false); if (empty($omember)) { //绑定用户,v1.7.7修改为直接注册 //注册会员 $pwd = rand(0, 9999); $data = array('username' => $oauth_name . time() . rand(0, 999), 'password' => $pwd, 'password2' => $pwd, 'email' => $oauth_name . $oauth_data['oauth_openid'] . '@dayrui.com', 'nickname' => (string) $memberinfo['name'], 'avatar' => $memberinfo['avatar']); $uid = $this->reg($data); if (empty($uid)) { $this->memberMsg(lang('m-reg-2')); } $data['id'] = $uid; $this->bang($data); $this->regEmail($data); //注册邮件提示 //登录cookie set_cookie('member_id', $uid, 24 * 3600); set_cookie('member_code', substr(md5(SITE_MEMBER_COOKIE . $uid), 5, 20), $time); $this->memberMsg(lang('m-log-4'), url('member/'), 1); } else { //验证成功,判断用户表 $member = $this->member->where('username=?', $omember['username'])->select(false); if (empty($member)) { $this->memberMsg(lang('m-log-14'), url('member/login')); } $oauth = $this->model('oauth'); //更新登录时间 $oauth->update(array('logintime' => time(), 'logintimes' => $omember['logintime'], 'oauth_data' => array2string($oauth_data)), 'id=' . $omember['id']); $this->update_login_info($member); set_cookie('member_id', $member['id'], 24 * 3600); //保存会话24小时。 set_cookie('member_code', substr(md5(SITE_MEMBER_COOKIE . $member['id']), 5, 20), 24 * 3600); if ($this->memberconfig['uc_use'] == 1) { list($uid) = uc_get_user($member['username']); if ($uid > 0) { $ucsynlogin = uc_user_synlogin($uid); $this->memberMsg(lang('m-log-4') . $ucsynlogin, url('member/'), 1); } } $this->memberMsg(lang('m-log-4'), url('member/'), 1); } }
// of (severe?, line, description) read_base(); parse_text($text); // Now process actions if ($action == 'login' || isset($_REQUEST['login'])) { if ($loggedin) { $error = _('Yor are already logged in.'); } else { if (count($userdata) || count($basedata)) { $_SESSION['l0id'] = $l0id; store_user($text); } oauth_login(); } } elseif ($action == 'callback') { oauth_callback(); } elseif ($action == 'logout' || isset($_REQUEST['logout'])) { oauth_logout(); $loggedin = false; } elseif (isset($_REQUEST['add']) || isset($_REQUEST['replace']) || isset($_REQUEST['url']) && strlen($_REQUEST['url']) > 0) { if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) { if ($_FILES['file']['error'] > 0) { $errors = array('OK', _('too big'), _('bigger than MAX_FILE_SIZE'), _('partial upload'), _('no file'), '', _('nowhere to store'), _('failed to write'), _('extension error')); $error = sprintf(_('Error uploading file: %s.'), $errors[$_FILES['file']['error']]); } else { $url = $_FILES['file']['tmp_name']; } } elseif (isset($_REQUEST['url']) && strlen($_REQUEST['url']) > 0) { $url = url_to_api($_REQUEST['url']); if ($url === false) { $error = _('Could not parse the URL.');