/** * 新規登録のメール処理 * * @param int $confirmation 完了確認ステータス * @param array $user ユーザ情報 * @return bool */ public function sendMail($confirmation, $user) { if ($confirmation === AutoUserRegist::CONFIRMATION_USER_OWN) { $data['subject'] = SiteSettingUtil::read('AutoRegist.approval_mail_subject'); $data['body'] = SiteSettingUtil::read('AutoRegist.approval_mail_body'); $data['email'] = array($user['User']['email']); $data['url'] = Router::url('/auth/auto_user_regist/approval', true) . $user['User']['activate_parameter']; } elseif ($confirmation === AutoUserRegist::CONFIRMATION_ADMIN_APPROVAL) { $data['subject'] = SiteSettingUtil::read('AutoRegist.acceptance_mail_subject'); $data['body'] = SiteSettingUtil::read('AutoRegist.acceptance_mail_body'); $data['email'] = $this->__getMailAddressForAdmin(); $data['url'] = Router::url('/auth/auto_user_regist/acceptance', true) . $user['User']['activate_parameter']; } else { return true; } foreach ($data['email'] as $email) { $this->mail->mailAssignTag->setFixedPhraseSubject($data['subject']); $this->mail->mailAssignTag->setFixedPhraseBody($data['body']); $this->mail->mailAssignTag->assignTags(array('X-URL' => $data['url'])); $this->mail->mailAssignTag->initPlugin(Current::read('Language.id')); $this->mail->initPlugin(Current::read('Language.id')); $this->mail->to($email); $this->mail->setFrom(Current::read('Language.id')); $this->mail->sendMailDirect(); } return true; }
/** * メール送信 * * @return void */ public function send() { // SiteSettingからメール設定を取得する SiteSettingUtil::setup(array('Mail.from', 'Mail.from_name', 'Mail.messageType', 'Mail.transport', 'Mail.smtp.host', 'Mail.smtp.port', 'Mail.smtp.user', 'Mail.smtp.pass', 'App.site_name')); $from = SiteSettingUtil::read('Mail.from'); // Fromが空ならメール未設定のため、メール送らない if (empty($from)) { $this->out('<error>From Address is empty. [' . __METHOD__ . ']</error>'); return $this->_stop(); } $now = NetCommonsTime::getNowDatetime(); // キュー取得&ロック - シェル実行の排他を実現したいため、行ロックしている // http://k-1blog.com/development/program/post-7407/ // http://d.hatena.ne.jp/fat47/20140212/1392171784 // 下記SQL(テーブル結合&範囲条件)でSELECT FOR UPDATEを実行すると、テーブルロック $sql = 'SELECT * FROM ' . 'mail_queues MailQueue, ' . 'mail_queue_users MailQueueUser ' . 'WHERE ' . 'MailQueue.id = MailQueueUser.mail_queue_id ' . 'AND MailQueue.send_time <= ? ' . 'FOR UPDATE '; $mailQueues = $this->MailQueue->query($sql, array($now)); if (empty($mailQueues)) { $this->out('MailQueue is empty. [' . __METHOD__ . '] '); return $this->_stop(); } $beforeId = $mailQueues[0]['MailQueue']['id']; $isSend = null; foreach ($mailQueues as $mailQueue) { // idが変わったら、MailQueue削除 if ($beforeId != $mailQueue['MailQueue']['id']) { $this->MailQueue->delete($beforeId); $isSend = null; } // ブロック非公開、期間限定の対応 if (is_null($isSend)) { $isSend = $this->_isSendBlockType($mailQueue); } if ($isSend) { $mail = new NetCommonsMail(); $mail->initShell($mailQueue); try { $mail->sendQueueMail($mailQueue['MailQueueUser'], $mailQueue['MailQueue']['language_id']); } catch (Exception $ex) { // SMTPの設定間違い等で送れなくても、処理を続行。メールは破棄(設定間違いでメールがキューに溜まる事を防ぐ) CakeLog::error($ex); } } // MailQueueUser削除 $this->MailQueueUser->delete($mailQueue['MailQueueUser']['id']); $beforeId = $mailQueue['MailQueue']['id']; } // 後始末 - MailQueue削除 $this->MailQueue->delete($beforeId); }
/** * delete method * * @return void */ public function delete() { $this->__prepare(); if (!SiteSettingUtil::read('UserCancel.use_cancel_feature', false)) { return $this->throwBadRequest(); } if (Hash::get($this->viewVars['user'], 'User.id') !== Current::read('User.id') || $this->viewVars['user']['User']['role_key'] === UserRole::USER_ROLE_KEY_SYSTEM_ADMINISTRATOR) { return $this->throwBadRequest(); } if (!$this->request->is('delete')) { return $this->throwBadRequest(); } $this->User->deleteUser($this->viewVars['user']); $this->redirect('/auth/logout'); }
/** * 新規登録の完了 * * @return void **/ public function completion() { //ウィザードのリンク削除 $this->helpers['NetCommons.Wizard']['navibar'] = Hash::remove($this->helpers['NetCommons.Wizard']['navibar'], '{s}.url'); $value = SiteSettingUtil::read('AutoRegist.confirmation'); if ($value === AutoUserRegist::CONFIRMATION_USER_OWN) { $message = __d('auth', 'Confirmation e-mail will be sent to the registered address, ' . 'after the system administrator approve your registration.'); $redirectUrl = '/'; } elseif ($value === AutoUserRegist::CONFIRMATION_AUTO_REGIST) { $message = __d('auth', 'Thank you for your registration. Click on the link, please login.'); $redirectUrl = '/auth/auth/login'; } else { $message = __d('auth', 'Your registration will be confirmed by the system administrator. <br>' . 'When confirmed, it will be notified by e-mail.'); $redirectUrl = '/'; } $this->set('message', $message); $this->set('redirectUrl', $redirectUrl); $userAttributes = $this->AutoUserRegist->getUserAttribures(); $this->set('userAttributes', $userAttributes); if ($this->Session->read('AutoUserRegist')) { $this->request->data = $this->Session->read('AutoUserRegist'); $this->Session->delete('AutoUserRegist'); } else { $this->request->data = array(); } }
/** * UserAttribureデータ取得 * * @return array */ public function getUserAttribures() { if ($this->__userAttributes) { return $this->__userAttributes; } //モデルのロード $this->loadModels(['UserAttribute' => 'UserAttributes.UserAttribute']); //SiteSettingデータ取得 Current::write('User.role_key', SiteSettingUtil::read('AutoRegist.role_key')); //UserAttributeデータ取得 $this->__userAttributes = $this->UserAttribute->getUserAttriburesForAutoUserRegist(array('OR' => array('UserAttributeSetting.user_attribute_key' => array(UserAttribute::LOGIN_ID_FIELD, UserAttribute::PASSWORD_FIELD), array('UserAttributeSetting.required' => true, 'UserAttributeSetting.data_type_key' => array(DataType::DATA_TYPE_CHECKBOX, DataType::DATA_TYPE_RADIO, DataType::DATA_TYPE_SELECT)), array('UserAttributeSetting.required' => true, 'UserAttributeSetting.only_administrator_editable' => false), 'UserAttributeSetting.auto_regist_display' => true))); return $this->__userAttributes; }
/** * メール送信日時で送るかどうか * * @param date $sendTime メール送信日時 * @param int $useReminder リマインダーを使うか * @return bool */ public function isMailSendTime($sendTime, $useReminder) { if ($sendTime === null) { return true; } // SiteSettingからメール設定を取得する $useCron = SiteSettingUtil::read('Mail.use_cron'); $now = NetCommonsTime::getNowDatetime(); // クーロンが使えなくて未来日なら、未来日メールなので送らない if (empty($useCron) && strtotime($now) < strtotime($sendTime)) { return false; } //$useReminder = $this->settings[$model->alias]['reminder']['useReminder']; if (!$useReminder) { return true; } // リマインダーで日時が過ぎてたら、メール送らない if (strtotime($now) > strtotime($sendTime)) { return false; } return true; }
/** * 埋め込みタグ変換:定型文の埋め込みタグを変換して、メール生文にする * * @return array タグ */ public function assignTagReplace() { // 承認系メールのタグは先に置換 if (array_key_exists('X-PLUGIN_MAIL_SUBJECT', $this->assignTags) && array_key_exists('X-PLUGIN_MAIL_BODY', $this->assignTags)) { $this->fixedPhraseBody = str_replace('{X-PLUGIN_MAIL_BODY}', $this->assignTags['X-PLUGIN_MAIL_BODY'], $this->fixedPhraseBody); $this->fixedPhraseSubject = str_replace('{X-PLUGIN_MAIL_SUBJECT}', $this->assignTags['X-PLUGIN_MAIL_SUBJECT'], $this->fixedPhraseSubject); unset($this->assignTags['X-PLUGIN_MAIL_SUBJECT'], $this->assignTags['X-PLUGIN_MAIL_BODY']); } // html or text $messageType = SiteSettingUtil::read('Mail.messageType'); // URL if (array_key_exists('X-URL', $this->assignTags)) { if ($messageType == 'text') { $this->fixedPhraseBody = str_replace('{X-URL}', $this->assignTags['X-URL'], $this->fixedPhraseBody); } else { $this->fixedPhraseBody = str_replace('{X-URL}', '<a href=\'' . $this->assignTags['X-URL'] . '\'>' . $this->assignTags['X-URL'] . '</a>', $this->fixedPhraseBody); } unset($this->assignTags['X-URL']); } // 本文 foreach ($this->embedTagsWysiwyg as $xbodyTag) { if (array_key_exists($xbodyTag, $this->assignTags)) { $body = $this->assignTags[$xbodyTag]; if ($messageType == 'text') { // htmlspecialchar 等をデコード と strap_tags $body = $this->__decodeAndStripTags($body); } $this->fixedPhraseBody = str_replace('{' . $xbodyTag . '}', $body, $this->fixedPhraseBody); unset($this->assignTags[$xbodyTag]); } } foreach ($this->assignTags as $key => $value) { $this->fixedPhraseBody = str_replace('{' . $key . '}', $value, $this->fixedPhraseBody); $this->fixedPhraseSubject = str_replace('{' . $key . '}', $value, $this->fixedPhraseSubject); } // 改行処理 と テキストのブロックを決められた幅で折り返す $this->fixedPhraseBody = $this->__textBrAndWrap($this->fixedPhraseBody); }
/** * サイトのデフォルトタイムゾーン(未ログインのゲスト用)を返す * * @return string timezone */ public function getSiteTimezone() { return SiteSettingUtil::read('App.default_timezone'); }
/** * NetCommons3のセキュリティ設定で許可されている拡張子のリストを返す * * @param Model $model Model * @return array */ public function getAllowExtension(Model $model) { $uploadAllowExtension = explode(',', SiteSettingUtil::read('Upload.allow_extension')); $uploadAllowExtension = array_map('trim', $uploadAllowExtension); return $uploadAllowExtension; }
/** * メール設定がされているかどうか * * @return bool */ public function isUserMailSend() { $from = SiteSettingUtil::read('Mail.from'); // Fromが空ならメール未設定のため、メール送らない if (empty($from)) { return false; } // cakeコマンドに実行権限なければ、メール送らない if (!MailSend::isExecutableCake()) { return false; } return true; }
/** * From セット * * @param int $languageId 言語ID * @return void */ public function setFrom($languageId) { $from = SiteSettingUtil::read('Mail.from'); $fromName = SiteSettingUtil::read('Mail.from_name', null, $languageId); $this->__setFrom($from, $fromName); }
/** * パスワード再発行 * * @return void **/ public function confirm() { if ($this->request->is('post')) { if ($this->ForgotPass->validateAuthorizationKey($this->request->data)) { $forgotPass = $this->Session->read('ForgotPass'); $this->mail->mailAssignTag->setFixedPhraseSubject(SiteSettingUtil::read('ForgotPass.request_mail_subject')); $this->mail->mailAssignTag->setFixedPhraseBody(SiteSettingUtil::read('ForgotPass.request_mail_body')); $this->mail->mailAssignTag->assignTags(array('X-HANDLENAME' => $forgotPass['handlename'], 'X-USERNAME' => $forgotPass['username'])); $this->mail->mailAssignTag->initPlugin(Current::read('Language.id')); $this->mail->initPlugin(Current::read('Language.id')); $this->mail->to(Hash::get($forgotPass, 'email')); $this->mail->setFrom(Current::read('Language.id')); if (!$this->mail->sendMailDirect()) { return $this->NetCommons->handleValidationError(array('SendMail Error')); } $this->NetCommons->setFlashNotification(__d('auth', 'We have sent your login id to your registered e-mail address.'), array('class' => 'success')); return $this->redirect('/auth/forgot_pass/update'); } $this->NetCommons->handleValidationError($this->ForgotPass->validationErrors); } }
/** * メールを送るかどうか - 共通処理 * * @param Model $model モデル * @param string $typeKey メールの種類 * @param string $settingPluginKey 設定を取得するプラグインキー * @return bool */ public function isMailSendCommon(Model $model, $typeKey = MailSettingFixedPhrase::DEFAULT_TYPE, $settingPluginKey = null) { if ($settingPluginKey === null) { $settingPluginKey = Current::read('Plugin.key'); } $from = SiteSettingUtil::read('Mail.from'); // Fromが空ならメール未設定のため、メール送らない if (empty($from)) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } // cakeコマンドに実行権限なければ、メール送らない if (!MailSend::isExecutableCake()) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } /** @see MailSetting::getMailSettingPlugin() */ $mailSettingPlugin = $model->MailSetting->getMailSettingPlugin(null, $typeKey, $settingPluginKey); $isMailSend = Hash::get($mailSettingPlugin, 'MailSetting.is_mail_send'); $isMailSendApproval = Hash::get($mailSettingPlugin, 'MailSetting.is_mail_send_approval'); // プラグイン設定でメール通知 and 承認メール通知をどちらも使わないなら、メール送らない if (!$isMailSend && !$isMailSendApproval) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } $status = Hash::get($model->data, $model->alias . '.status'); // 一時保存はメール送らない if ($status == WorkflowComponent::STATUS_IN_DRAFT) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } $block = Current::read('Block'); // ブロック非公開、期間外はメール送らない if (!$model->MailQueue->isSendBlockType($block, '')) { CakeLog::debug('[' . __METHOD__ . '] ' . __FILE__ . ' (line ' . __LINE__ . ')'); return false; } return true; }
/** * 登録メール通知 * * @return void */ public function notify() { $user = $this->Session->read('UserAdd'); $this->set('user', $user['User']); if ($this->request->is('post')) { unset($this->request->data['send']); //入力チェック $this->UserMail->set($this->request->data); if ($this->UserMail->validates()) { //メール送信処理 $this->mail->mailAssignTag->setFixedPhraseSubject($this->request->data['UserMail']['title']); $this->mail->mailAssignTag->setFixedPhraseBody($this->request->data['UserMail']['body']); $this->mail->mailAssignTag->initPlugin(Current::read('Language.id')); $this->mail->setReplyTo($this->request->data['UserMail']['reply_to']); $this->mail->initPlugin(Current::read('Language.id')); $this->mail->to($this->viewVars['user']['email']); try { $this->mail->setFrom(Current::read('Language.id')); if (!$this->mail->sendMailDirect()) { return $this->NetCommons->handleValidationError(array('SendMail Error')); } } catch (Exception $ex) { CakeLog::error($ex); return $this->NetCommons->handleValidationError(array('SendMail Error'), __d('mails', 'There is errors in the mail settings. It was not able to send mail.')); } //リダイレクト $this->Session->delete('UserAdd'); $this->NetCommons->setFlashNotification(__d('user_manager', 'Successfully mail send.'), array('class' => 'success')); return $this->redirect('/user_manager/user_manager/index/'); } $this->NetCommons->handleValidationError($this->UserMail->validationErrors); } else { //ユーザデータ取得 $this->mailSetting = $this->UserMail->MailSetting->getMailSettingPlugin(null, 'save_notify'); $this->mail->mailAssignTag->setFixedPhraseSubject($this->mailSetting['MailSettingFixedPhrase']['mail_fixed_phrase_subject']); $this->mail->mailAssignTag->setFixedPhraseBody($this->mailSetting['MailSettingFixedPhrase']['mail_fixed_phrase_body']); $this->mail->mailAssignTag->initPlugin(Current::read('Language.id')); $password = Hash::get($this->viewVars['user'], 'password', ''); $passwordUrl = NetCommonsUrl::url('/auth/forgot_pass/request', true) . '?email=' . $this->viewVars['user']['email']; $this->mail->mailAssignTag->assignTags(array('X-HANDLENAME' => $this->viewVars['user']['handlename'], 'X-USERNAME' => $this->viewVars['user']['username'], 'X-PASSWORD' => $password, 'X-PASSWORD_URL' => $passwordUrl, 'X-EMAIL' => $this->viewVars['user']['email'], 'X-URL' => NetCommonsUrl::url('/', true))); $this->mail->mailAssignTag->assignTagReplace(); $this->request->data['UserMail']['title'] = $this->mail->mailAssignTag->fixedPhraseSubject; $this->request->data['UserMail']['body'] = $this->mail->mailAssignTag->fixedPhraseBody; $this->request->data['UserMail']['user_id'] = $this->viewVars['user']['id']; $this->request->data['UserMail']['reply_to'] = SiteSettingUtil::read('Mail.from'); } }