Browse Source

some bug fix and send email when user register or forget password

mahdi
mahdihty 4 years ago
parent
commit
97106ee675
  1. 5
      app/Enums/tables.php
  2. 35
      app/Http/Controllers/AuthController.php
  3. 12
      app/Listeners/NotifHandler.php
  4. 2
      app/Notifications/MailNotification.php
  5. 9
      resources/lang/fa/notification.php

5
app/Enums/tables.php

@ -63,6 +63,11 @@ return [
'name' => 'Works', 'name' => 'Works',
'singular_name' => 'Work', 'singular_name' => 'Work',
], ],
'users' => [
'id' => 100,
'name' => 'Users',
'singular_name' => 'Users',
],
//Relation Table's //Relation Table's
'business_user' => [ 'business_user' => [

35
app/Http/Controllers/AuthController.php

@ -5,6 +5,8 @@ namespace App\Http\Controllers;
use App\Models\User; use App\Models\User;
use App\Models\Business; use App\Models\Business;
use App\Models\Fingerprint; use App\Models\Fingerprint;
use App\Notifications\MailNotification;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
@ -15,6 +17,7 @@ use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Laravel\Socialite\Facades\Socialite; use Laravel\Socialite\Facades\Socialite;
use Illuminate\Session\TokenMismatchException; use Illuminate\Session\TokenMismatchException;
use phpDocumentor\Reflection\Type;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
class AuthController extends Controller class AuthController extends Controller
@ -94,7 +97,7 @@ class AuthController extends Controller
$request->merge(['password' => Hash::make($request->password)]); $request->merge(['password' => Hash::make($request->password)]);
$code_data = ['verification_code' => $this->sendVerificationCode()];
$code_data = ['verification_code' => $this->sendVerificationCode(\request('email'), 'register')];
$method_data = ['method' => 'registerMain']; $method_data = ['method' => 'registerMain'];
Cache::put($request->email, $request->all() + $code_data + $method_data, 3600); // remain one hour Cache::put($request->email, $request->all() + $code_data + $method_data, 3600); // remain one hour
@ -114,11 +117,16 @@ class AuthController extends Controller
return $this->createFingerPrint(); return $this->createFingerPrint();
} }
public function sendVerificationCode($contact_way = null)
public function sendVerificationCode($contact_way, $type)
{ {
$verification_code = 1234; // rand(10001, 99999)
$verification_code = rand(10001, 99999);
//send code for user with contact way
Notification::route('mail', $contact_way)->notify( new MailNotification([
'greeting' => __('notification.auth.verification.greeting'),
'subject' => __('notification.auth.verification.subject'),
'body' => __('notification.auth.verification.body', ['code' => $verification_code]),
'link' => __('notification.auth.verification.link', ['email' => $contact_way, 'type' => $type]),
]));
return $verification_code; return $verification_code;
} }
@ -136,11 +144,18 @@ class AuthController extends Controller
'verification_code' => 'required|string|min:4|max:4|in:'.$user_info['verification_code'] 'verification_code' => 'required|string|min:4|max:4|in:'.$user_info['verification_code']
]); ]);
Cache::forget($request->email);
// Cache::forget($request->email);
if (isset($user_info['method'])) {
Cache::forget($request->email);
return call_user_func('self::'.$user_info['method'], $user_info);
}
return isset($user_info['method']) ?
call_user_func('self::'.$user_info['method'], $user_info) :
\response()->json(['message' => 'Code verified successfully.'], Response::HTTP_OK,);
return \response()->json(['message' => 'Code verified successfully.'], Response::HTTP_OK,);
// return isset($user_info['method']) ?
// call_user_func('self::'.$user_info['method'], $user_info) :
// \response()->json(['message' => 'Code verified successfully.'], Response::HTTP_OK,);
} }
public function forgetPassword(Request $request) public function forgetPassword(Request $request)
@ -149,7 +164,7 @@ class AuthController extends Controller
'email' => 'required|email|exists:users,email' 'email' => 'required|email|exists:users,email'
]); ]);
$code_data = ['verification_code' => $this->sendVerificationCode()];
$code_data = ['verification_code' => $this->sendVerificationCode(\request('email', 'forget'))];
Cache::put($request->email, $request->all() + $code_data, 3600); // remain one hour Cache::put($request->email, $request->all() + $code_data, 3600); // remain one hour
@ -178,6 +193,8 @@ class AuthController extends Controller
Auth::setUser($user); Auth::setUser($user);
Cache::forget($request->email);
return $this->createFingerPrint(); return $this->createFingerPrint();
} }

12
app/Listeners/NotifHandler.php

@ -33,10 +33,12 @@ class NotifHandler
if (class_exists($event_class)) { if (class_exists($event_class)) {
$event_class::dispatch($message); $event_class::dispatch($message);
} }
Notification::send(auth()->user(), new SocketNotification(
[
'message' => enum('tables.'.$message->data->table_name.'.singular_name').enum('cruds.inverse.'.$message->data->crud_id.'.name'),
'payload'=>$business_info
]));
if (auth()->user()) {
Notification::send(auth()->user(), new SocketNotification(
[
'message' => enum('tables.'.$message->data->table_name.'.singular_name').enum('cruds.inverse.'.$message->data->crud_id.'.name'),
'payload'=> request('_business_info') ?? null
]));
}
} }
} }

2
app/Notifications/MailNotification.php

@ -73,6 +73,6 @@ class MailNotification extends Notification implements ShouldQueue
->greeting($this->message['greeting']) ->greeting($this->message['greeting'])
->line($this->message['body']) ->line($this->message['body'])
->subject($this->message['subject']) ->subject($this->message['subject'])
->action('Notification Action', url('/'));
->action('بیشتر', $this->message['link'] ?? url('/'));
} }
} }

9
resources/lang/fa/notification.php

@ -85,6 +85,15 @@ return [
'suspended' => 'حساب مسدود شد.', 'suspended' => 'حساب مسدود شد.',
], ],
'auth' => [
'verification' => [
'greeting' => 'سلام کاربر گرامی!',
'subject' => 'کد تایید',
'body' => 'کد تایید شما :code',
'link' => 'http://localhost:3000/verification?email=:email&type=:type'
]
],
'sms' => [ 'sms' => [
'templates' => [ 'templates' => [
'template_name' => [ 'template_name' => [

Loading…
Cancel
Save