private function validateEmail($email, $botUserId)
{
if (!$email || !$botUserId) {
return false;
}
// delete any expired codes
SecurityCode::whereBotUserId($botUserId)->where('created_at', '<', DB::raw('now() - INTERVAL 10 MINUTE'))->delete();
if (SecurityCode::whereBotUserId($botUserId)->first()) {
return false;
}
$user = User::whereEmail($email)->whereNull('bot_user_id')->first();
if (!$user) {
return false;
}
$code = new SecurityCode();
$code->user_id = $user->id;
$code->account_id = $user->account_id;
$code->code = mt_rand(100000, 999999);
$code->bot_user_id = $botUserId;
$code->save();
$this->userMailer->sendSecurityCode($user, $code->code);
return $code->code;
}