cakephp 2.6を使用しています。アクティベーションリンクをユーザーがクリックすると、その後、私のデータベースのステータスフィールドは、私の電子メールが正しくなるだろうが、私は方法を知っているドン1.登録後のメールのアカウントアクティベーションリンクcakephp
で更新する場合、私は、登録が成功し、 後にメールでアカウントのアクティベーションリンクを送信する必要がありますlastinsertidを電子メールの一意の識別子として取得し、クリック後にアカウントを更新することにより、電子メール内のリンクを送信する。
私はこれを手伝ってください。以下
function add() {
$this->layout = "layout_login";
$this->pageTitle = "Add Admin";
$this->set("pageTitle", "Add Admin");
if (!empty($this->request->data)) {
$this->User->set($this->data['User']);
$isValidated = $this->User->validates();
if ($isValidated) {
// Generating UUID
$this->data['User']['activation_key'] = $activation_key = String::uuid();
$this->User->save($this->data, array('validate' => false));
$this->Session->setFlash(__('Please check your email for account verification.'));
$subject = "Account Activation link By Kaya Dispatch";
$to = trim($this->request->data['User']['email']);
$this->Email->sendAs = 'html';
$this->Email->from = '[email protected]';
$this->Email->to = $to;
$this->Email->subject = $subject;
$activationUrl = Router::url(['controller' => 'users', 'action' => 'activate/' . $activation_key ]);
$message = "Dear <span style='color:#666666'>" . $name . "</span>,<br/><br/>";
$message .= "Your account has been created successfully by Administrator.<br/>";
$message .= "Please find the below details of your account: <br/><br/>";
$message .= "<b>Activate your account by clicking on the below url:</b> <br/>";
$message .= "<a href='$activationUrl'>$activationUrl</a><br/><br/>";
$message .= "<br/>Thanks, <br/>Support Team";
$this->Email->send($message);
}
}
}
アカウントのアクティベーションコードは、まあ、これは論理的なものである
function activate($activation_key) {
$userData = $this->User->find('first', array(
'conditions' => array(
'User.activation_key' => $activation_key,
'User.status' => 0
)
));
if(!empty($userData)){
if ($userData['User']['status'] == 0)
{
$activeStatus = 1;
}
$status = $this->User->updateAll(array('User.status' => $activeStatus), array('User.id' => $id));
if ($status)
{ $this->Session->setFlash(__('Status updated successfully'));
} else
{ $this->Session->setFlash(__('Something went wrong, please try again.'));
}
$this->redirect(array('controller' => 'Users', 'action' => 'index'));
}
}
テーブルに列activation_keyを追加しましたが、テーブル内のactivation_key列にデータが挿入されていませんでした。このリンクをクリックすると、ステータス列はテーブル –
で更新されません。 。私の質問で.. –
私はあなたのために私の答えを更新しました! '' User.status '=>を使って既にユーザデータを見つけているので、 '' if($ userData [' User '' ['status'] == 0) 'をアクティブにチェックインする必要はありません。 0 '状態になる。 – hmd