private function _sendAuthEmail($email, $activation_key) { $mail = new mail(); $body = getEmailTpl('authEmail', array('activate_url' => __APP__ . '/auth/authEmail/user/' . $_SESSION['uid'] . '/key/' . $activation_key)); if ($mail->send($email, C('WEB_NAME') . '用户', $body['subject'], $body['content'])) { return TRUE; } return FALSE; }
/** * 注册用户 * @param type $data 注册的信息 用户名密码神马之类的。 */ function register($data) { $result = FALSE; $new_user = $data; $new_user['password'] = md5_d($data['password']); $new_user['last_ip'] = ip_get_client(); // 发送电子邮件来激活用户 if (C('AUTH_EMAIL_ACTIVATE')) { // 添加激活密钥到new_user array $new_user['activation_key'] = token(); // 在数据库中创建的临时用户,用户仍然未激活。 $insert = $this->auth_model->create_temp($new_user); } else { // 创建用户 $insert = $this->auth_model->create_user($new_user); // 增加用户积分/创建用户资料…… $this->_user_activated($insert, $new_user['rid']); } if ($insert) { // 原始密码 $new_user['password'] = $data['password']; $result = $new_user; // 按照配置文件中的信息发送电子邮件 // 如果用户需要使用电子邮件激活帐户 if (C('AUTH_EMAIL_ACTIVATE')) { // 创建Email $from = C('email_username'); $subject = sprintf(L('auth_activate_subject'), C('WEB_NAME')); // 激活链接 $new_user['activate_url'] = __WEB__ . '/index/auth/activate/username/' . $new_user['username'] . '/key/' . $new_user['activation_key']; // 触发事件,并获得电子邮件的内容 $new_user['expire'] = C('EMAIL_ACTIVATE_EXPIRE') / 3600 . '小时'; $content = getEmailTpl('register_active', $new_user); // 发送激活链接到邮件 $this->_send_email($new_user['email'], $from, $content['subject'], $content['content']); } else { // 没有开启邮箱验证注册,但是注册后会发送账户信息 if (C('EMAIL_ACCOUNT_INFO')) { $from = C('email_username'); $subject = sprintf(L('auth_account_subject'), C('WEB_NAME')); $content = getEmailTpl('register_info', $new_user); $this->_send_email($new_user['email'], $from, $content['subject'], $content['content']); } } } return $result; }