1 00:00:00,090 --> 00:00:00,350 OK. 2 00:00:00,390 --> 00:00:07,470 So back to visual studio we'll look at firstly our icons controller and I mean we could sit down and 3 00:00:07,470 --> 00:00:13,440 dissect everything that is here but what I really want to point out are the fact that it does have actions 4 00:00:13,440 --> 00:00:15,010 for the log in. 5 00:00:15,090 --> 00:00:21,090 It does have a GET and POST action where it validates who is the person logging in and then takes an 6 00:00:21,120 --> 00:00:22,170 action. 7 00:00:22,230 --> 00:00:25,770 It's just a bunch of statements that we're used to. 8 00:00:25,830 --> 00:00:31,710 And then you get some other code because remember it's not all about verifying or validating against 9 00:00:31,740 --> 00:00:41,250 a local database but it also gave us code to allow us to register and sign up for an application using 10 00:00:41,550 --> 00:00:44,550 social media accounts for this video. 11 00:00:44,550 --> 00:00:52,830 However we're going to simply look at controlling registration and log in using our own local database 12 00:00:52,860 --> 00:00:56,610 and what we need to do in order to support that. 13 00:00:56,640 --> 00:01:00,140 Now let's systematically go through all of this code. 14 00:01:00,150 --> 00:01:00,510 All right. 15 00:01:01,110 --> 00:01:07,920 So the first thing to point out is that in the models folder you would have gotten some model files 16 00:01:08,850 --> 00:01:12,920 particularly identity model not C.S. identity models. 17 00:01:12,920 --> 00:01:13,850 That's yes. 18 00:01:14,040 --> 00:01:20,160 And this file would be either initialize it for the entire identity engine which is what controls I 19 00:01:20,160 --> 00:01:22,110 use the authentication engine. 20 00:01:22,110 --> 00:01:30,690 Right now this user authentication engine actually automatically creates a database for you at least 21 00:01:30,690 --> 00:01:36,180 if you don't already have one if you already have one then it takes a bit of configuration to ensure 22 00:01:36,480 --> 00:01:43,290 that you are going to be pointing to the database that you wanted to point to in our model file. 23 00:01:43,290 --> 00:01:47,360 Identity models we'll see that we have two classes. 24 00:01:47,370 --> 00:01:56,190 Application user and application DV context and application DB context points to some connections string 25 00:01:56,220 --> 00:02:03,330 called default connect so what happens is that once you generate all this code and an identity engine 26 00:02:03,720 --> 00:02:09,050 it actually will generate a database for you on the first launch. 27 00:02:09,060 --> 00:02:09,390 All right. 28 00:02:09,750 --> 00:02:16,830 And this database will be generated based on the specifications set up in in default connection. 29 00:02:17,010 --> 00:02:22,860 So we can go to solution explorer and take a look at the Web config file. 30 00:02:22,860 --> 00:02:24,100 That's a Web config. 31 00:02:24,320 --> 00:02:30,630 And the last one here that is at the project level there is another one here in the view's level that 32 00:02:30,630 --> 00:02:33,200 is not the one you are to be looking at. 33 00:02:33,210 --> 00:02:39,950 So the last Web config file that is in the project let's go both of the project. 34 00:02:39,950 --> 00:02:46,570 It will have under the connection strings section in line 12. 35 00:02:46,580 --> 00:02:51,830 It may vary but you'll see a connection string here with the name default connection. 36 00:02:51,980 --> 00:02:58,640 And if you take a look at what is in the connection string value you'll see it has a quite unique looking 37 00:02:59,210 --> 00:03:00,230 value there. 38 00:03:00,350 --> 00:03:05,270 And what it is doing is creating a database that has the same name as your project. 39 00:03:05,870 --> 00:03:14,350 And it will use that as the engine for your identity functions. 40 00:03:14,360 --> 00:03:20,540 Now if I take a look at server Explorer I see that I indeed in fact do have a database set of default 41 00:03:20,540 --> 00:03:27,840 connection and in brackets school management and you'll see that it has all of those tables right. 42 00:03:27,860 --> 00:03:32,540 It has quite a few tables and I added a few tables there afterwards. 43 00:03:32,540 --> 00:03:34,050 But don't mind those. 44 00:03:34,130 --> 00:03:36,600 You should see at least these. 45 00:03:37,150 --> 00:03:43,910 But that is not necessarily what is desired because we have already been working on our database we 46 00:03:43,910 --> 00:03:49,440 are at this point because we are doing database first MVC five developments. 47 00:03:49,610 --> 00:03:59,360 So indeed in fact what should be used to hold our identity tables should be our database that we have 48 00:03:59,360 --> 00:04:06,420 come this far with which is housed in the school management on a square D.B. entities connection string. 49 00:04:06,470 --> 00:04:13,130 And if we look at this connection string we see that it is indeed and in fact pointing to the data base 50 00:04:13,310 --> 00:04:18,470 in our local EBA called school management D.B.. 51 00:04:18,800 --> 00:04:26,510 That is the database that we really want to be using to house all of our user interactions are user 52 00:04:26,510 --> 00:04:33,190 authentication and the various user based functions. 53 00:04:33,200 --> 00:04:33,590 All right. 54 00:04:33,860 --> 00:04:40,700 So the first thing you want to do is change where this is pointing to an I already have that line of 55 00:04:40,700 --> 00:04:41,020 code. 56 00:04:41,030 --> 00:04:43,100 I did this all right. 57 00:04:43,340 --> 00:04:44,560 And I'll walk you through it. 58 00:04:44,560 --> 00:04:51,440 So just comment this line and on Comment this line and I'll walk you through the changes I made that 59 00:04:51,480 --> 00:05:00,380 took everything out of the data source and then I replaced it with the values coming from the data source 60 00:05:01,160 --> 00:05:11,320 here so I looked in my entity's connection string and I scroll across until I saw data source. 61 00:05:11,510 --> 00:05:17,900 So we have connection string is equal to and then we have data source and then I took everything here 62 00:05:17,900 --> 00:05:27,180 from local D.B. sorry right down to the last one I don't think you need everything but just to give 63 00:05:27,180 --> 00:05:29,430 you some clarity. 64 00:05:29,430 --> 00:05:35,630 And then I used that value and paste it here in data source right here. 65 00:05:35,670 --> 00:05:39,320 So at least the two of them are looking to the same point. 66 00:05:41,210 --> 00:05:48,410 And then you're probably going to ask so why not just change the connection string that is being referenced 67 00:05:48,650 --> 00:05:51,600 inside our identity model. 68 00:05:51,620 --> 00:05:52,150 No. 69 00:05:52,190 --> 00:05:58,430 The problem with doing that is we're using entity framework and identities does not play well with this 70 00:05:58,430 --> 00:06:00,430 flavor of entity framework. 71 00:06:00,530 --> 00:06:06,670 So it will actually give you an error if you try to replace the connection string that identity model 72 00:06:06,670 --> 00:06:07,370 is using. 73 00:06:07,370 --> 00:06:13,400 You can try it and see the error for yourself and if you have had any success with it that would go 74 00:06:13,400 --> 00:06:18,470 contrary to what I'm seeing then drop me a line and let me know when we can have a discussion about 75 00:06:18,470 --> 00:06:18,860 it. 76 00:06:18,920 --> 00:06:24,860 But my thing is I just kept default connection I could always rename its books. 77 00:06:24,860 --> 00:06:30,170 I have to make sure it matches a connection string here in this config file and then I changed out the 78 00:06:30,170 --> 00:06:34,130 value in connection string to point to my database. 79 00:06:34,130 --> 00:06:40,340 Now having done so once you go into debug mode it will then one search for whatever database. 80 00:06:41,030 --> 00:06:46,740 So in this case since it didn't exist it's actually created this database at the time. 81 00:06:46,970 --> 00:06:54,290 And then what it will do if the database is found which it will be in this case is go ahead and generate 82 00:06:54,350 --> 00:06:55,510 those tables. 83 00:06:55,520 --> 00:07:02,210 So if I look back in server explorer and look at all the tables you'll see that I know have all of those 84 00:07:02,210 --> 00:07:04,490 tables created here. 85 00:07:04,940 --> 00:07:10,040 And if I look inside of is being that users by clicking and viewing the data 86 00:07:13,130 --> 00:07:17,070 I will see that the user I just created is right here. 87 00:07:17,090 --> 00:07:22,310 The idea looks a bit weird because we're probably used to that auto incrementing This is what you call 88 00:07:22,310 --> 00:07:27,000 a Jew idea good or very unique ideas value. 89 00:07:27,070 --> 00:07:32,840 All right we have the email address and we have a few forces but look at this. 90 00:07:32,870 --> 00:07:34,340 Look at the password. 91 00:07:34,340 --> 00:07:38,140 This is not just a password but it's called a password hash. 92 00:07:38,150 --> 00:07:39,020 Look at it. 93 00:07:39,020 --> 00:07:40,590 Take a good look at that. 94 00:07:40,640 --> 00:07:48,230 It is always good practice to encrypt your passwords so that somebody by any stroke of luck got to look 95 00:07:48,230 --> 00:07:52,700 at your database and look at their users record as much as they can see the e-mail address. 96 00:07:52,700 --> 00:07:56,080 They should never be able to make out what this password is. 97 00:07:56,120 --> 00:08:01,100 And if you look at what comes up in that tooltip you see that that is a full value of this password. 98 00:08:01,100 --> 00:08:04,850 It is completely unintelligible to a human being. 99 00:08:04,850 --> 00:08:05,210 All right. 100 00:08:05,600 --> 00:08:14,000 And then they have a few other default carloads that go in and you see the user name is automatically 101 00:08:14,000 --> 00:08:16,940 set to whatever the e-mail address is. 102 00:08:16,940 --> 00:08:17,210 All right. 103 00:08:17,240 --> 00:08:20,930 So that obtains for every user that you create. 104 00:08:21,000 --> 00:08:23,170 You see that they also have support for rules. 105 00:08:23,180 --> 00:08:24,910 I don't have any rules. 106 00:08:24,960 --> 00:08:29,770 Now let's get back to our model application user. 107 00:08:29,860 --> 00:08:36,350 Now the challenge with this auto generated code is that it doesn't necessarily capture all of the data 108 00:08:36,380 --> 00:08:39,290 that we want to capture based on our context. 109 00:08:39,290 --> 00:08:45,320 So for instance I'm doing a school management system if I'm going to have users I'm going to definitely 110 00:08:45,320 --> 00:08:48,740 need more than email address and password for my users. 111 00:08:48,740 --> 00:08:54,220 I'm probably going to want a date of birth for my students and went to once and I dress for my teacher. 112 00:08:54,260 --> 00:08:57,140 So I will I'm going to want additional information. 113 00:08:57,140 --> 00:08:57,500 All right. 114 00:08:57,860 --> 00:09:06,650 So we need to be able to modify our context or our model that is governing what a user looks like to 115 00:09:06,650 --> 00:09:08,860 our application. 116 00:09:08,880 --> 00:09:12,490 No there are a few changes that will need to be made. 117 00:09:12,500 --> 00:09:15,920 The first one is with application user. 118 00:09:15,950 --> 00:09:22,580 So we want to go ahead and add the property dates of birth to this class so I can just write up in Visual 119 00:09:22,580 --> 00:09:24,060 Studio and press stuff twice. 120 00:09:24,080 --> 00:09:26,320 And that will generate that line. 121 00:09:26,390 --> 00:09:37,070 I would want that date of birth to be a date time data type and I would want it to be birth date and 122 00:09:37,070 --> 00:09:43,880 then I can just use this clarified that using system in order to get our date time to recall. 123 00:09:43,910 --> 00:09:47,080 You have to use certain libraries to get certain class types. 124 00:09:47,510 --> 00:09:55,050 So we know have new property in our user called Date of birth or birth dates rather. 125 00:09:55,070 --> 00:10:02,240 So that is modification number one under our belt do know to add as many properties as you need and 126 00:10:02,240 --> 00:10:09,920 be sure to use the correct data type as you see you need to when you're storing the data because whatever 127 00:10:09,920 --> 00:10:16,010 data type you're going to use here in C sharp is going to be translated over into our school for further 128 00:10:16,010 --> 00:10:16,580 storage. 129 00:10:16,610 --> 00:10:21,070 So be very very deliberate with your data types. 130 00:10:21,170 --> 00:10:28,760 The next step is to make what you call a migration or a change to the database. 131 00:10:28,760 --> 00:10:33,880 Now we've gone through making changes to the database we saw that we just need to go into our SVOD explorer 132 00:10:33,890 --> 00:10:38,090 bring up the table modify it and then update our DMX. 133 00:10:38,090 --> 00:10:45,080 The problem here however is that while this EDL mix has not been updated to reflect the new tables and 134 00:10:45,080 --> 00:10:51,200 to making the change just like that does not necessarily mean that application is going to know what 135 00:10:51,200 --> 00:10:51,860 to do 136 00:10:54,920 --> 00:11:00,630 now we need to run a migration and to do that we're going to have to get our hands a bit dirty with 137 00:11:00,690 --> 00:11:05,580 our console which means this is one of those things that can just click and generate. 138 00:11:05,580 --> 00:11:08,780 You'll have to write a bit of code here to do that. 139 00:11:08,850 --> 00:11:16,950 So we will want to write some code to enable migrations and further on the migrations using our package 140 00:11:17,010 --> 00:11:18,870 manager console. 141 00:11:18,960 --> 00:11:22,900 I have it here on Dr. toolbar already. 142 00:11:23,040 --> 00:11:31,500 But then if you don't have it there or anywhere visible then you can always go to Tools and then go 143 00:11:31,500 --> 00:11:38,250 to New get package manager and then you just click package manager console and that will generate this 144 00:11:38,250 --> 00:11:39,210 console. 145 00:11:39,270 --> 00:11:41,120 So I'm going to. 146 00:11:41,610 --> 00:11:47,820 So I could add my console of any messy era that was there and then we will look at enabling migrations 147 00:11:47,820 --> 00:11:48,770 first and foremost. 148 00:11:48,770 --> 00:11:53,500 So we'll write enable dash my creations. 149 00:11:53,850 --> 00:11:58,950 Press enter and then I'm actually going to reproduce that error that we just saw. 150 00:11:59,250 --> 00:12:07,710 So this arrow is saying that we can't have a migration being done in ambiguity because I have more than 151 00:12:07,710 --> 00:12:14,250 one context the other context it doesn't know which context or which database connection or remember 152 00:12:14,250 --> 00:12:19,350 that we had to connection strings as told by our web config file. 153 00:12:19,350 --> 00:12:20,930 That was a wrong one sorry. 154 00:12:20,950 --> 00:12:24,990 In Web config we had context number one context number two. 155 00:12:25,020 --> 00:12:32,370 Or rather we had context number one application DB context as well as context number two. 156 00:12:32,370 --> 00:12:38,220 Do remember that this is a database context in waiting enable migrations is saying I don't know which 157 00:12:38,220 --> 00:12:41,310 one you want to use this command on. 158 00:12:41,490 --> 00:12:44,030 So we have to be a bit more specific. 159 00:12:45,480 --> 00:12:47,940 So they actually instruct you as to what to say. 160 00:12:47,940 --> 00:12:50,790 They see use and they see it for both. 161 00:12:50,790 --> 00:12:57,450 So more than one context to respond to Niblett for the application DB context then we need to see enable 162 00:12:57,450 --> 00:13:03,560 migrations for this at that and then if we wanted for the entity's context then we need to enabling 163 00:13:03,570 --> 00:13:05,350 for that. 164 00:13:05,400 --> 00:13:11,580 So I would want it's on the application DB cleantech since that is the one that's read and truly we 165 00:13:11,580 --> 00:13:16,010 are identifying as our user management are context. 166 00:13:16,020 --> 00:13:21,900 So I'm going to see here enable migrations I can just press up to see the last command and then I'll 167 00:13:21,900 --> 00:13:24,150 see Dash context 168 00:13:27,170 --> 00:13:34,130 type name and I just press tab and it generated that line and then I'm just going to copy and paste 169 00:13:34,370 --> 00:13:42,230 this part to reduce the margin for error application context D.B. and this press enter and see what 170 00:13:42,230 --> 00:13:49,640 happens so that operation may have taken a while but then we'll see here that's completed and we've 171 00:13:49,640 --> 00:13:53,400 got a new file configuration that see us. 172 00:13:53,540 --> 00:14:00,980 And we also have a tiny warning here saying that they detected that another migration may have occurred 173 00:14:01,340 --> 00:14:07,750 but the end result is that we have enabled it for our project. 174 00:14:07,790 --> 00:14:08,170 All right. 175 00:14:08,180 --> 00:14:15,690 So the next thing we want to do is actually register our migration So migration is pretty much like 176 00:14:15,740 --> 00:14:17,360 making a change to the database. 177 00:14:17,360 --> 00:14:19,740 You'd make a change to the database. 178 00:14:19,940 --> 00:14:26,990 In this situation though we're making a change to the model that is generating the database so open 179 00:14:26,990 --> 00:14:30,670 to this boy web generated models based on the database. 180 00:14:30,860 --> 00:14:34,030 These models are generated based on the database. 181 00:14:34,160 --> 00:14:41,660 In this situation the database was generated based on application user model which is inheriting from 182 00:14:41,660 --> 00:14:46,810 identity user which is where all of those default tables and columns were generated from. 183 00:14:46,850 --> 00:14:50,090 So we actually modified the base model. 184 00:14:50,180 --> 00:14:55,970 So we need to inform the database that the model that it should emulate is now updated. 185 00:14:55,970 --> 00:15:01,810 And this is a principle in code first development we're doing database for as developments. 186 00:15:01,820 --> 00:15:03,680 So it called first development. 187 00:15:03,680 --> 00:15:09,710 That is how it is you build them based model and then you generate the database based on that. 188 00:15:09,980 --> 00:15:16,760 So in this situation we need to let our database know that we've made a change or we're going to add 189 00:15:16,760 --> 00:15:17,480 a migration. 190 00:15:17,480 --> 00:15:27,810 So I'm going to add dash migration and I'm going to name it added birth date. 191 00:15:28,040 --> 00:15:34,910 That is the name of this migration that I am registering so I'm just going to press enter and then this 192 00:15:34,910 --> 00:15:37,310 is also going to do a little operation. 193 00:15:37,400 --> 00:15:40,820 And when this is completed you'll see that you would have gotten another file. 194 00:15:40,910 --> 00:15:46,220 And just to take a look at where these files are being stored you actually got a new folder called migrations 195 00:15:46,520 --> 00:15:49,760 and then you see all of those migration files being listed there. 196 00:15:49,760 --> 00:15:56,540 So each time you add a migration then a file is generated just to keep track of the changes that are 197 00:15:56,540 --> 00:15:57,590 being made. 198 00:15:57,590 --> 00:16:02,750 The good thing about this is that you can roll back to a specific migration in case you think you may 199 00:16:02,750 --> 00:16:07,970 have botched your data model or you've made a change that was undesirable you can just roll back your 200 00:16:07,970 --> 00:16:11,330 migration and it would undo the changes to your database. 201 00:16:11,330 --> 00:16:20,480 So this code first methodology does come in handy when you're dealing with a very dynamic project and 202 00:16:20,480 --> 00:16:25,160 you don't necessarily know what your database is until you are developing the feature. 203 00:16:25,190 --> 00:16:32,080 So this works well with a more agile approach than having the database and building our own database. 204 00:16:32,090 --> 00:16:37,910 That being said after we get this file the last thing we need to do is actually update the database 205 00:16:37,910 --> 00:16:43,430 so we see updates dash database and then press enter. 206 00:16:43,430 --> 00:16:43,850 All right. 207 00:16:43,850 --> 00:16:50,750 And then we get a bit of verbiage seeing that we can see of the dash database space dash verbose and 208 00:16:50,750 --> 00:16:55,990 that would show us all of the obscure statements being applied to the target database meaning whatever 209 00:16:56,000 --> 00:17:00,880 statements would have been used to meet that change and add that column but the end result is we see 210 00:17:00,890 --> 00:17:06,440 seen or at writing so we can assume that we have no errors and that we can always go back to our server 211 00:17:06,440 --> 00:17:14,480 explorer and refresh our table and voilĂ  there is a birth date added to our table so you can do this 212 00:17:14,480 --> 00:17:17,890 with as many other columns as you see fit. 213 00:17:17,900 --> 00:17:21,130 I'm just using birthday today as a quick example. 214 00:17:21,200 --> 00:17:29,870 Once again you simply add your column here or as a property or other and then you run a migration. 215 00:17:29,870 --> 00:17:35,560 The great thing is that you already enables migrations so you don't need to go through that step again. 216 00:17:35,720 --> 00:17:42,020 What happens here after is that each time you make a change you have to add a migration and to its name 217 00:17:42,110 --> 00:17:49,820 what migration was done and then you run an update command and that will keep track of all of your changes 218 00:17:49,850 --> 00:17:56,180 as you go along because you know your project may expand it might contract your requirements change 219 00:17:56,210 --> 00:18:04,000 and you need to be rather dynamic with what you're storing as user information. 220 00:18:04,250 --> 00:18:11,990 So that is how you go about customizing this identity model to what you may need in order to complete 221 00:18:12,110 --> 00:18:15,240 your task. 222 00:18:15,260 --> 00:18:22,160 No where have about two more steps and then we can call this relatively completed the fact that you 223 00:18:22,160 --> 00:18:25,460 added this to the database does not change the view. 224 00:18:25,610 --> 00:18:31,460 So remember although we update the model we still need to modify our view to be able to collect this 225 00:18:31,460 --> 00:18:37,130 information and there are a few more steps that need to go in in order to accomplish this. 226 00:18:37,130 --> 00:18:40,310 So firstly we need to understand where what is stored. 227 00:18:40,340 --> 00:18:47,030 So remember all views are stored in a views folder in a folder that corresponds with the controller 228 00:18:47,270 --> 00:18:49,190 that it is related to. 229 00:18:49,190 --> 00:18:55,760 So we have that Collins controller for user authentication so we have that ConEd views folder for all 230 00:18:55,880 --> 00:19:04,810 views related to that and then we do have or register page now already start page is what asked those 231 00:19:04,810 --> 00:19:12,340 for the user name which in other words would be the e-mail and the password and then it ask for a confirmed 232 00:19:12,340 --> 00:19:20,650 password as you see there is some configuration some generated code in the book and that gives us the 233 00:19:21,580 --> 00:19:26,650 the comparison between the password on the confirmed password before it actually accepts that data you 234 00:19:26,650 --> 00:19:31,960 can attempt to have mismatched passwords and see that validation message that comes back. 235 00:19:31,960 --> 00:19:35,070 And remember that must validation message will come back on top. 236 00:19:35,070 --> 00:19:38,490 Here are the set of them would come back here. 237 00:19:38,530 --> 00:19:45,120 So what we want to do is add birth date as a field so I already have email. 238 00:19:45,310 --> 00:19:55,340 I would probably want to select or collect the birth date right after email so I can see it as the birth 239 00:19:55,940 --> 00:19:59,350 date and birth date. 240 00:19:59,360 --> 00:20:06,950 But then you would notice that there is no birth dates coming up in the intelligence because our model 241 00:20:07,370 --> 00:20:09,570 does not know anything about birth dates. 242 00:20:09,570 --> 00:20:14,390 So I'm just going to put it there and we see that as a red line because our model once again does not 243 00:20:14,390 --> 00:20:16,070 know what birth date is. 244 00:20:16,160 --> 00:20:23,020 If we look at what the model is we'll see another country's new construct being introduced called a 245 00:20:23,060 --> 00:20:23,900 view model. 246 00:20:23,930 --> 00:20:27,850 So it's really just a model like any other class that we've seen. 247 00:20:27,860 --> 00:20:35,170 It's just that the view model the principle of view models is that you the developer can actually customize 248 00:20:35,170 --> 00:20:41,750 a class that helps you to add your own data and notations and validations and so on and then you pass 249 00:20:41,750 --> 00:20:45,500 it on into the database or match it back to the model at will. 250 00:20:46,160 --> 00:20:52,490 I would have to do an entirely different tutorial on that view model point of view and perspective but 251 00:20:52,520 --> 00:20:58,730 then let's just beer through this one and hopefully connect the dots if not you can always watch that 252 00:20:58,730 --> 00:21:00,800 video. 253 00:21:00,800 --> 00:21:09,050 So we need to modify our view model so that the page will know about birth dates so if we just control 254 00:21:09,050 --> 00:21:16,250 and click on the register view model we'll be navigated to it and it is really being hosed in a file 255 00:21:16,280 --> 00:21:23,000 called a ConEd view models so in solution explore if we go into models we see that we have a ConEd view 256 00:21:23,000 --> 00:21:25,150 models all right. 257 00:21:25,370 --> 00:21:31,550 And then if we open that file we see that we have quite a few models view models rather that kind of 258 00:21:32,000 --> 00:21:37,830 have the same names as some of the views that you would have seen in the cones controller. 259 00:21:37,850 --> 00:21:45,260 All right so you have verified code view model you have verified code view you have for got view model 260 00:21:46,100 --> 00:21:53,110 if you look in solution explorer you have a forgot or forgot password views are so read entry level 261 00:21:53,120 --> 00:21:59,690 view model is more of a specific type of class that you create and you can set up your data annotations 262 00:21:59,690 --> 00:22:05,120 are will you see that there are quite a few data annotations that would validation and what is displayed 263 00:22:05,420 --> 00:22:12,590 and that gives you greater control over how you generate your view and what you display on it versus 264 00:22:12,590 --> 00:22:17,300 the view coming the model coming back from the database where you kind of have to work with what you 265 00:22:17,300 --> 00:22:19,030 get kind of vibe. 266 00:22:19,100 --> 00:22:22,410 So this is a far more flexible way for you too. 267 00:22:22,430 --> 00:22:26,990 It's a bit more work but it is a flexible way for you to manage your views. 268 00:22:27,080 --> 00:22:32,200 So if we look at our register view model we see that this is required. 269 00:22:32,210 --> 00:22:37,730 It's an email address the displays emails so we all know from our data annotations video that we can 270 00:22:37,730 --> 00:22:39,630 change what is displayed here. 271 00:22:39,730 --> 00:22:40,390 All right. 272 00:22:41,120 --> 00:22:46,570 Email address slash user name since they're doubling all right. 273 00:22:46,580 --> 00:22:52,370 So I can say email or just slash user name and that would change that display and we have the property 274 00:22:52,670 --> 00:22:53,230 email. 275 00:22:53,270 --> 00:23:00,190 So what I need to do in order for this view model to normal birthdate is added here as a property. 276 00:23:00,200 --> 00:23:02,070 So I will go down. 277 00:23:02,080 --> 00:23:05,120 So I'm going to make the birth date mandatory. 278 00:23:05,120 --> 00:23:07,580 So I'm going to say are required. 279 00:23:07,580 --> 00:23:12,050 I'm going to specify the data type so you have some default ones like this. 280 00:23:12,050 --> 00:23:17,060 That's an e-mail that just attributes but this one I'm going to have to use my data type. 281 00:23:17,060 --> 00:23:24,680 I think these are knows so data type and then open and close parentheses and then set up those parentheses 282 00:23:24,830 --> 00:23:31,700 as the parameters I would say data type dot date time and you'll see they have quite a few ones coming 283 00:23:31,700 --> 00:23:38,750 up in the intelligence so you have all of those that you can use if you need to add that kind of validation 284 00:23:39,110 --> 00:23:42,460 to whatever field you're able to put in. 285 00:23:42,680 --> 00:23:53,770 So the data type must be of type the time and the display will be. 286 00:23:53,960 --> 00:23:56,240 Date of birth. 287 00:23:56,630 --> 00:24:05,160 And once again this is where that display name comes in because I'm really calling this birthdate so 288 00:24:05,160 --> 00:24:11,930 it is of type it time and it is birth date. 289 00:24:14,550 --> 00:24:20,480 And then once again I being through the library for Date Time which is using system. 290 00:24:20,520 --> 00:24:28,710 Having done that the narrow line will go away because no our model knows what birth date is. 291 00:24:28,710 --> 00:24:39,240 And then the final piece of this puzzle is to modify or a cone controller in our register post option 292 00:24:40,920 --> 00:24:46,500 where it is actually loading up our model to send off to the database. 293 00:24:46,500 --> 00:24:53,670 So we see var user is equal to new application user or Amber where application user is coming from. 294 00:24:53,670 --> 00:24:57,270 It is the class that we just added. 295 00:24:57,270 --> 00:24:59,750 Birth date to application user. 296 00:24:59,750 --> 00:25:00,680 Birth date. 297 00:25:00,690 --> 00:25:12,870 So we need to update this creation model description of an object of application user to see user name 298 00:25:13,680 --> 00:25:16,290 email and then either edit it. 299 00:25:16,290 --> 00:25:22,440 So that's what it would be but we don't want it to be daytime but no we'll just add it on and say birth 300 00:25:22,860 --> 00:25:25,860 date is equal to model 301 00:25:28,430 --> 00:25:30,770 dot birth date. 302 00:25:33,020 --> 00:25:39,980 So remember that once the post option once we get the view and then it is submitted it turns over to 303 00:25:39,980 --> 00:25:41,810 the post action the post. 304 00:25:41,810 --> 00:25:49,610 Action is then receiving an object off register view model called model and in this register view model 305 00:25:49,610 --> 00:26:01,850 or model object called model we are using the corresponding data fields to fill out these properties. 306 00:26:01,850 --> 00:26:08,960 So that means I could easily add another field here and call it a user name and then instead of using 307 00:26:08,960 --> 00:26:16,490 the email address for both email and user name we can see a model dot username after adding an appropriate 308 00:26:16,490 --> 00:26:20,630 text box or collection section for the user name. 309 00:26:21,020 --> 00:26:29,840 So whatever modifications you're going to make to your application user model you have to also make 310 00:26:29,840 --> 00:26:34,220 it to your register view model then the register view. 311 00:26:34,220 --> 00:26:36,530 In order to have synchronicity there. 312 00:26:36,800 --> 00:26:43,970 And then finally or a current controller and all of that can't be done without doing these migration 313 00:26:44,480 --> 00:26:45,300 steps. 314 00:26:45,500 --> 00:26:53,120 So I was actually in the notes right out the steps towards filling out or completing all these tasks 315 00:26:53,540 --> 00:26:54,400 step by step. 316 00:26:54,440 --> 00:26:58,410 If you follow those steps then you can't leave any stone unturned. 317 00:26:58,610 --> 00:27:06,520 So to wrap this up let us make sure that the changes that we made are reflecting in the functionality. 318 00:27:06,520 --> 00:27:09,980 So once again I mean the chance of data annotations as it emerges. 319 00:27:09,980 --> 00:27:14,920 This is a name known to use a shadow of the same email address or user name. 320 00:27:14,930 --> 00:27:21,620 If I try to register then we will get something about the dates of birth field being required because 321 00:27:21,620 --> 00:27:27,770 we set up that data annotation and the passwords do not match because there is also a generated code 322 00:27:28,040 --> 00:27:30,230 or annotations that govern that. 323 00:27:31,130 --> 00:27:37,090 So all of those things are in place the dates of birth really and truly you want to use. 324 00:27:37,200 --> 00:27:38,250 And the picture here. 325 00:27:38,270 --> 00:27:44,360 You don't want to have dates of birth just being a free text field as much as it's a date time and it 326 00:27:44,360 --> 00:27:52,010 will not accept that but then users will try to type in the date according to how they think they should 327 00:27:52,010 --> 00:27:52,430 look. 328 00:27:52,430 --> 00:27:54,790 Some people see year month day. 329 00:27:54,800 --> 00:27:59,910 Some people say year day month some say day month year et cetera et cetera et cetera. 330 00:27:59,920 --> 00:28:06,470 So you want to use a calendar because enforce the standard from right here as much as you can. 331 00:28:06,500 --> 00:28:08,100 But I won't go into that right. 332 00:28:08,110 --> 00:28:19,130 No I'll just write a very generic kind of random date and I will use a password test password and it's 333 00:28:19,130 --> 00:28:25,290 more they'll know that you can use data annotations to actually govern how strict these passwords are. 334 00:28:25,430 --> 00:28:26,180 That's a mismatch. 335 00:28:26,180 --> 00:28:27,790 Also that metric. 336 00:28:27,880 --> 00:28:34,790 That is a mismatch so type in a password and then press register. 337 00:28:34,790 --> 00:28:41,570 So it does actually click register and see what happens and then it gives us that standard about that 338 00:28:41,570 --> 00:28:44,480 password so let me try that again test. 339 00:28:48,500 --> 00:28:53,920 So the password is capital T capital P test password 1. 340 00:28:53,990 --> 00:28:58,030 All right so we have at least one digit and we have at least one upper. 341 00:28:58,040 --> 00:28:59,720 I give it to so we shouldn't have a problem. 342 00:28:59,720 --> 00:28:59,970 No. 343 00:28:59,970 --> 00:29:00,410 All right. 344 00:29:00,470 --> 00:29:04,500 We see that we progressed beyond that checkpoint. 345 00:29:04,550 --> 00:29:11,270 And if we take a quick look in our database just quickly bring it up or solution explore 346 00:29:15,290 --> 00:29:20,590 drill down into our tables into our databases and then into our tables 347 00:29:24,630 --> 00:29:28,270 and we look at the data and is being net users. 348 00:29:28,320 --> 00:29:29,300 And there we have it. 349 00:29:29,310 --> 00:29:35,520 We have the user that was created earlier and it got a very generic birth date because the birth date 350 00:29:35,520 --> 00:29:36,960 field can't be no. 351 00:29:36,960 --> 00:29:40,910 Then we specify that in our database design. 352 00:29:40,920 --> 00:29:42,550 So it's not no. 353 00:29:42,570 --> 00:29:45,180 And so we've got a very generic birth date. 354 00:29:45,180 --> 00:29:51,960 And also we see here that the one we just created actually got the birth date that we put in. 355 00:29:52,020 --> 00:29:52,350 All right. 356 00:29:53,190 --> 00:29:57,900 So those are things that you can do to make sure that you're capturing all of the required fields according 357 00:29:57,900 --> 00:30:05,010 to your context and application and customize the speed on its user identity engine. 358 00:30:05,010 --> 00:30:06,780 All right so thanks for watching guys. 359 00:30:06,780 --> 00:30:08,250 I hope you learned a lot. 360 00:30:08,250 --> 00:30:10,740 Once again if you are unsure about anything. 361 00:30:10,740 --> 00:30:15,490 Drop me a line in the comments and I'll be sure to get back to you as quickly as possible. 362 00:30:15,660 --> 00:30:21,780 And in the next video we'll be looking at how we can go both restricting access to certain parts of 363 00:30:21,780 --> 00:30:22,740 our application.