WEBVTT 00:01.580 --> 00:07.280 So we have our sinor package written, and last time when I was talking about this final function expired, 00:07.880 --> 00:13.390 you may have noticed I got my true and false reversed when something has expired. 00:13.430 --> 00:14.630 This will return true. 00:14.660 --> 00:17.240 When something has not expired, it returns false. 00:17.750 --> 00:20.530 And that should be pretty clear right from the name of the function. 00:20.780 --> 00:21.760 And that was my mistake. 00:22.340 --> 00:27.220 But in any case, let's go over to our handlers, dash API and use this package. 00:27.890 --> 00:29.360 So the first thing we want to do. 00:30.540 --> 00:37.290 Is right here after we pass the juice and we need to create a valid Eurail that we can then sign now, 00:37.290 --> 00:41.610 of course, this URL doesn't exist yet, so we haven't written the logic on the front end to display 00:41.610 --> 00:44.740 the page, but we'll take care of that before too long. 00:44.940 --> 00:47.510 So let's create a variable, which I'm going to click. 00:50.340 --> 00:58.530 And link is a sign the value of format dot s print F and the string I want to format is starts with 00:58.530 --> 01:10.350 the percent s which will be the euro for our front end then slash reset dash password email equals percent 01:10.470 --> 01:10.800 s. 01:12.570 --> 01:15.350 And the first substitution is our you url to our front end. 01:15.450 --> 01:22.200 We get that from the config config front end and the second one is the email and we get that from payload 01:22.620 --> 01:23.030 email. 01:23.160 --> 01:32.700 So the URL will be in my case HTP column slash localhost part four thousand reset dash password questionmark. 01:32.700 --> 01:35.250 Email equals whatever email is taken to the form. 01:35.520 --> 01:41.580 OK, now we need to sign this and here's where we use our package and I'll just say sign. 01:41.610 --> 01:46.260 That's a variable is a sign the value of Eurail Sinar. 01:49.760 --> 01:51.290 Hopefully, that is the important for me. 01:52.600 --> 01:53.320 Dart Center. 01:57.150 --> 02:00.870 Right there, and I just populate that with my secret, 02:05.460 --> 02:12.660 which is Casta to a slice of bytes, I've got confect secret key. 02:17.210 --> 02:21.600 OK, so it looks like it didn't do the import for me well, for the quick fix will do it. 02:22.100 --> 02:23.440 Yes, and important. 02:25.310 --> 02:30.920 So now we have a variable we can use to call those three functions we just created, and of course, 02:30.950 --> 02:32.840 what I want to do here is create a sign link. 02:33.380 --> 02:34.790 So signed link 02:37.640 --> 02:46.190 is assigned the value of sign dot, generate token from string, and I hand it by link, but I created 02:46.190 --> 02:50.770 right up here in line for twenty three, so this should hand back a signed Yoro. 02:50.900 --> 02:56.000 So the next thing I have to do is get rid of this hardcoded Yoro and make that the sign link. 02:58.940 --> 03:04.670 OK, the only other thing I want to do at this point is people can type whatever they want but at an 03:04.790 --> 03:07.200 all right here that's not going to work email. 03:08.270 --> 03:13.280 The only other thing I need to do at this point is people can enter whatever email address they want 03:13.280 --> 03:14.210 on the front end. 03:14.690 --> 03:19.970 And I need to make sure that I actually have that user before I send the information back, before I 03:19.970 --> 03:21.040 send my JSON back. 03:21.590 --> 03:32.390 So after I do my read JSON and before I try to generate my link, let's just verify that the email verified 03:32.390 --> 03:33.710 that email exists. 03:34.160 --> 03:36.710 OK, so we can do that really easily. 03:37.070 --> 03:39.920 I'll ignore the first response because I don't actually care about the user. 03:40.190 --> 03:43.330 I just want to see if the user exists in my database. 03:44.120 --> 03:47.300 So ignoring the first return value but looking for an error. 03:47.300 --> 03:52.700 Let's call app dot get or debug get user by email and put in. 03:54.030 --> 03:59.010 Payload email, if error is not equal to nil. 04:00.330 --> 04:08.580 That means we can't find that email, so I'll just send a response via RESP is a struct and it has an 04:08.580 --> 04:10.580 error field, which is a boolean. 04:10.920 --> 04:16.110 And Jason, I'll call that error and it has a message. 04:19.180 --> 04:21.040 Which is also a bully and and Jason 04:24.790 --> 04:33.670 will call that message, and our populated values rest on error equals true because there is an error 04:33.880 --> 04:45.970 and resp message equals no matching email found on our system. 04:47.750 --> 04:48.650 And that should be a straight. 04:52.160 --> 04:55.410 And we just write that, Jason, and return so aptly, right, Jason? 04:56.420 --> 05:02.600 And that requires some kind of status and status accepted because I accepted it, but I'm not going 05:02.600 --> 05:03.380 to do anything with it. 05:03.800 --> 05:05.960 And our response in return. 05:07.490 --> 05:12.060 OK, so if everything went according to plan, I should be able to run this. 05:12.110 --> 05:12.790 Let's give it a try. 05:15.380 --> 05:16.420 So make start. 05:16.760 --> 05:17.750 I'll just start everything. 05:20.350 --> 05:22.210 It all compiled, that's good. 05:22.660 --> 05:28.930 Let's go back to our Web browser forgot password, so I'm going to put in me at here dot com, which 05:28.930 --> 05:29.690 doesn't exist. 05:29.740 --> 05:30.810 Let's see if we got it right. 05:31.730 --> 05:33.980 No matching email found in our system perfect. 05:34.250 --> 05:41.120 Now let's put in admin at example dot com, which is in our system. 05:43.250 --> 05:46.460 And it's centered let's go to Mail Trap and see what we get. 05:47.500 --> 05:53.950 So we have one here and there it is, click on the link below to get started and it gives me HDP localhost 05:53.950 --> 06:01.600 four thousand reset dash password questionmark email equals admitted example dotcom followed by an ampersand. 06:01.630 --> 06:04.720 Then here's the part that signs this link. 06:04.720 --> 06:08.580 It's a signed you URL hash equals all of this. 06:09.490 --> 06:13.600 Now we obviously can what we can click on that, but we'll just get a page not found or some kind of 06:13.600 --> 06:14.590 response like that. 06:14.830 --> 06:23.200 We need to next go create the URL on our front end to look for reset, dash password and then validate 06:23.560 --> 06:28.990 the signature for that URL and do something if it's valid and do something else if it's not. 06:29.170 --> 06:31.510 And we'll get started on that in the next lecture.