In this video, I want to show the rules that we have available inside a truck down here.
So how do we do that?
We'll go back to the application.
Stop it right here and we'll have to modify our view model to contain more fields.
So if we go to the definition here was cruel to the very end and will do prop, this will be a enumerable
for the dropdown.
We need a select list item.
We have to add the namespace Microsoft that has been at that MVC dot rendering.
And I'm going to call this roll out of Propp here.
I'll have a string and I'll also have a string for which Google was selected.
So these two properties now will be able to use in the get action method.
So what we can do is we can create a list of selected list item here and on there we will be adding
to items.
First is admin and the later one is user will do control that to add the using statement.
So this is the list item that we can use and we can display a dropdown inside the register Vue.
So right here where we have the registered for your model will actually assign the role list.
So right here we will say overall list is equal to list items.
So with that, we can modify our registered view, will go to The View and we'll have to add a new form
group.
Let me copy and paste.
This will have this world selected.
And then rather than input time, we will need a select type here so we can move the validation and
will have select values as before.
This will be for all selected because that is where we want to store which group was selected.
How do we populate this dropdown?
And that will be inside model dot roll.
Next, we'll give it some bootstrap process for farm control.
If you are using bootstrap five, I believe the class is from select.
Then will that option here give it a class of disabled and selected by default, will just display select
room?
I have not added validations in here, but you can do that if you want.
Next, what we want to do is once we create the account by selecting the role that users should be assigned
that specific role, how do we do that?
That will do inside the account controller registered post action method once the result is succeeded.
That means the user has been created after the user has been created.
We can check if role was selected and if it was admin user in that case will assign admin.
In all the other cases we will assign the role of user so will have an if condition here and we'll say
if model Doctorow's selected does not equal to null and we can add more conditions like that like model
that wrote selected length is greater than zero and model that road selected.
Is equal, equal to Admon, make sure it is case sensitive here, so if you have capitally use that,
if it is Hackman's, we want to assign the user that God created right here to the rule of admin user.
So far that will await and we have user manager.
That is a matter to rule A.
Keep in mind that this is a singular action method.
A plural action method can assign more than one rule to a user when we just want to assign one single
rule right now.
So on the user, we want to assign a rule of admin.
In the aspart, we will assign the role of user.
Since both of these roles have already been created, this should not be an issue.
So we are taking care of everything right here.
But what about if someone logs in using Facebook?
You can add the same conditions there and you can also add dropdown if you want.
But to keep it simple, I just say that external log ends by default, will be assigned to the role
of user.
So we'll scroll down to our external login.
This is the get action method will go to our post action method where we are creating the user right
here.
So once that has been created, we will await underscore user manager trackpad to roll his sink and
we'll be assigning our user the role of user.
Now everything looks good, it will be better if we can display the role of the current Lockton user
to validate everything on our side, that could be done easily as well.
If we go inside at index view inside the home folder, then we can display the role of the logged in
user here.
We can do that by checking here with an if condition and we can check if user that is in role.
If the user has a role of admin, we can display the role right here that your role is admin in the
aspart will display that your role.
Is user, if you prefer more complex logic, we can do all the calculations inside the cat action method,
but I won't go into those details right now.
This is a simple way of checking it, because before this is a condition, we are making sure that only
authenticated users can get in.
So if an authenticated user is not an admin by default, it will be a user because those are the only
two rules that we allow.
Right now.
So perfect, this looks good.
That's why did everything that we see here in the next video.