1
00:00:01,450 --> 00:00:07,840
So now we want to actually set up some routes to pages that are only available to users who are logged

2
00:00:07,840 --> 00:00:10,080
in, and that's really simple to do.

3
00:00:10,570 --> 00:00:14,860
First of all, what I'm going to do is create a handbook, a new handler, and I'm going to call it

4
00:00:14,860 --> 00:00:18,880
func, and it'll have the receiver of Repository, as usual.

5
00:00:21,280 --> 00:00:25,060
And I'm going to call it admin dashboard.

6
00:00:26,430 --> 00:00:29,340
And it's a handler, so we give it the standard parameters.

7
00:00:35,440 --> 00:00:41,470
And all that's going to do right now is show a simple template, OK, and the template doesn't exist,

8
00:00:41,470 --> 00:00:42,460
but we'll create it in a moment.

9
00:00:42,470 --> 00:00:46,440
It's going to be a really simple template for now just to make sure that things work as expected.

10
00:00:47,290 --> 00:00:48,940
So let's render the template.

11
00:00:51,450 --> 00:00:57,480
And the template is going to require the response writer, the pointer to the request, and we'll call

12
00:00:57,480 --> 00:01:06,000
it admin dashboard page dot tempo and we'll give it an empty models template data.

13
00:01:09,150 --> 00:01:13,690
OK, so that is our first step.

14
00:01:13,710 --> 00:01:19,650
Now let's go create a template, so in my templates folder, I'm going to create a really simple template,

15
00:01:20,500 --> 00:01:24,090
a new file, and I will call this admin.

16
00:01:26,790 --> 00:01:36,360
Dashboard page, up tempo, and there it is and all I'm going to say in this is this page is secure

17
00:01:36,540 --> 00:01:42,870
and we'll make a real template, a real dashboard template and dashboard admin pages in the next lecture

18
00:01:42,870 --> 00:01:43,590
or two.

19
00:01:44,280 --> 00:01:45,040
So let's save that.

20
00:01:45,270 --> 00:01:46,830
Now, let's go back to our roots.

21
00:01:46,830 --> 00:01:48,860
And here's the part where we protect our roots.

22
00:01:49,320 --> 00:01:57,150
What I'm going to do is create using mux, something that's built into the router that we're using in

23
00:01:57,150 --> 00:01:57,810
this package.

24
00:01:57,990 --> 00:02:01,970
And it's called Muxtape Root, and it requires a pattern.

25
00:02:02,010 --> 00:02:04,260
I'm going to give it a pattern of slash admin.

26
00:02:04,260 --> 00:02:09,630
Anything that starts with admin will be handled by this particular function.

27
00:02:09,900 --> 00:02:17,910
The root function on on the mux router and inside of that are the second parameter is itself going to

28
00:02:17,910 --> 00:02:25,980
be a function and an anonymous function that takes mux, which is of type Ketut router as a parameter.

29
00:02:27,030 --> 00:02:31,740
And the body of that function will be things that I want to do, routes that I want to match.

30
00:02:32,070 --> 00:02:36,810
So the first thing I'm going to do before I actually add any roots to this is we're going to use this

31
00:02:36,810 --> 00:02:37,260
middleware.

32
00:02:37,260 --> 00:02:39,510
And if you remember, let's open up our middleware file.

33
00:02:41,220 --> 00:02:47,280
We created this one, called off and all off does is to make sure that the user is authenticated.

34
00:02:47,310 --> 00:02:49,860
OK, so we're going to use that middleware in this route.

35
00:02:50,370 --> 00:02:56,260
And this middleware will only apply to things that are inside this Muxtape root function.

36
00:02:56,910 --> 00:03:00,390
So let's use the middleware mark use of.

37
00:03:02,140 --> 00:03:11,710
And now will create a new road and let's do let's do it as a get request must get and the pattern is

38
00:03:11,710 --> 00:03:14,560
going to have admin pretended to it.

39
00:03:14,830 --> 00:03:23,470
So what I want to add here is a route to dashboard, which will actually be a route to slash admin slash

40
00:03:23,470 --> 00:03:25,770
dashboard, and that's going to use a handler.

41
00:03:26,050 --> 00:03:35,500
So handlers repo and will use repo and will use the dashboard one we just created, which I believe

42
00:03:35,500 --> 00:03:36,750
I called admin dashboard.

43
00:03:36,940 --> 00:03:37,330
I did.

44
00:03:37,870 --> 00:03:42,240
OK, so we've created this right now, so let's try it out.

45
00:03:42,520 --> 00:03:43,750
Let's stop our application.

46
00:03:43,750 --> 00:03:45,370
If it's running, it is.

47
00:03:46,210 --> 00:03:46,810
And run it.

48
00:03:47,770 --> 00:03:51,400
And first of all, we'll go to our application, make sure we're not logged in.

49
00:03:51,400 --> 00:03:51,880
We're not.

50
00:03:51,880 --> 00:03:56,440
And let's try going to slash admin slash dashboard.

51
00:03:58,840 --> 00:04:01,720
And it takes me to the login page exactly as it should.

52
00:04:01,750 --> 00:04:06,640
So let's log in admin, admin, dot com password.

53
00:04:08,300 --> 00:04:13,880
Log in and now let's try going to that route again, admin dashboard.

54
00:04:16,160 --> 00:04:17,990
And it shows me that she is secure.

55
00:04:18,650 --> 00:04:25,070
So now we have a means of ensuring that certain routes in our application are only available to authenticated

56
00:04:25,070 --> 00:04:25,580
users.

57
00:04:25,860 --> 00:04:31,430
And what we need to do next is to actually build a back end that allows the property owner to look at

58
00:04:31,430 --> 00:04:35,120
reservations, to cancel them, to change them, whatever it may be.

59
00:04:35,270 --> 00:04:37,910
And we'll do that in the next section of the course.
