No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoginController.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Helpers\Helper;
  4. use App\Http\Controllers\Controller;
  5. use App\Model\Auditrail\HistoryLogs;
  6. use App\Providers\RouteServiceProvider;
  7. use App\User;
  8. use Illuminate\Foundation\Auth\AuthenticatesUsers;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\DB;
  11. use Illuminate\Support\Facades\Hash;
  12. use Auth;
  13. use Carbon\Carbon;
  14. use Illuminate\Support\Facades\Validator;
  15. class LoginController extends Controller
  16. {
  17. /*
  18. |--------------------------------------------------------------------------
  19. | Login Controller
  20. |--------------------------------------------------------------------------
  21. |
  22. | This controller handles authenticating users for the application and
  23. | redirecting them to your home screen. The controller uses a trait
  24. | to conveniently provide its functionality to your applications.
  25. |
  26. */
  27. use AuthenticatesUsers;
  28. /**
  29. * Where to redirect users after login.
  30. *
  31. * @var string
  32. */
  33. protected $redirectTo = '/dashboard';
  34. private $title = 'Login Page | Admin Jasa Raharja';
  35. /**
  36. * Create a new controller instance.
  37. *
  38. * @return void
  39. */
  40. public function __construct()
  41. {
  42. DB::getQueryLog();
  43. $this->middleware('guest')->except('logout');
  44. }
  45. public function index()
  46. {
  47. $data = [
  48. //bawaan
  49. 'title' => $this->title,
  50. ];
  51. return view('auth.login', $data);
  52. }
  53. public function action_login(Request $request)
  54. {
  55. $rule = [
  56. 'email' => 'required|exists:users,email',
  57. 'password' => 'required'
  58. ];
  59. $message = [
  60. 'required' => 'The :attribute is required',
  61. 'exists' => ':attribute not found',
  62. ];
  63. $validator = Validator::make($request->input(), $rule, $message);
  64. if ($validator->passes()) {
  65. $auth = Auth::attempt($request->only('email', 'password'));
  66. if ($auth) {
  67. // $request->session()->put('credential', Auth::user());
  68. // return redirect(route('admin.dashboard'));
  69. if (empty(Auth::user()->rumah_sakit)) {
  70. // $data_history_logs = [
  71. // 'type_id' => '1',
  72. // 'user_id' => Auth::user()->id,
  73. // 'log' => 'Login(SIDONI LAB)',
  74. // 'waktu' => Carbon::now()->format('Y-m-d H:i:s'),
  75. // 'ip_address' => Helper::get_ip_user(),
  76. // 'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
  77. // ];
  78. // $insert_data_item_kantongs = HistoryLogs::insert($data_history_logs);
  79. $request->session()->put('credential', Auth::user());
  80. return redirect(route('admin.dashboard'));
  81. } else {
  82. Auth::logout();
  83. session()->flush();
  84. session()->invalidate();
  85. // return back()->with('error', 'Akun yang anda gunakan salah, Silahkan menggunakan Akun Rumah Sakit')->withInput();
  86. return redirect(route('auth.index'))->with('message', Helper::failed_alert('Akun yang anda gunakan salah, Silahkan menggunakan Akun Admin'))->withInput();
  87. }
  88. } else {
  89. return redirect(route('auth.index'))->with('message', Helper::failed_alert('Password Salah'))->withInput();
  90. }
  91. } else {
  92. return redirect(route('auth.index'))->with('message', Helper::failed_alert('Email Belum Terdaftar'))->withInput();;
  93. }
  94. }
  95. }