You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Services/Password.php

56 lines
1.3 KiB
PHP

<?php
namespace App\Services;
use App\Models\PasswordReset;
/***
* Class Password
* @package App\Services
*/
class Password
{
/**
* @param $email string
* @return bool
*/
public static function sendResetEmail($email, $english = false)
{
$now = time();
$expiresAt = $now + 3600 * 24;
$pwdRst = new PasswordReset();
$pwdRst->email = $email;
$pwdRst->init_time = $now;
$pwdRst->expire_time = $expiresAt;
$pwdRst->token = bin2hex(random_bytes(32));
if (!$pwdRst->save()) {
return false;
}
$subject = 'Password Reset';
$resetUrl = Config::get('baseUrl') . "/password/token/" . $pwdRst->token;
try {
$sent = Mail::send($email, $subject, 'password/reset.tpl', [
"resetUrl" => $resetUrl,
"expire" => date('Y-m-d H:i:s', $expiresAt),
"language" => $english ? 'true' : 'false'
], [
//BASE_PATH.'/public/assets/email/styles.css'
], '重置密码');
} catch (\Throwable $exception) {
$sent = false;
}
if (!$sent) {
$pwdRst->delete();
return false;
}
return true;
}
public static function resetBy($token, $password)
{
}
}