public function sendVerificationCode() { $user = Auth::user(); $verification['code'] = strtoupper(str_random(5)); $verification['user_id'] = $user->id; //expire in 10 minutes $verification['expiration'] = date('Y-m-d H:i:s', time() + 600); $vObj = VerificationCode::create($verification); if ($vObj) { $phone = str_replace(['(', ')'], '', $user->userable->phone); } $smsService = new NexmoSmsService(); $sent = $smsService->send($phone, 'mastori', 'Ο κωδικός επαλήθευσης είναι: ' . $verification['code']); if ($sent) { return response()->json(['status' => 'ok'], 200); } else { return response()->json(['error' => 'Sms error'], 500); } }
public function sendConfirmation() { $data = Request::only(['email']); $email = $data['email']; $token = str_random(30); $domain = substr(strrchr($email, "@"), 1); if (in_array($domain, explode(',', env('ACCEPTABLE_EMAIL_DOMAINS')))) { try { // Check if student exists already User::where('email', $email)->firstOrFail(); } catch (ModelNotFoundException $e) { // Send email verification if they are Mail::send('emails.verification_code', ['email' => $email, 'confirmation_code' => $token], function ($m) use($email) { $m->from('admin@' . env('USER_DOMAIN'), env('SITE_TITLE')); $m->to($email)->subject('Verify Your Email For ' . env('SITE_TITLE')); }); VerificationCode::create(['email' => $email, 'confirmation_code' => $token]); return View::make('emails.thank_you'); } } else { return Redirect::back()->withErrors(['That email is not on our approved list of student emails']); } }