-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
29,342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.31101.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVC5Course", "MVC5Course\MVC5Course.csproj", "{F05FD365-217D-40BA-B3E2-8FFA108254A0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{F05FD365-217D-40BA-B3E2-8FFA108254A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F05FD365-217D-40BA-B3E2-8FFA108254A0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F05FD365-217D-40BA-B3E2-8FFA108254A0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F05FD365-217D-40BA-B3E2-8FFA108254A0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Web; | ||
using System.Web.Optimization; | ||
|
||
namespace MVC5Course | ||
{ | ||
public class BundleConfig | ||
{ | ||
// 如需「搭配」的詳細資訊,請瀏覽 http://go.microsoft.com/fwlink/?LinkId=301862 | ||
public static void RegisterBundles(BundleCollection bundles) | ||
{ | ||
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( | ||
"~/Scripts/jquery-{version}.js")); | ||
|
||
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( | ||
"~/Scripts/jquery.validate*")); | ||
|
||
// 使用開發版本的 Modernizr 進行開發並學習。然後,當您 | ||
// 準備好實際執行時,請使用 http://modernizr.com 上的建置工具,只選擇您需要的測試。 | ||
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( | ||
"~/Scripts/modernizr-*")); | ||
|
||
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( | ||
"~/Scripts/bootstrap.js", | ||
"~/Scripts/respond.js")); | ||
|
||
bundles.Add(new StyleBundle("~/Content/css").Include( | ||
"~/Content/bootstrap.css", | ||
"~/Content/site.css")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Web; | ||
using System.Web.Mvc; | ||
|
||
namespace MVC5Course | ||
{ | ||
public class FilterConfig | ||
{ | ||
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | ||
{ | ||
filters.Add(new HandleErrorAttribute()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Entity; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using Microsoft.AspNet.Identity; | ||
using Microsoft.AspNet.Identity.EntityFramework; | ||
using Microsoft.AspNet.Identity.Owin; | ||
using Microsoft.Owin; | ||
using Microsoft.Owin.Security; | ||
using MVC5Course.Models; | ||
|
||
namespace MVC5Course | ||
{ | ||
public class EmailService : IIdentityMessageService | ||
{ | ||
public Task SendAsync(IdentityMessage message) | ||
{ | ||
// 將您的電子郵件服務外掛到這裡以傳送電子郵件。 | ||
return Task.FromResult(0); | ||
} | ||
} | ||
|
||
public class SmsService : IIdentityMessageService | ||
{ | ||
public Task SendAsync(IdentityMessage message) | ||
{ | ||
// 將您的 SMS 服務外掛到這裡以傳送簡訊。 | ||
return Task.FromResult(0); | ||
} | ||
} | ||
|
||
// 設定此應用程式中使用的應用程式使用者管理員。UserManager 在 ASP.NET Identity 中定義且由應用程式中使用。 | ||
public class ApplicationUserManager : UserManager<ApplicationUser> | ||
{ | ||
public ApplicationUserManager(IUserStore<ApplicationUser> store) | ||
: base(store) | ||
{ | ||
} | ||
|
||
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) | ||
{ | ||
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>())); | ||
// 設定使用者名稱的驗證邏輯 | ||
manager.UserValidator = new UserValidator<ApplicationUser>(manager) | ||
{ | ||
AllowOnlyAlphanumericUserNames = false, | ||
RequireUniqueEmail = true | ||
}; | ||
|
||
// 設定密碼的驗證邏輯 | ||
manager.PasswordValidator = new PasswordValidator | ||
{ | ||
RequiredLength = 6, | ||
RequireNonLetterOrDigit = true, | ||
RequireDigit = true, | ||
RequireLowercase = true, | ||
RequireUppercase = true, | ||
}; | ||
|
||
// 設定使用者鎖定詳細資料 | ||
manager.UserLockoutEnabledByDefault = true; | ||
manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5); | ||
manager.MaxFailedAccessAttemptsBeforeLockout = 5; | ||
|
||
// 註冊雙因素驗證提供者。此應用程式使用手機和電子郵件接收驗證碼以驗證使用者 | ||
// 您可以撰寫專屬提供者,並將它外掛到這裡。 | ||
manager.RegisterTwoFactorProvider("電話代碼", new PhoneNumberTokenProvider<ApplicationUser> | ||
{ | ||
MessageFormat = "您的安全碼為 {0}" | ||
}); | ||
manager.RegisterTwoFactorProvider("電子郵件代碼", new EmailTokenProvider<ApplicationUser> | ||
{ | ||
Subject = "安全碼", | ||
BodyFormat = "您的安全碼為 {0}" | ||
}); | ||
manager.EmailService = new EmailService(); | ||
manager.SmsService = new SmsService(); | ||
var dataProtectionProvider = options.DataProtectionProvider; | ||
if (dataProtectionProvider != null) | ||
{ | ||
manager.UserTokenProvider = | ||
new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity")); | ||
} | ||
return manager; | ||
} | ||
} | ||
|
||
// 設定在此應用程式中使用的應用程式登入管理員。 | ||
public class ApplicationSignInManager : SignInManager<ApplicationUser, string> | ||
{ | ||
public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager) | ||
: base(userManager, authenticationManager) | ||
{ | ||
} | ||
|
||
public override Task<ClaimsIdentity> CreateUserIdentityAsync(ApplicationUser user) | ||
{ | ||
return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager); | ||
} | ||
|
||
public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context) | ||
{ | ||
return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using System.Web.Routing; | ||
|
||
namespace MVC5Course | ||
{ | ||
public class RouteConfig | ||
{ | ||
public static void RegisterRoutes(RouteCollection routes) | ||
{ | ||
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | ||
|
||
routes.MapRoute( | ||
name: "Default", | ||
url: "{controller}/{action}/{id}", | ||
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using Microsoft.AspNet.Identity; | ||
using Microsoft.AspNet.Identity.Owin; | ||
using Microsoft.Owin; | ||
using Microsoft.Owin.Security.Cookies; | ||
using Microsoft.Owin.Security.Google; | ||
using Owin; | ||
using MVC5Course.Models; | ||
|
||
namespace MVC5Course | ||
{ | ||
public partial class Startup | ||
{ | ||
// 如需設定驗證的詳細資訊,請瀏覽 http://go.microsoft.com/fwlink/?LinkId=301864 | ||
public void ConfigureAuth(IAppBuilder app) | ||
{ | ||
// 設定資料庫內容、使用者管理員和登入管理員,以針對每個要求使用單一執行個體 | ||
app.CreatePerOwinContext(ApplicationDbContext.Create); | ||
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); | ||
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); | ||
|
||
// 讓應用程式使用 Cookie 儲存已登入使用者的資訊 | ||
// 並使用 Cookie 暫時儲存使用者利用協力廠商登入提供者登入的相關資訊; | ||
// 在 Cookie 中設定簽章 | ||
app.UseCookieAuthentication(new CookieAuthenticationOptions | ||
{ | ||
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, | ||
LoginPath = new PathString("/Account/Login"), | ||
Provider = new CookieAuthenticationProvider | ||
{ | ||
// 讓應用程式在使用者登入時驗證安全性戳記。 | ||
// 這是您變更密碼或將外部登入新增至帳戶時所使用的安全性功能。 | ||
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>( | ||
validateInterval: TimeSpan.FromMinutes(30), | ||
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) | ||
} | ||
}); | ||
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); | ||
|
||
// 讓應用程式在雙因素驗證程序中驗證第二個因素時暫時儲存使用者資訊。 | ||
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); | ||
|
||
// 讓應用程式記住第二個登入驗證因素 (例如電話或電子郵件)。 | ||
// 核取此選項之後,將會在用來登入的裝置上記住登入程序期間的第二個驗證步驟。 | ||
// 這類似於登入時的 RememberMe 選項。 | ||
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); | ||
|
||
// 註銷下列各行以啟用利用協力廠商登入提供者登入 | ||
//app.UseMicrosoftAccountAuthentication( | ||
// clientId: "", | ||
// clientSecret: ""); | ||
|
||
//app.UseTwitterAuthentication( | ||
// consumerKey: "", | ||
// consumerSecret: ""); | ||
|
||
//app.UseFacebookAuthentication( | ||
// appId: "", | ||
// appSecret: ""); | ||
|
||
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() | ||
//{ | ||
// ClientId = "", | ||
// ClientSecret = "" | ||
//}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web.Http; | ||
|
||
namespace MVC5Course | ||
{ | ||
public static class WebApiConfig | ||
{ | ||
public static void Register(HttpConfiguration config) | ||
{ | ||
// Web API 設定和服務 | ||
|
||
// Web API 路由 | ||
config.MapHttpAttributeRoutes(); | ||
|
||
config.Routes.MapHttpRoute( | ||
name: "DefaultApi", | ||
routeTemplate: "api/{controller}/{id}", | ||
defaults: new { id = RouteParameter.Optional } | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
body { | ||
padding-top: 50px; | ||
padding-bottom: 20px; | ||
} | ||
|
||
/* Set padding to keep content from hitting the edges */ | ||
.body-content { | ||
padding-left: 15px; | ||
padding-right: 15px; | ||
} | ||
|
||
/* Override the default bootstrap behavior where horizontal description lists | ||
will truncate terms that are too long to fit in the left column | ||
*/ | ||
.dl-horizontal dt { | ||
white-space: normal; | ||
} | ||
|
||
/* Set width on the form input elements since they're 100% wide by default */ | ||
input, | ||
select, | ||
textarea { | ||
max-width: 280px; | ||
} |
Oops, something went wrong.