Hello everyone, I tried to reply in my original post, but I cant.
I try to implement a way to send a email after somebody use the one time login plugin, I modified the plugin to keep the token, so I can use more than 1 time, and also remove the option to remove it after 15 minutes, and works fine, but now I try to use the email plugin to send a email when its used, Same like my previous topic I using the email plugin and in login plugin is working fine, its was a grammatical mistake, but now when I try to use in the same way in the one time login plugin, Send me this error:
This is the code I used in the one-time-login.php:
private function authenticateOtl()
{
$username = $this->grav['uri']->param('user');
$firstName = $this->grav['uri']->param('firstname');
$lastName = $this->grav['uri']->param('lastname');
$otl_nonce = $this->grav['uri']->param('otl_nonce');
$rolUsername = $this->grav['uri']->param('username');
$sitename = $this->grav['uri']->param('sitename');
$this->redirect = "/";
// Load user object.
$user = !empty($username) ? User::load($username) : null;
if (empty($user) || !$user->otl_nonce) {
$this->grav['log']->info("Invalid OTL URL.");
$this->grav['messages']->add('Invalid OTL URL.', 'error');
}
if ($user) {
$otl_nonce_expire = $user->otl_nonce_expire;
if (($user->otl_nonce == $otl_nonce) /* && (time() < $otl_nonce_expire) */) {
// Remove OTL user entries.
/* unset($user->otl_nonce);
unset($user->otl_nonce_expire);
unset($user->otl_admin_logon); */
$user->save();
$user->authenticated = true;
$user->authorized = $user->authorize('admin.login');
// Authenticate user to website.
$this->grav['session']->user = $user;
unset($this->grav['user']);
$this->grav['user'] = $user;
date_default_timezone_set("America/Costa_Rica");
$time = date("l / d-m-Y(H:i:s)");
$to = '[email protected]';
$from = '[email protected]';
$subject = $time . " | Inicio de sesión";
$content = '
<html>
<head>
<style>
table {
width:100%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
text-align: left;
}
table#t01 tr:nth-child(even) {
background-color: #eee;
}
table#t01 tr:nth-child(odd) {
background-color: #fff;
}
table#t01 th {
background-color: black;
color: white;
}
</style>
<title>Inicio de sesión </title>
</head>
<body>
<h1> Inicio de sesión </h1>
<table>
<tr>
<th> Fecha de inicio de sesión </th>
<th> Correo o nombre de usuario </th>
</tr>
<tr>
<td>'.$time.'</td>
<td>'.$rolUsername.'</td>
<td>'.$sitename.'</td>
</tr>
</table>
</body>
</html>';
/* $message = $this->grav['Email']->message($subject, $content, 'text/html')
->setFrom($from)
->setTo($to);
$sent = $this->grav['Email']->send($message); */
$this->redirect = "/10/=".$firstName ."&lastname=". $lastName;
} else {
$this->grav['messages']->add('Invalid OTL URL.', 'error');
$this->grav['log']->info("Invalid OTL URL.");
}
}
// Redirect.
$this->grav->redirect($this->redirect);
}
}