Add helper function generate_random_token
This commit is contained in:
parent
459a232c26
commit
e2575f8a9a
@ -112,11 +112,7 @@ class UserController extends Controller
|
||||
return json(trans('user.verification.verified'), 1);
|
||||
}
|
||||
|
||||
$key = config('app.key');
|
||||
$key = starts_with($key, 'base64:') ? base64_decode(substr($key, 7)) : $key;
|
||||
|
||||
$token = hash_hmac('sha256', str_random(40), $key);
|
||||
|
||||
$token = generate_random_token();
|
||||
$this->user->verification_token = $token;
|
||||
$this->user->save();
|
||||
|
||||
|
@ -518,3 +518,16 @@ if (! function_exists('can_moderate_texture')) {
|
||||
return ($texture->uploader == $user->uid || $user->isAdmin());
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('generate_random_token')) {
|
||||
|
||||
function generate_random_token($key = null) {
|
||||
|
||||
if (is_null($key)) {
|
||||
$key = config('app.key');
|
||||
$key = starts_with($key, 'base64:') ? base64_decode(substr($key, 7)) : $key;
|
||||
}
|
||||
|
||||
return hash_hmac('sha256', str_random(40), $key);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ $factory->defineAs(User::class, 'unverified', function (Faker\Generator $faker)
|
||||
'last_sign_at' => $faker->dateTime,
|
||||
'register_at' => $faker->dateTime,
|
||||
'verified' => 0,
|
||||
'verification_token' => hash_hmac('sha256', str_random(40), 'key')
|
||||
'verification_token' => generate_random_token()
|
||||
];
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user