RegisterController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace App\Http\Controllers\AuthSupervisor;
  3. use Validator;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Foundation\Auth\RegistersUsers;
  7. use Illuminate\Support\Facades\Auth;
  8. use App\Mail\SignUp;
  9. use App\User;
  10. use App\Models\Department;
  11. use App\Models\University;
  12. use Hash;
  13. use Mail;
  14. class RegisterController extends Controller
  15. {
  16. /*
  17. |--------------------------------------------------------------------------
  18. | Register Controller
  19. |--------------------------------------------------------------------------
  20. |
  21. | This controller handles the registration of new users as well as their
  22. | validation and creation. By default this controller uses a trait to
  23. | provide this functionality without requiring any additional code.
  24. |
  25. */
  26. //use RegistersUsers;
  27. /**
  28. * Where to redirect users after login / registration.
  29. *
  30. * @var string
  31. */
  32. //protected $redirectTo = '/login-v2';
  33. /**
  34. * Create a new controller instance.
  35. *
  36. * @return void
  37. */
  38. public function __construct()
  39. {
  40. $this->middleware('teacher.guest');
  41. }
  42. protected function validator(array $data)
  43. {
  44. return Validator::make($data, [
  45. 'firstname' => ['required', 'string', 'max:255'],
  46. 'lastname' => ['required', 'string', 'max:255'],
  47. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  48. 'password' => ['required', 'string', 'min:8', 'confirmed'],
  49. //'phonenumber' => ['required', 'string', 'max:255'],
  50. 'universityname' => ['required', 'string', 'max:255'],
  51. 'department' => ['required', 'string', 'max:255'],
  52. 'designation' => ['required', 'string', 'max:255'],
  53. 'universitywebsite' => ['required', 'string', 'max:255'],
  54. ]);
  55. }
  56. /**
  57. * Create a new user instance after a valid registration.
  58. *
  59. * @param array $data
  60. * @return User
  61. */
  62. protected function create(Request $req)
  63. {
  64. $user_check_data =User::where('email',$req->email)->where('user_type',2)->where('sign_up',1)->doesntExist();
  65. if($user_check_data){
  66. $user_data = User::create([
  67. 'first_name' => $req->firstname,
  68. 'last_name' => $req->lastname,
  69. 'password' => Hash::make($req->password),
  70. 'email' => $req->email,
  71. // 'phone_number' => $req->phonenumber,
  72. 'university_name' => $req->university,
  73. 'department' => $req->department,
  74. 'others_department' => $req->others_department,
  75. 'designation' => $req->designation,
  76. 'uni_website' => $req->universitywebsite,
  77. 'user_type' => 2,
  78. 'ref_no' => name_initials($req->firstname,$req->lastname).''.teacherRefNoGenerate(),
  79. 'status' =>1,
  80. 'sign_up' => 1, // 1=signup
  81. 'registered_date' =>now(),
  82. ]);
  83. }else{
  84. return redirect()->to("/login-v2")->with('success','You are already registered. Please login here.');
  85. }
  86. $data['name'] = $user_data->first_name .' '.$user_data->last_name;
  87. $data['receive_email']=$user_data->email;
  88. $user_mail = $user_data->email;
  89. $from = 'asraful@revinr.com';
  90. Mail::send('email.register_teacher_email',$data, function ($message) use ($user_mail,$from) {
  91. $message->from($from);
  92. $message->to($user_mail)->subject('We’re excited to have you as a member of our community');
  93. });
  94. return redirect()->to("/login-v2")->with('success','Your registration successfully saved.');
  95. }
  96. /**
  97. * Show the application registration form.
  98. *
  99. * @return \Illuminate\Http\Response
  100. */
  101. public function showRegistrationForm()
  102. {
  103. $departments =Department::where('status',1)->orderBy('name','ASC')->get();
  104. $universities =University::orderBy('name','ASC')->get();
  105. return view('auth_supervisor.register-v2',compact('departments','universities'));
  106. }
  107. /**
  108. * Get the guard to be used during registration.
  109. *
  110. * @return \Illuminate\Contracts\Auth\StatefulGuard
  111. */
  112. protected function guard()
  113. {
  114. return Auth::guard('teacher');
  115. }
  116. }