示例#1
0
 private function genActivation($email, $type, $return)
 {
     $details_query = $this->mySQL_r->prepare("SELECT CONCAT(`f_name`, ' ',`s_name`), `username` FROM `core_users` WHERE `email`=?");
     if ($details_query === false) {
         return new ActionResult($this, $return['f'], 0, 'Failed to send activation code.<br />Error: <code>Couldn\'t fetch details</code>', B_T_FAIL);
     }
     $details_query->bind_param('s', $email);
     $details_query->execute();
     $details_query->bind_result($name, $username);
     $details_query->store_result();
     if ($details_query->num_rows != 1) {
         return new ActionResult($this, $return['f'], 0, 'No user found to activate', B_T_FAIL);
     }
     $details_query->fetch();
     $this->mySQL_w->autocommit(false);
     $code_query = $this->mySQL_w->prepare("UPDATE `core_users` SET `act_c`=?, `act_t`=FROM_UNIXTIME(?), `act_b`=0 WHERE `email`=?");
     if ($code_query === false) {
         return new ActionResult($this, $return['f'], 0, 'Failed to send activation code.<br />Error: <code>Couldn\'t save activation details</code>', B_T_FAIL);
     }
     $code = $this->parent->parent->user->ranHash();
     $time = time();
     $code_query->bind_param('sis', $code, $time, $email);
     $code_query->execute();
     $code_query->store_result();
     if ($code_query->affected_rows != 1) {
         return new ActionResult($this, $return['f'], 0, 'Failed to generate activation code.', B_T_FAIL);
     }
     $mail = new Emailer();
     if ($type == 'add') {
         $mail->Subject = 'Account Creation';
         $mail->msgHTML(UserEmail::accountCreation($name, $username, $email, $code)['html']);
         $mail->AltBody = UserEmail::accountCreation($name, $username, $email, $code)['text'];
     } elseif ($type == 'resend') {
         $mail->Subject = 'Resend Activation Email';
         $mail->msgHTML(UserEmail::resendActivation($name, $username, $email, $code)['html']);
         $mail->AltBody = UserEmail::resendActivation($name, $username, $email, $code)['text'];
     } elseif ($type == 'recover') {
         $mail->Subject = 'Recover Account';
         $mail->msgHTML(UserEmail::recoverAccount($name, $username, $email, $code)['html']);
         $mail->AltBody = UserEmail::recoverAccount($name, $username, $email, $code)['text'];
     } elseif ($type == 'email') {
         $mail->Subject = 'Change Email';
         $mail->msgHTML(UserEmail::changeEmail($name, $username, $email, $code)['html']);
         $mail->AltBody = UserEmail::changeEmail($name, $username, $email, $code)['text'];
     }
     //$mail->Subject = 'Account Activation';
     $mail->addAddress($email, $name);
     if ($mail->send()) {
         $this->mySQL_w->commit();
         $this->mySQL_w->autocommit(true);
         return new ActionResult($this, $return['s'], 1, 'Generated activation code and sent email!', B_T_SUCCESS);
     } else {
         $this->mySQL_w->rollback();
         $this->mySQL_w->autocommit(true);
         return new ActionResult($this, $return['f'], 0, 'Failed to send activation code.', B_T_FAIL);
     }
 }