Example #1
0
 /**
  * re-issue password2
  * @return ViewModel
  */
 public function remindStoreAction()
 {
     $this->layout('layout/index');
     // get temporary id
     $id = (string) $this->params()->fromRoute('id');
     if (!$id) {
         $this->flashMessenger()->addMessage('Not allowed');
         //            $this->flashMessenger()->addMessage('許可されていません。');
         return $this->redirect()->toRoute('app', array('controller' => 'index'));
     }
     $tmp = new TemporaryIdTable();
     $row = $tmp->getFetchOne($id);
     if (!$row || !isset($row->create_user) || !$row->create_user) {
         $this->flashMessenger()->addMessage('Not allowed');
         //            $this->flashMessenger()->addMessage('許可されていません。');
         return $this->redirect()->toRoute('app', array('controller' => 'index'));
     }
     $success = false;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $token_id = $this->container()->get('token_id');
         $this->container()->clear('token_id');
         if ($token_id != $request->getPost('token_id')) {
             $this->flashMessenger()->addMessage('Not allowed');
             //                $this->flashMessenger()->addMessage('許可されていません。');
             return $this->redirect()->toRoute('app', array('controller' => 'index'));
         }
         $db = new UserEntity();
         $chk = true;
         $i = 0;
         while ($chk) {
             $new_pw = make_rand_str(8, 3);
             $chk = $db->db()->checkLoginPw($row->create_user, $new_pw);
             ++$i;
             if (!$chk || 10 < $i) {
                 // avoid infinite loop
                 break;
             }
         }
         if (!$chk) {
             $success = $db->changePw($row->create_user, $new_pw, 1);
         }
         if ($success) {
             $mail = new Message();
             $mail->setEncoding("UTF-8");
             $mail->addFrom(AUTO_MAIL_FROM)->addTo($row->email)->setSubject($this->translator()->translate("About initialize password"));
             //                        ->setSubject($this->translator()->translate("パスワード初期化について"));
             $body_tpl = file_get_contents(APP_DIR . '/tpl/remind-store-mail.txt');
             $body_tpl = trim(str_replace("\r\n", "\n", $body_tpl));
             $body_tpl = $this->translator()->translate($body_tpl);
             $body_tpl .= "\n\n" . "PW:" . $new_pw;
             $body_tpl .= "\n\n\n" . "URL:" . BASE_URL;
             $mail->setBody($body_tpl);
             $transport = new SmtpTransport();
             $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'plain', 'connection_config' => array('ssl' => 'tls', 'username' => AUTO_MAIL_FROM, 'password' => AUTO_MAIL_FROM_PASSWORD), 'port' => 587));
             $transport->setOptions($options);
         }
         if ($success) {
             $success = $transport->send($mail);
         } else {
             if (IS_TEST) {
                 $logger = new \Zend\Log\Logger();
                 $writer = new \Zend\Log\Writer\Stream(APP_DIR . '/log/debug.txt');
                 $logger->addWriter($writer);
                 $logger->log(\Zend\Log\Logger::DEBUG, print_r($mail, 1));
             }
         }
         $tmp->finishRecord($id);
         $message = $success ? 'Please confirm e-mail' : 'Failed';
         //            $message = $success ? 'メールを確認してください。' : '処理失敗';
         $this->flashMessenger()->addMessage($message);
         return $this->redirect()->toRoute('app', array('controller' => 'index'));
     }
     // create token_id
     $token_id = make_token_id();
     $this->container()->set('token_id', $token_id);
     $values = array('token_id' => $token_id, 'id' => $id);
     $view = new ViewModel($values);
     $view->setTemplate('/' . VIEW_DIR . '/index/remind-store.phtml');
     return $view;
 }
Example #2
0
 /**
  * restore
  * @return ViewModel
  */
 public function restoreAction()
 {
     $this->init();
     $success = false;
     $user_no = $this->auth()->get('user_no');
     // check auth by id
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id || $id == $user_no) {
         $success = false;
     } else {
         $success = 4 == $this->ctrlLv ? true : false;
     }
     $db = new UserEntity();
     // check belonging branch
     if ($success && !$this->auth()->get('admin')) {
         $row = $db->db()->getFetchOne($id);
         $success = $this->auth()->get('branch_no') == $row->branch_no;
     }
     if ($success) {
         $success = $db->db()->restoreRecord($id, $user_no);
     }
     $this->flashMessenger()->addMessage($success ? 'Restore' : 'Failed');
     //                ->addMessage($success ? '復帰しました。' : '処理失敗');
     $view = new ViewModel(array('message' => $success ? 'success' : 'failed'));
     $view->setTemplate('/common/message.phtml');
     $view->setTerminal(true);
     return $view;
 }