RegisterController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use App\Providers\RouteServiceProvider;
  6. use App\User;
  7. use Illuminate\Support\Facades\Validator;
  8. use Illuminate\Foundation\Auth\RegistersUsers;
  9. use Illuminate\Support\Facades\Mail;
  10. use Illuminate\Support\Facades\Hash;
  11. //use App\Mail\SignUp;
  12. use App\Models\ReferUser;
  13. use Auth;
  14. use Illuminate\Support\Str;
  15. class RegisterController extends Controller
  16. {
  17. /*
  18. |--------------------------------------------------------------------------
  19. | Register Controller
  20. |--------------------------------------------------------------------------
  21. |
  22. | This controller handles the registration of new users as well as their
  23. | validation and creation. By default this controller uses a trait to
  24. | provide this functionality without requiring any additional code.
  25. |
  26. */
  27. // use RegistersUsers;
  28. /**
  29. * Where to redirect users after registration.
  30. *
  31. * @var string
  32. */
  33. //protected $redirectTo = RouteServiceProvider::HOME;
  34. /**
  35. * Create a new controller instance.
  36. *
  37. * @return void
  38. */
  39. public function __construct()
  40. {
  41. $this->middleware('guest');
  42. }
  43. /**
  44. * Get a validator for an incoming registration request.
  45. *
  46. * @param array $data
  47. * @return \Illuminate\Contracts\Validation\Validator
  48. */
  49. protected function validator(array $data)
  50. {
  51. // if($data['user_type']==1){
  52. return Validator::make($data, [
  53. 'givenname' => ['required', 'string', 'max:255'],
  54. 'familyname' => ['required', 'string', 'max:255'],
  55. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  56. 'password' => ['required', 'string', 'min:8', 'confirmed'],
  57. 'nationality' => ['required', 'string','max:255'],
  58. 'dob' => ['required', 'string','date'],
  59. 'optradio' => ['required', 'string','max:255'],
  60. ]);
  61. // }
  62. }
  63. /**
  64. * Create a new user instance after a valid registration.
  65. *
  66. * @param array $data
  67. * @return \App\User
  68. */
  69. protected function create(Request $req)
  70. {
  71. //if($data['user_type']==1){
  72. $token =Str::random(64);
  73. $user_data = User::create([
  74. 'first_name' => $req->givenname,
  75. 'last_name' => $req->familyname,
  76. 'email' => $req->email,
  77. 'nationality' => $req->nationality,
  78. 'dob' => \Carbon\Carbon::parse($req->dob)->format('Y-m-d'),
  79. 'gender' => $req->optradio,
  80. 'user_type' => $req->user_type,
  81. 'password' => Hash::make($req->password),
  82. 'status' => 1,
  83. 'remember_token' => $token,
  84. ]);
  85. $refer_user_exists = ReferUser::where('email',$req->email)->first();
  86. if($refer_user_exists){
  87. $refer_user_exists->signup =1;
  88. $refer_user_exists->update();
  89. }
  90. $data['token'] = $token;
  91. $data['name'] = $req->first_name .''.$req->last_name;
  92. $user_mail = $req->email;
  93. $from = 'test@mail.com';
  94. Mail::send('email.student_signup_verify_email',$data, function ($message) use ($user_mail,$from) {
  95. $message->from($from);
  96. $message->to($user_mail)->subject('Signup Email Verify');
  97. });
  98. return redirect()->to("/login")->with('success','Your registration successfully saved. Please check your email for verification');
  99. //}
  100. }
  101. public function showRegistrationForm()
  102. {
  103. return view('auth.register');
  104. }
  105. public function email_verification($token)
  106. {
  107. $data = User::where('remember_token',$token)->first();
  108. $data->email_verification=1;
  109. $data->email_verified_at=now();
  110. $data->update();
  111. return Redirect('/login')->with('success','Your mail is activated successfully. Login here ');
  112. }
  113. }