private function validateCode($input, $botUserId)
{
if (!$input || !$botUserId) {
return false;
}
$code = SecurityCode::whereBotUserId($botUserId)->where('created_at', '>', DB::raw('now() - INTERVAL 10 MINUTE'))->where('attempts', '<', 5)->first();
if (!$code) {
return false;
}
if (!hash_equals($code->code, $input)) {
$code->attempts += 1;
$code->save();
return false;
}
$user = User::find($code->user_id);
$user->bot_user_id = $code->bot_user_id;
$user->save();
return true;
}