1 00:00:00,009 --> 00:00:04,329 Welcome back. So let's add one more feature. And this time it's gonna be 2 00:00:04,730 --> 00:00:07,750 a feature for our logged in users. 3 00:00:07,880 --> 00:00:12,720 We want them to be able to view their own personal logs. 4 00:00:12,920 --> 00:00:16,829 So this is gonna be in two steps. First, we'll have to create a function 5 00:00:17,110 --> 00:00:20,350 that would allow them to view their logs. And then second, 6 00:00:20,530 --> 00:00:24,430 we'll have to create a post login menu. 7 00:00:24,680 --> 00:00:28,010 So I log in users, they will have a separate menu where 8 00:00:28,139 --> 00:00:32,340 they will have the option to view the log. So this is going to be in two parts. 9 00:00:32,348 --> 00:00:34,650 First of all, let us create a function 10 00:00:34,919 --> 00:00:38,220 that would allow them to view the log. So 11 00:00:38,740 --> 00:00:42,700 I'm gonna do that just underneath the main login function. 12 00:00:42,709 --> 00:00:45,740 So let me just add a note in here that says uh 13 00:00:46,330 --> 00:00:47,779 function, 14 00:00:48,279 --> 00:00:51,060 uh sorry function 15 00:00:51,869 --> 00:00:54,009 to view logs. OK? 16 00:00:54,240 --> 00:00:56,130 I'm gonna call this function view 17 00:00:56,240 --> 00:00:57,599 on those call logs. 18 00:00:58,479 --> 00:01:00,659 And of course, we're gonna pass in the 19 00:01:00,830 --> 00:01:03,979 parameter user name. 20 00:01:04,760 --> 00:01:07,370 OK? At my colon. All right. 21 00:01:07,379 --> 00:01:09,610 So let's first of all print out like 22 00:01:09,620 --> 00:01:12,169 a general message saying something like you know, 23 00:01:12,180 --> 00:01:14,110 logs for user and then 24 00:01:14,309 --> 00:01:15,739 you know the particular user. So 25 00:01:16,099 --> 00:01:18,099 I'm gonna say print. 26 00:01:19,010 --> 00:01:20,230 Ok. And then 27 00:01:20,750 --> 00:01:24,620 let's have our F string and then let's have our coats 28 00:01:25,269 --> 00:01:30,769 and then let me add my backward slash and, and then we can say logs for 29 00:01:31,790 --> 00:01:31,800 a 30 00:01:31,919 --> 00:01:33,440 user 31 00:01:33,849 --> 00:01:34,650 and then 32 00:01:35,110 --> 00:01:37,209 we have a curly braces 33 00:01:38,290 --> 00:01:40,550 and then we can have the user name. 34 00:01:40,900 --> 00:01:45,339 Ok. Not necessary, but it's nice to have. All right. Now, 35 00:01:45,669 --> 00:01:50,690 we're gonna open up the audit log, the text file because it's from there. 36 00:01:50,760 --> 00:01:53,500 We're gonna pull in the logs. So I'm gonna say with, 37 00:01:53,819 --> 00:01:55,029 and now open 38 00:01:56,529 --> 00:01:58,480 and now in brackets, what's the name of the file? 39 00:01:58,839 --> 00:02:00,860 It is audit underscore log 40 00:02:02,010 --> 00:02:02,069 dot 41 00:02:02,860 --> 00:02:03,190 txt. 42 00:02:03,809 --> 00:02:06,709 And now, of course, we want to have 43 00:02:07,230 --> 00:02:08,419 the read mode, 44 00:02:09,679 --> 00:02:12,300 ok? Because we're going to read from the file 45 00:02:12,470 --> 00:02:15,970 and we're gonna say as log underscore file 46 00:02:16,490 --> 00:02:17,479 at our colon. 47 00:02:17,850 --> 00:02:22,520 And, ok, so now we're gonna go through the logs and the files, 48 00:02:22,529 --> 00:02:25,160 let's pass them into a variable called logs. 49 00:02:25,600 --> 00:02:29,740 And now log underscore file dot red lines. 50 00:02:30,880 --> 00:02:33,580 Ok? And there it is. 51 00:02:33,789 --> 00:02:34,429 Ok. 52 00:02:34,720 --> 00:02:37,839 So now we're gonna have to create some sort of 53 00:02:37,850 --> 00:02:42,059 a for loop that's gonna go through each individual logs. 54 00:02:42,070 --> 00:02:44,050 And what exactly are we looking for? 55 00:02:44,839 --> 00:02:49,899 We are looking for any logs that will match a particular user name. 56 00:02:49,949 --> 00:02:52,259 So I'm gonna come in here right now. 57 00:02:52,699 --> 00:02:54,300 All right. And I'm gonna say, 58 00:02:54,690 --> 00:02:54,919 uh, 59 00:02:55,779 --> 00:02:56,889 user logs, 60 00:02:57,649 --> 00:02:59,009 ok. User 61 00:02:59,240 --> 00:03:01,000 underscore logs 62 00:03:01,429 --> 00:03:03,190 is gonna be equal 63 00:03:03,559 --> 00:03:06,550 to and now check this out. I'm gonna open up at 64 00:03:07,110 --> 00:03:10,149 my brackets in here, I'm gonna say log dot strip. 65 00:03:10,990 --> 00:03:13,429 And the reason why I'm using the strip function is again, 66 00:03:13,440 --> 00:03:15,080 I want to remove any unnecessary 67 00:03:15,210 --> 00:03:20,320 white space or margins from the user names. So I'm gonna say log the strip and now 68 00:03:20,630 --> 00:03:22,600 I'm gonna say for 69 00:03:23,110 --> 00:03:25,449 log in logs. 70 00:03:25,660 --> 00:03:28,550 So especially for each individual log in our logs. 71 00:03:28,820 --> 00:03:32,009 And what are we looking for looking for if the user name 72 00:03:32,589 --> 00:03:38,479 is in the log? So we're looking for a very specific username in our log files. 73 00:03:38,490 --> 00:03:41,330 So now if we do in fact find 74 00:03:41,789 --> 00:03:45,289 a match for the log for the username or do we now do. So we're gonna say 75 00:03:46,089 --> 00:03:47,380 if user 76 00:03:47,929 --> 00:03:49,350 underscore logs 77 00:03:49,669 --> 00:03:50,990 add a colon 78 00:03:51,270 --> 00:03:54,220 and now I'm gonna say four log in 79 00:03:54,479 --> 00:03:55,330 user 80 00:03:56,250 --> 00:04:01,009 on those call logs, what we wanna do, we simply want to print. 81 00:04:01,500 --> 00:04:03,550 So I'm gonna say print and then 82 00:04:04,800 --> 00:04:05,419 log 83 00:04:05,919 --> 00:04:09,000 and there you go. And of course, we need to create a condition. 84 00:04:09,009 --> 00:04:10,479 What if no log was found? 85 00:04:10,610 --> 00:04:12,190 We can simply say else 86 00:04:12,440 --> 00:04:13,820 and now we can print, 87 00:04:15,250 --> 00:04:16,260 we can say 88 00:04:16,820 --> 00:04:19,250 no logs were found 89 00:04:21,309 --> 00:04:25,329 in your account because remember this is for the logged in user 90 00:04:25,880 --> 00:04:29,799 and there you go. So just to give you a very quick recap. 91 00:04:29,809 --> 00:04:32,869 All right, we defined the function as view on those logs 92 00:04:33,089 --> 00:04:34,899 and we passed in the username 93 00:04:35,220 --> 00:04:38,850 and now we printed out a general message saying, you know, logs for the user 94 00:04:39,570 --> 00:04:40,630 and then the username. 95 00:04:40,950 --> 00:04:45,190 And then we opened up the audit log, the TXT file, 96 00:04:45,420 --> 00:04:47,470 we're going to read from it as a log file. 97 00:04:47,589 --> 00:04:49,649 And then we created a available called logs 98 00:04:49,779 --> 00:04:53,390 that will actually use the method with lines for each particular log file. 99 00:04:53,739 --> 00:04:56,929 And now in here, we created our for loop 100 00:04:57,029 --> 00:05:00,750 that's going to go through each individual log in the logs 101 00:05:00,940 --> 00:05:05,040 and then see if there is a match for that user name. 102 00:05:05,049 --> 00:05:07,579 Now, if there is in fact a match, 103 00:05:07,589 --> 00:05:10,559 we can simply print out the log for that particular user. 104 00:05:10,570 --> 00:05:11,350 Otherwise 105 00:05:11,529 --> 00:05:16,160 we will simply say no logs are found in their account. 106 00:05:16,570 --> 00:05:19,790 So there it is, we have successfully created a function to view the logs. 107 00:05:19,950 --> 00:05:22,679 Join me in the next video where we're gonna create 108 00:05:23,250 --> 00:05:27,600 the post login menu for our logged in users.