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

53 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)
{
$pwdRst = new PasswordReset();
$pwdRst->email = $email;
$pwdRst->init_time = time();
$pwdRst->expire_time = time() + 3600 * 24; // @todo
$pwdRst->token = bin2hex(random_bytes(32));
if (!$pwdRst->save()) {
return false;
}
$subject = Config::get('appName') . ($english ? ' Password reset' : '重置密码');
$resetUrl = Config::get('baseUrl') . "/password/token/" . $pwdRst->token;
try {
$sent = Mail::send($email, $subject, 'password/reset.tpl', [
"resetUrl" => $resetUrl,
"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)
{
}
}