Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into chap20-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gildedgardenia committed Nov 21, 2022
2 parents 2c48f13 + 5f8a63d commit 4828425
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 130 deletions.
6 changes: 5 additions & 1 deletion src/assignments/tech-jobs-mvc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ In this project, you’ll show that you can:
#. Use Razor syntax to display data within a view.
#. Create new action methods to process form submission.



TechJobs (MVC Edition)
----------------------

Expand Down Expand Up @@ -70,6 +72,8 @@ carefully as you solve each problem.
to finish the rest. First, you'll create a controller method to retrieve search results.
#. Finally, you'll display search results in the view.

Throughout your work, refer to our `demo app <https://csharp-mvc.launchcodetechnicaltraining.org/>`_ as needed to clarify questions about intended application behavior.

Getting Started
----------------

Expand Down Expand Up @@ -353,4 +357,4 @@ Here are some additional challenges, for those willing to take them on:
hyperlinked to a new listing of all jobs with that same value. For example,
if we have a list of jobs with the ``JavaScript`` skill, clicking on a
location value like ``Saint Louis`` will generate a new list with all the
jobs available in that city.
jobs available in that city.
2 changes: 2 additions & 0 deletions src/assignments/tech-jobs-persistent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ you'll need to do the work to connect the project to a database for storing user

Each of the three sections of this assignment will also ask you to demonstrate your SQL skills under an item labelled **SQL TASK**.

As you work through each part, refer to our `demo app <https://techjobs-persistent.launchcodetechnicaltraining.org/>`_ to clarify questions about intended application behavior.

Getting Started
----------------

Expand Down
51 changes: 25 additions & 26 deletions src/chapters/auth/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@ The first place to start with configuring Identity to fit the needs of the proje
Try and code along as you read more about Identity!
This page starts off with the code in the `identity-scaffolding <https://github.com/LaunchCodeEducation/CodingEventsDemo/tree/identity-scaffolding>`__ branch in ``CodingEventsDemo``.
The final code for this page is in the `identity-config <https://github.com/LaunchCodeEducation/CodingEventsDemo/tree/identity-config>`__ branch in ``CodingEventsDemo``.

If you are looking for an additional walkthrough, check out this `article <https://learn.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?source=recommendations&view=aspnetcore-6.0>`__ from Microsoft.

``Startup.cs``
--------------

``ConfigureServices()``
^^^^^^^^^^^^^^^^^^^^^^^

The first place that we may want to customize our settings is at the bottom of ``ConfigureServices()``.
When you were testing out your application, you may have accidentally entered an invalid password.
The validation conditions for a user's password is an example of one of the settings that can be configured here by using a method called ``services.Configure<IdentityOptions>()``.
If we wanted to make the minimum number of characters for our password 10 as opposed to 6, we would do the following.
Now that we are getting to configure our user, let's check out the code in ``ConfigureServices()``.
Earlier you may have added the following:

.. sourcecode:: csharp
:linenos:

services.Configure<IdentityOptions>( options =>
options.Password.RequiredLength = 10
);
services.AddDefaultIdentity<IdentityUser>
(options =>
{
options.SignIn.RequireConfirmedAccount = true;
options.Password.RequireDigit = false;
options.Password.RequiredLength = 10;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = false;
}).AddEntityFrameworkStores<EventDbContext>();

For a full list of the default settings for users' passwords and how we can change those settings, check out the `documentation <https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.identity.passwordoptions?view=aspnetcore-3.1>`__.
This code is dictating the settings for account creation. Right now, for a user to create an account, they have to have the following:

In ``ConfigureServices()``, we can also configure cookie settings, password hashers, user validation requirements, sign in settings and more.
#. They have to click a link to confirm their account.
#. Their password has to be more than 10 characters long.
#. Their password has to include an uppercase letter(s).

``Configure()``
^^^^^^^^^^^^^^^
The following is not true for a user to create an account.

Below ``ConfigureServices()``, you will find ``Configure()``. Inside ``Configure()``, we must make sure we have the following:
#. Their password does not have to include a number.
#. Their password does not have to include a special character such as a question mark.
#. Their password does not have to include lowercase letters.

.. sourcecode:: csharp
:linenos:
These are just some basic requirements that can be changed to suit the needs of your application.
For a full list of the default settings for users' passwords and how we can change those settings, check out the `documentation <https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.identity.passwordoptions?view=aspnetcore-6.0>`__.

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

While we did properly scaffold Identity onto our code base, we need to add the calls to ``UseAuthentication()`` and ``UseAuthorization()``.
Our application uses middleware to relay requests between our application and our database.
By adding the calls to ``UseAuthentication()`` and ``UseAuthorization()``, we are specifying that we now need authentication middleware to handle these requests.
Authentication is not just about ensuring users are signed in. It is about protecting data at every point it passes through to make the application work.
In ``ConfigureServices()``, we can also configure cookie settings, password hashers, user validation requirements, sign in settings and more.

Additional Customizations
-------------------------
Expand All @@ -66,7 +66,6 @@ Here are some examples of what you can do with it.
.. admonition:: Note

If you want to customize user data, it is best to do so when initially scaffolding the app.
Identity has a default user class called ``IdentityUser``.
`IdentityUser <https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.identity.entityframeworkcore.identityuser?view=aspnetcore-1.1>`__ has a number of properties that are important and relevant to storing user data.
However, when you read through the requirements you may notice that you need additional properties, such as the user's first and last name.
If you want to add custom properties, check out this `article <https://docs.microsoft.com/en-us/aspnet/core/security/authentication/add-user-data?view=aspnetcore-5.0&tabs=visual-studio>`__ from Microsoft.
If you want to add custom properties, check out this `article <https://learn.microsoft.com/en-us/aspnet/core/security/authentication/add-user-data?view=aspnetcore-6.0&tabs=visual-studio>`__ from Microsoft.
12 changes: 0 additions & 12 deletions src/chapters/auth/identity-management.rst

This file was deleted.

1 change: 0 additions & 1 deletion src/chapters/auth/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ Authentication
users
configuration
authorization
identity-management
studio

Loading

0 comments on commit 4828425

Please sign in to comment.