55use App \Http \Requests \Api \V1_0 \VolunteerRegistrationRequest ;
66use App \Http \Controllers \Controller ;
77use Dingo \Api \Routing \Helpers ;
8- use App \Vounteer ;
8+ use App \Volunteer ;
99use App \City ;
10+ use App \VerificationCode ;
11+ use App \Jobs \SendVerificationEmail ;
12+ use App \Utils \StringUtil ;
1013
1114class VolunteerAuthController extends Controller
1215{
@@ -31,14 +34,20 @@ public function register(VolunteerRegistrationRequest $request)
3134 // Get volunteer data, except city object
3235 $ volunteerInput = $ request ->except (['city ' ]);
3336 // Get city ID
34- //$cityId = $request->input('city.id');
37+ $ cityId = $ request ->input ('city.id ' );
38+ $ verificationCodeString = StringUtil::generateHashToken ();
3539
3640 // Create a new volunteer
37- //$volunteer = Volunteer::create($volunteerInput);
38- //$city = City::find($cityId);
39- //$volunteer->cities()->save($city);
41+ $ volunteer = Volunteer::create ($ volunteerInput );
42+ $ city = City::find ($ cityId );
43+ $ volunteer ->cities ()->save ($ city );
44+
45+ // Save verification code into the volunteer
46+ $ verificationCode = new VerificationCode (['code ' => $ verificationCodeString ]);
47+ $ volunteer ->verificationCode ()->save ($ verificationCode );
4048
41- // Send verification email
49+ // Send verification email to an queue
50+ $ this ->dispatch (new SendVerificationEmail ($ volunteer , $ verificationCodeString , 'Verification email ' ));
4251
4352 // Get authentication token
4453
0 commit comments