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.

ForgotPasswordController.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Http\Controllers\v3\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. use Illuminate\Support\Facades\Log;
  8. use Hash;
  9. use Carbon\Carbon;
  10. use Validator;
  11. use App\LatestModel\Staff;
  12. class ForgotPasswordController extends Controller
  13. {
  14. /*
  15. |--------------------------------------------------------------------------
  16. | Password Reset Controller
  17. |--------------------------------------------------------------------------
  18. |
  19. | This controller is responsible for handling password reset emails and
  20. | includes a trait which assists in sending these notifications from
  21. | your application to your users. Feel free to explore this trait.
  22. |
  23. */
  24. use SendsPasswordResetEmails;
  25. /**
  26. * Create a new controller instance.
  27. *
  28. * @return void
  29. */
  30. public function checkEmail(Request $request){
  31. $this->validate($request, [
  32. 'email' => 'required|email',
  33. ]);
  34. $user = '';
  35. $roles_access = '';
  36. if($request->has('role_access')){
  37. if($request->role_access == 'contractor'){
  38. $roles_access = 'Contractor';
  39. }else if($request->role_access == 'customer-service'){
  40. $roles_access = 'Customer Service';
  41. }else if($request->role_access == 'marketing'){
  42. $roles_access = 'Marketing';
  43. }else if($request->role_access == 'dealer'){
  44. $roles_access = 'Dealer';
  45. }else if($request->role_access == 'sales'){
  46. $roles_access = 'Sales';
  47. }
  48. }
  49. if($request->has('password')){
  50. $validator = Validator::make($request->all(), [
  51. 'password' => 'min:8|confirmed',
  52. ]);
  53. $user = Staff::where('email', $request->email)->where('roles_access',$roles_access)->first();
  54. if (!empty($user)) {
  55. $encryptP = Hash::make($request->get('password'));
  56. $user->password = $encryptP;
  57. $user->save();
  58. $user->StaffDetail->password = $encryptP;
  59. $user->StaffDetail->save();
  60. return redirect('/v3')->with('success_msg', 'Success! update password');
  61. }else{
  62. return redirect()->back()->withInput()->with('error_msg','Staff id not found');
  63. }
  64. }else{
  65. $user = Staff::where('email', $request->email)->where('roles_access',$roles_access)->first();
  66. if (!empty($user)) {
  67. // return redirect()->back()->withInput()->with('success_msg', 'Success! update password');
  68. return redirect()->back()->withInput()->with('success_msg', 'Email found');
  69. }else{
  70. return redirect()->back()->withInput()->with('error_msg','Email / roles not found');
  71. }
  72. }
  73. }
  74. }