added mongodb mvc sample
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
@{
|
||||
ViewData["Title"] = "Confirm Email";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<div>
|
||||
<p>
|
||||
Thank you for confirming your email. Please <a asp-controller="Account" asp-action="Login">Click here to Log in</a>.
|
||||
</p>
|
||||
</div>
|
||||
@@ -0,0 +1,35 @@
|
||||
@model ExternalLoginConfirmationViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<h3>Associate your @ViewData["LoginProvider"] account.</h3>
|
||||
|
||||
<form asp-controller="Account" asp-action="ExternalLoginConfirmation" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<h4>Association Form</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
|
||||
<p class="text-info">
|
||||
You've successfully authenticated with <strong>@ViewData["LoginProvider"]</strong>.
|
||||
Please enter a user name for this site below and click the Register button to finish
|
||||
logging in.
|
||||
</p>
|
||||
<div class="form-group">
|
||||
<label asp-for="Email" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Email" class="form-control" />
|
||||
<span asp-validation-for="Email" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Register</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@{
|
||||
ViewData["Title"] = "Login Failure";
|
||||
}
|
||||
|
||||
<header>
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<p class="text-danger">Unsuccessful login with service.</p>
|
||||
</header>
|
||||
@@ -0,0 +1,31 @@
|
||||
@model ForgotPasswordViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Forgot your password?";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<p>
|
||||
For more information on how to enable reset password please see this <a href="http://go.microsoft.com/fwlink/?LinkID=532713">article</a>.
|
||||
</p>
|
||||
|
||||
@*<form asp-controller="Account" asp-action="ForgotPassword" method="post" class="form-horizontal" role="form">
|
||||
<h4>Enter your email.</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Email" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Email" class="form-control" />
|
||||
<span asp-validation-for="Email" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>*@
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@{
|
||||
ViewData["Title"] = "Forgot Password Confirmation";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<p>
|
||||
Please check your email to reset your password.
|
||||
</p>
|
||||
@@ -0,0 +1,8 @@
|
||||
@{
|
||||
ViewData["Title"] = "Locked out";
|
||||
}
|
||||
|
||||
<header>
|
||||
<h1 class="text-danger">Locked out.</h1>
|
||||
<p class="text-danger">This account has been locked out, please try again later.</p>
|
||||
</header>
|
||||
@@ -0,0 +1,93 @@
|
||||
@using System.Collections.Generic
|
||||
@using Microsoft.AspNetCore.Http
|
||||
@using Microsoft.AspNetCore.Authentication
|
||||
@model LoginViewModel
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Log in";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<section>
|
||||
<form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<h4>Use a local account to log in.</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Email" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Email" class="form-control" />
|
||||
<span asp-validation-for="Email" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Password" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Password" class="form-control" />
|
||||
<span asp-validation-for="Password" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<div class="checkbox">
|
||||
<label asp-for="RememberMe">
|
||||
<input asp-for="RememberMe" />
|
||||
@Html.DisplayNameFor(m => m.RememberMe)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Log in</button>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<a asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]">Register as a new user?</a>
|
||||
</p>
|
||||
<p>
|
||||
<a asp-action="ForgotPassword">Forgot your password?</a>
|
||||
</p>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<section>
|
||||
<h4>Use another service to log in.</h4>
|
||||
<hr />
|
||||
@{
|
||||
var schemes = await SignInManager.GetExternalAuthenticationSchemesAsync();
|
||||
var loginProviders = schemes.ToList();
|
||||
if (loginProviders.Count == 0)
|
||||
{
|
||||
<div>
|
||||
<p>
|
||||
There are no external authentication services configured. See <a href="http://go.microsoft.com/fwlink/?LinkID=532715">this article</a>
|
||||
for details on setting up this ASP.NET application to support logging in via external services.
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form asp-controller="Account" asp-action="ExternalLogin" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<div>
|
||||
<p>
|
||||
@foreach (var provider in loginProviders)
|
||||
{
|
||||
<button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.Name account">@provider.Name</button>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
@model RegisterViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Account" asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<h4>Create a new account.</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Email" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Email" class="form-control" />
|
||||
<span asp-validation-for="Email" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Password" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Password" class="form-control" />
|
||||
<span asp-validation-for="Password" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="ConfirmPassword" class="form-control" />
|
||||
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Register</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
@model ResetPasswordViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Reset password";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Account" asp-action="ResetPassword" method="post" class="form-horizontal" role="form">
|
||||
<h4>Reset your password.</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<input asp-for="Code" type="hidden" />
|
||||
<div class="form-group">
|
||||
<label asp-for="Email" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Email" class="form-control" />
|
||||
<span asp-validation-for="Email" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Password" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Password" class="form-control" />
|
||||
<span asp-validation-for="Password" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="ConfirmPassword" class="form-control" />
|
||||
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Reset</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@{
|
||||
ViewData["Title"] = "Reset password confirmation";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"].</h1>
|
||||
<p>
|
||||
Your password has been reset. Please <a asp-controller="Account" asp-action="Login">Click here to log in</a>.
|
||||
</p>
|
||||
@@ -0,0 +1,21 @@
|
||||
@model SendCodeViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Send Verification Code";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Account" asp-action="SendCode" asp-route-returnurl="@Model.ReturnUrl" method="post" class="form-horizontal" role="form">
|
||||
<input asp-for="RememberMe" type="hidden" />
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
Select Two-Factor Authentication Provider:
|
||||
<select asp-for="SelectedProvider" asp-items="Model.Providers"></select>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
@model UseRecoveryCodeViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Use recovery code";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Account" asp-action="UseRecoveryCode" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<h4>@ViewData["Status"]</h4>
|
||||
<hr />
|
||||
<div class="form-group">
|
||||
<label asp-for="Code" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Code" class="form-control" />
|
||||
<span asp-validation-for="Code" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
@model VerifyAuthenticatorCodeViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Verify";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Account" asp-action="VerifyAuthenticatorCode" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<input asp-for="RememberMe" type="hidden" />
|
||||
<h4>@ViewData["Status"]</h4>
|
||||
<hr />
|
||||
<div class="form-group">
|
||||
<label asp-for="Code" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Code" class="form-control" />
|
||||
<span asp-validation-for="Code" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<div class="checkbox">
|
||||
<input asp-for="RememberBrowser" />
|
||||
<label asp-for="RememberBrowser"></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<a asp-action="UseRecoveryCode">Lost your authenticator?</a>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
@model VerifyCodeViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Verify";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Account" asp-action="VerifyCode" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<input asp-for="Provider" type="hidden" />
|
||||
<input asp-for="RememberMe" type="hidden" />
|
||||
<h4>@ViewData["Status"]</h4>
|
||||
<hr />
|
||||
<div class="form-group">
|
||||
<label asp-for="Code" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Code" class="form-control" />
|
||||
<span asp-validation-for="Code" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<div class="checkbox">
|
||||
<input asp-for="RememberBrowser" />
|
||||
<label asp-for="RememberBrowser"></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
@{
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Home Page";
|
||||
}
|
||||
|
||||
<div class="jumbotron">
|
||||
<h1>ASP.NET Identity</h1>
|
||||
<p class="lead">ASP.NET Identity is the membership system for ASP.NET apps. Following are the features of ASP.NET Identity in this sample application.</p>
|
||||
<p><a href="http://www.asp.net/identity" class="btn btn-primary btn-large">Learn more »</a></p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Initialize ASP.NET Identity</dt>
|
||||
<dd>
|
||||
You can initialize ASP.NET Identity when the application starts. Since ASP.NET Identity is Entity Framework based in this sample,
|
||||
you can create DatabaseInitializer which is configured to get called each time the app starts.
|
||||
<strong>Please look in App_Start\IdentityConfig.cs</strong>
|
||||
This code shows the following
|
||||
<ul>
|
||||
<li>When should the Initializer run and when should the database be created</li>
|
||||
<li>Create Admin user</li>
|
||||
<li>Create Admin role</li>
|
||||
<li>Add Admin user to Admin role</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Add profile data for the user</dt>
|
||||
<dd>
|
||||
<a href="http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx">Please follow this tutorial.</a>
|
||||
|
||||
<ul>
|
||||
<li>Add profile information in the Users Table</li>
|
||||
<li>Look in Models\IdentityModels.cs for examples</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Validation</dt>
|
||||
<dd>
|
||||
When you create a User using a username or password, the Identity system performs validation on the username and password, and the passwords are hashed before they are
|
||||
stored in the database. You can customize the validation by changing some of the properties of the validators such as Turn alphanumeric on/off, set minimum password length
|
||||
or you can write your own custom validators and register them with the UserManager.
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Register a user and login</dt>
|
||||
<dd>
|
||||
Click @Html.ActionLink("Register", "Register", "Account") and see the code in AccountController.cs and Register Action.
|
||||
Click @Html.ActionLink("Log in", "Login", "Account") and see the code in AccountController.cs and Login Action.
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Social Logins</dt>
|
||||
<dd>
|
||||
You can the support so that users can login using their Facebook, Google, Twitter, Microsoft Account and more.
|
||||
</dd>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="http://www.windowsazure.com/en-us/documentation/articles/web-sites-dotnet-deploy-aspnet-mvc-app-membership-oauth-sql-database/">Add Social Logins</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://blogs.msdn.com/b/webdev/archive/2013/10/16/get-more-information-from-social-providers-used-in-the-vs-2013-project-templates.aspx">Get more data about the user when they log in using Facebook</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Basic User Management</dt>
|
||||
<dd>
|
||||
Do Create, Update, List and Delete Users.
|
||||
Assign a Role to a User.
|
||||
Only Users In Role Admin can access this page. This uses the [Authorize(Roles = "Admin")] on the UserAdmin controller.
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Basic Role Management</dt>
|
||||
<dd>
|
||||
Do Create, Update, List and Delete Roles.
|
||||
Only Users In Role Admin can access this page. This authorization is done by using the [Authorize(Roles = "Admin")] on the RolesAdmin controller.
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Account Confirmation</dt>
|
||||
<dd>
|
||||
When you register a new account, you will be sent an email confirmation.
|
||||
You can use an email service such as <a href="http://www.windowsazure.com/en-us/documentation/articles/sendgrid-dotnet-how-to-send-email/">SendGrid</a> which integrates nicely with Windows Azure and requires no configuration or
|
||||
set up an SMTP server to send email.
|
||||
You can send email using the EmailService which is registered in App_Start\IdentityConfig.cs
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Two-Factor Authentication</dt>
|
||||
<dd>
|
||||
This sample shows how you can use Two-Factor authentication. This sample has a SMS and email service registered where you can send SMS or email for sending the security code.
|
||||
You can add more two-factor authentication factors such as QR codes and plug them into ASP.NET Identity.
|
||||
<ul>
|
||||
<li>
|
||||
You can use a SMS using <a href="https://www.twilio.com/">Twilio</a> or use any means of sending SMS. Please <a href="https://www.twilio.com/docs/quickstart/csharp/sms/sending-via-rest">read</a> for more details on using Twilio.
|
||||
You can send SMS using the SmsService which is registered in App_Start\IdentityConfig.cs
|
||||
</li>
|
||||
<li>
|
||||
You can use an email service such as <a href="http://www.windowsazure.com/en-us/documentation/articles/sendgrid-dotnet-how-to-send-email/">SendGrid</a> or
|
||||
set up an SMTP server to send email.
|
||||
You can send email using the EmailService which is registered in App_Start\IdentityConfig.cs
|
||||
</li>
|
||||
|
||||
<li>
|
||||
When you login, you can add a phone number by clicking the Manage page.
|
||||
</li>
|
||||
<li>
|
||||
Once you add a phone number and have the Phone service hooked to send a SMS, you will get a code through SMS to confirm your phone number.
|
||||
</li>
|
||||
<li>
|
||||
In the Manage page, you can turn on Two-Factor authentication.
|
||||
</li>
|
||||
<li>
|
||||
When you logout and login, after you enter the username and password, you will get an option of how to get the security code to use for two-factor authentication.
|
||||
</li>
|
||||
<li>
|
||||
You can copy the code from your SMS or email and enter in the form to login.
|
||||
</li>
|
||||
<li>
|
||||
The sample also shows how to protect against Brute force attacks against two-factor codes. When you enter a code incorrectly for 5 times then you will be
|
||||
lockedout for 5 min before you can enter a new code. These settings can be configured in App_Start\IdentityConfig.cs by setting DefaultAccountLockoutTimeSpan and MaxFailedAccessAttemptsBeforeLockout on the UserManager.
|
||||
</li>
|
||||
<li>
|
||||
If the machine you are browsing this website is your own machine, you can choose to check the "Remember Me" option after you enter the code.
|
||||
This option will remember you forever on this machine and will not ask you for the two-factor authentication, the next time when you login to the website.
|
||||
You can change your "Remember Me" settings for two-factor authentication in the Manage page.
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Account Lockout</dt>
|
||||
<dd>
|
||||
Provide a way to Lockout out the user if the user enters their password or two-factor codes incorrectly.
|
||||
The number of invalid attempts and the timespan for the users are locked out can be configured.
|
||||
A developer can optionally turn off Account Lockout for certain user accounts should they need to.
|
||||
</dd>
|
||||
<ul>
|
||||
<li>Account LockOut settings can be configured in the UserManager in IdentityConfig.cs</li>
|
||||
</ul>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Security Token provider</dt>
|
||||
<dd>
|
||||
Support a way to regenerate the Security Token for the user in cases when the User changes there password or any other security related information such as removing an associated login(such as Facebook, Google, Microsoft Account etc).
|
||||
This is needed to ensure that any tokens generated with the old password are invalidated. In the sample project, if you change the users password then a new token is generated for the user and any previous tokens are invalidated.
|
||||
This feature provides an extra layer of security to your application since when you change your password, you will be logged out from everywhere (all other browsers) where you have logged into this application.
|
||||
</dd>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>The provider is registered when you add CookieAuthentication in StartupAuth to your application.</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Password Reset</dt>
|
||||
<dd>
|
||||
Allows the user to reset their passwords if they have forgotten their password. In this sample users need to confirm their email before they can reset their passwords.
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Custom Storage providers</dt>
|
||||
<dd>
|
||||
You can extend ASP.NET Identity to write your own custom storage provider for storing the ASP.NET Identity system and user data
|
||||
in a persistance system of your choice such as MondoDb, RavenDb, Azure Table Storage etc.
|
||||
</dd>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="http://www.asp.net/identity/overview/extensibility/overview-of-custom-storage-providers-for-aspnet-identity">
|
||||
learn more on how to implement your own storage provider
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<dl>
|
||||
<dt>Documentation</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>
|
||||
Tutorials: <a href="www.asp.net/identity">www.asp.net/identity</a>
|
||||
</li>
|
||||
<li>
|
||||
StackOverflow: <a href="http://stackoverflow.com/questions/tagged/asp.net-identity">http://stackoverflow.com/questions/tagged/asp.net-identity</a>
|
||||
</li>
|
||||
<li>
|
||||
Twitter: #identity #aspnet
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://curah.microsoft.com/55636/aspnet-identity">ASP.NET Identity on curah</a>
|
||||
</li>
|
||||
<li>
|
||||
Have bugs or suggestions for ASP.NET Identity <a href="http://aspnetidentity.codeplex.com/">http://aspnetidentity.codeplex.com/</a>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,27 @@
|
||||
@model AddPhoneNumberViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Add Phone Number";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<form asp-controller="Manage" asp-action="AddPhoneNumber" method="post" class="form-horizontal" role="form">
|
||||
<h4>Add a phone number.</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="PhoneNumber" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="PhoneNumber" class="form-control" />
|
||||
<span asp-validation-for="PhoneNumber" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Send verification code</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
@model ChangePasswordViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Change Password";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Manage" asp-action="ChangePassword" method="post" class="form-horizontal" role="form">
|
||||
<h4>Change Password Form</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="OldPassword" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="OldPassword" class="form-control" />
|
||||
<span asp-validation-for="OldPassword" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="NewPassword" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="NewPassword" class="form-control" />
|
||||
<span asp-validation-for="NewPassword" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="ConfirmPassword" class="form-control" />
|
||||
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Change password</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
@model DisplayRecoveryCodesViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Your recovery codes:";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<p class="text-success">@ViewData["StatusMessage"]</p>
|
||||
|
||||
<div>
|
||||
<h4>Here are your new recovery codes</h4>
|
||||
<hr />
|
||||
<dl class="dl-horizontal">
|
||||
<dt>Codes:</dt>
|
||||
@foreach (var code in Model.Codes)
|
||||
{
|
||||
<dd>
|
||||
<text>@code</text>
|
||||
</dd>
|
||||
}
|
||||
</dl>
|
||||
</div>
|
||||
@@ -0,0 +1,86 @@
|
||||
@model IndexViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Manage your account";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<p class="text-success">@ViewData["StatusMessage"]</p>
|
||||
|
||||
<div>
|
||||
<h4>Change your account settings</h4>
|
||||
<hr />
|
||||
<dl class="dl-horizontal">
|
||||
<dt>Password:</dt>
|
||||
<dd>
|
||||
@if (Model.HasPassword)
|
||||
{
|
||||
<text>[ <a asp-controller="Manage" asp-action="ChangePassword">Change</a> ]</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>[ <a asp-controller="Manage" asp-action="SetPassword">Create</a> ]</text>
|
||||
}
|
||||
</dd>
|
||||
<dt>External Logins:</dt>
|
||||
<dd>
|
||||
@Model.Logins.Count [ <a asp-controller="Manage" asp-action="ManageLogins">Manage</a> ]
|
||||
</dd>
|
||||
<dt>Phone Number:</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Phone Numbers can used as a second factor of verification in two-factor authentication.
|
||||
See <a href="http://go.microsoft.com/fwlink/?LinkID=532713">this article</a>
|
||||
for details on setting up this ASP.NET application to support two-factor authentication using SMS.
|
||||
</p>
|
||||
@(Model.PhoneNumber ?? "None")
|
||||
@if (Model.PhoneNumber != null)
|
||||
{
|
||||
<br />
|
||||
<text>[ <a asp-controller="Manage" asp-action="AddPhoneNumber">Change</a> ]</text>
|
||||
<form asp-controller="Manage" asp-action="RemovePhoneNumber" method="post" role="form">
|
||||
[<button type="submit" class="btn-link">Remove</button>]
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>[ <a asp-controller="Manage" asp-action="AddPhoneNumber">Add</a> ]</text>
|
||||
}
|
||||
</dd>
|
||||
|
||||
<dt>Two-Factor Authentication:</dt>
|
||||
<dd>
|
||||
<!--<p>
|
||||
There are no two-factor authentication providers configured. See <a href="http://go.microsoft.com/fwlink/?LinkID=532713">this article</a>
|
||||
for setting up this application to support two-factor authentication.
|
||||
</p>-->
|
||||
@if (Model.TwoFactor)
|
||||
{
|
||||
<form asp-controller="Manage" asp-action="DisableTwoFactorAuthentication" method="post" class="form-horizontal" role="form">
|
||||
Enabled [<button type="submit" class="btn-link">Disable</button>]
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form asp-controller="Manage" asp-action="EnableTwoFactorAuthentication" method="post" class="form-horizontal" role="form">
|
||||
[<button type="submit" class="btn-link">Enable</button>] Disabled
|
||||
</form>
|
||||
}
|
||||
</dd>
|
||||
<dt>Authentication App:</dt>
|
||||
<dd>
|
||||
@if (Model.AuthenticatorKey == null)
|
||||
{
|
||||
<form asp-controller="Manage" asp-action="ResetAuthenticatorKey" method="post" class="form-horizontal" role="form">
|
||||
Generate [<button type="submit" class="btn-link">Generate</button>]
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>Your key is: @Model.AuthenticatorKey</text>
|
||||
<form asp-controller="Manage" asp-action="GenerateRecoveryCode" method="post" class="form-horizontal" role="form">
|
||||
Generate [<button type="submit" class="btn-link">Generate new recovery codes</button>]
|
||||
</form>
|
||||
}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
@@ -0,0 +1,54 @@
|
||||
@model ManageLoginsViewModel
|
||||
@using Microsoft.AspNetCore.Authentication
|
||||
@{
|
||||
ViewData["Title"] = "Manage your external logins";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<p class="text-success">@ViewData["StatusMessage"]</p>
|
||||
@if (Model.CurrentLogins.Count > 0)
|
||||
{
|
||||
<h4>Registered Logins</h4>
|
||||
<table class="table">
|
||||
<tbody>
|
||||
@for (var index = 0; index < Model.CurrentLogins.Count; index++)
|
||||
{
|
||||
<tr>
|
||||
<td>@Model.CurrentLogins[index].LoginProvider</td>
|
||||
<td>
|
||||
@if ((bool)ViewData["ShowRemoveButton"])
|
||||
{
|
||||
<form asp-controller="Manage" asp-action="RemoveLogin" method="post" class="form-horizontal" role="form">
|
||||
<div>
|
||||
<input asp-for="@Model.CurrentLogins[index].LoginProvider" name="LoginProvider" type="hidden"/>
|
||||
<input asp-for="@Model.CurrentLogins[index].ProviderKey" name="ProviderKey" type="hidden"/>
|
||||
<input type="submit" class="btn btn-default" value="Remove" title="Remove this @Model.CurrentLogins[index].LoginProvider login from your account" />
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
@:
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
@if (Model.OtherLogins.Count > 0)
|
||||
{
|
||||
<h4>Add another service to log in.</h4>
|
||||
<hr />
|
||||
<form asp-controller="Manage" asp-action="LinkLogin" method="post" class="form-horizontal" role="form">
|
||||
<div id="socialLoginList">
|
||||
<p>
|
||||
@foreach (var provider in Model.OtherLogins)
|
||||
{
|
||||
<button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.Name account">@provider.DisplayName</button>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
@model SetPasswordViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Set Password";
|
||||
}
|
||||
|
||||
<p class="text-info">
|
||||
You do not have a local username/password for this site. Add a local
|
||||
account so you can log in without an external login.
|
||||
</p>
|
||||
|
||||
<form asp-controller="Manage" asp-action="SetPassword" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<h4>Set your password</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="NewPassword" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="NewPassword" class="form-control" />
|
||||
<span asp-validation-for="NewPassword" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="ConfirmPassword" class="form-control" />
|
||||
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Set password</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
@model VerifyPhoneNumberViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Verify Phone Number";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Manage" asp-action="VerifyPhoneNumber" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
|
||||
<input asp-for="PhoneNumber" type="hidden" />
|
||||
<h4>Add a phone number.</h4>
|
||||
<h5>@ViewData["Status"]</h5>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Code" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Code" class="form-control" />
|
||||
<span asp-validation-for="Code" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - Identity Sample</title>
|
||||
<link rel="stylesheet" href="//ajax.aspnetcdn.com/ajax/bootstrap/3.3.5/css/bootstrap.min.css"></link>
|
||||
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a asp-controller="Home" asp-action="Index" class="navbar-brand">Identity Sample</a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a asp-controller="Home" asp-action="Index">Home</a></li>
|
||||
</ul>
|
||||
@await Html.PartialAsync("_LoginPartial")
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container body-content">
|
||||
@RenderBody()
|
||||
<hr />
|
||||
<footer>
|
||||
<p>© 2016 - IdentitySample</p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="//ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script>
|
||||
<script src="//ajax.aspnetcdn.com/ajax/bootstrap/3.3.5/bootstrap.min.js"></script>
|
||||
<script src="~/js/site.min.js" asp-append-version="true"></script>
|
||||
|
||||
@RenderSection("scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,26 @@
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using MongoIdentitySample.Mvc.Models
|
||||
|
||||
@inject SignInManager<ApplicationUser> SignInManager
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
|
||||
@if (SignInManager.IsSignedIn(User))
|
||||
{
|
||||
<form asp-controller="Account" asp-action="LogOff" method="post" id="logoutForm" class="navbar-right">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
<a asp-controller="Manage" asp-action="Index" title="Manage">Hello @UserManager.GetUserName(User)!</a>
|
||||
</li>
|
||||
<li>
|
||||
<button type="submit" class="btn btn-link navbar-btn navbar-link">Log off</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li><a asp-controller="Account" asp-action="Register">Register</a></li>
|
||||
<li><a asp-controller="Account" asp-action="Login">Log in</a></li>
|
||||
</ul>
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"></script>
|
||||
<script src="//ajax.aspnetcdn.com/ajax/mvc/5.2.3/jquery.validate.unobtrusive.min.js"></script>
|
||||
@@ -0,0 +1,6 @@
|
||||
@using MongoIdentitySample.Mvc
|
||||
@using MongoIdentitySample.Mvc.Models
|
||||
@using MongoIdentitySample.Mvc.Models.AccountViewModels
|
||||
@using MongoIdentitySample.Mvc.Models.ManageViewModels
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
Reference in New Issue
Block a user