開発メモ

開発用のメモです。

パスワードリマインダー

<?php
class ForgotCustomize extends SC_Plugin_Base {


function after(&$objPage) {
    $this -> tpl_mainpage = 'forgot/index.tpl';
    switch ($objPage->getMode()) {
        case 'mail_check' :
            echo 1;
            if (SC_Utils_Ex::isBlank($objPage -> errmsg)) {
                $this -> errmsg = $this -> lfCheckForgotSecret($objPage -> arrForm, $objPage);
                if (SC_Utils_Ex::isBlank($this -> errmsg)) {
                    $objPage -> tpl_mainpage = 'forgot/complete.tpl';
                    $objPage -> tpl_onload .= 'opener.location.reload(true);';
                    $objPage ->setTemplate($objPage -> tpl_mainpage);
                }
            }
            break;
        default :
            break;
    }
}

public function lfCheckForgotSecret(&$arrForm, &$objPage) {
    $errmsg = '';
    
    $objQuery =& SC_Query_Ex::getSingletonInstance();
    
    $where = '(email = ? OR email_mobile = ?) AND name01 = ? AND name02 = ? AND del_flg = 0';
    $arrVal = array($arrForm['email'], $arrForm['email'], $arrForm['name01'], $arrForm['name02']);
    $result = $objQuery->select('customer_id, reminder, status', 'dtb_customer', $where, $arrVal);
        
    $new_password = GC_Utils_Ex::gfMakePassword(8);
    if (FORGOT_MAIL == 1) {
        // メールで変更通知をする
        $objDb = new SC_Helper_DB_Ex();
        $CONF = $objDb->sfGetBasisData();
        $this->lfSendMail($CONF, $arrForm['email'], $arrForm['name01'], $new_password, $objPage);
    }
    $sqlval = array();
    $sqlval['password'] = $new_password;
    SC_Helper_Customer_Ex::sfEditCustomerData($sqlval, $result[0]['customer_id']);
    $arrForm['new_password'] = $new_password;
    return $errmsg;
}
        
public function lfSendMail(&$CONF, $email, $customer_name, $new_password, &$objPage) {
    // パスワード変更お知らせメール送信
    $objMailText = new SC_SiteView_Ex(false);
    $objMailText->setPage($objPage);
    $objMailText->assign('customer_name', $customer_name);
    $objMailText->assign('new_password', $new_password);
    $toCustomerMail = $objMailText->fetch('mail_templates/forgot_mail.tpl');
    $objHelperMail = new SC_Helper_Mail_Ex();
    $objHelperMail->setPage($this);
    // メール送信オブジェクトによる送信処理
    $objMail = new SC_SendMail_Ex();
    $objMail->setItem(
        '' //宛先
        , $objHelperMail->sfMakeSubject('パスワードを変更いたしました。')
        , $toCustomerMail //本文
        , $CONF['email03'] //配送元アドレス
        , $CONF['shop_name'] // 配送元名
        , $CONF['email03'] // reply to
        , $CONF['email04'] //return_path
        , $CONF['email04'] // errors_to
    );
    $objMail->setTo($email, $customer_name . '');
    $objMail->sendMail();
    return;
}

}
Twitter: @asahina_alice