summaryrefslogtreecommitdiff
path: root/Project-Unite/App_Start
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-03-20 16:45:17 -0400
committerMichael <[email protected]>2017-03-20 16:45:17 -0400
commitcdc61eb4ea5309769ad4db84d92594e4dc3dff67 (patch)
treea8297a7aecc4376f07a497a5e02ab5ff165bfbd3 /Project-Unite/App_Start
parentd9f475e1f33bbf39ca0d79d7a6b0c2fd501b4f2d (diff)
downloadproject-unite-cdc61eb4ea5309769ad4db84d92594e4dc3dff67.tar.gz
project-unite-cdc61eb4ea5309769ad4db84d92594e4dc3dff67.tar.bz2
project-unite-cdc61eb4ea5309769ad4db84d92594e4dc3dff67.zip
Initial commit (azure deploy test)
Diffstat (limited to 'Project-Unite/App_Start')
-rw-r--r--Project-Unite/App_Start/BundleConfig.cs31
-rw-r--r--Project-Unite/App_Start/FilterConfig.cs14
-rw-r--r--Project-Unite/App_Start/IdentityConfig.cs124
-rw-r--r--Project-Unite/App_Start/RouteConfig.cs23
-rw-r--r--Project-Unite/App_Start/Startup.Auth.cs70
5 files changed, 262 insertions, 0 deletions
diff --git a/Project-Unite/App_Start/BundleConfig.cs b/Project-Unite/App_Start/BundleConfig.cs
new file mode 100644
index 0000000..b0ec54b
--- /dev/null
+++ b/Project-Unite/App_Start/BundleConfig.cs
@@ -0,0 +1,31 @@
+using System.Web;
+using System.Web.Optimization;
+
+namespace Project_Unite
+{
+ public class BundleConfig
+ {
+ // For more information on bundling, visit 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*"));
+
+ // Use the development version of Modernizr to develop with and learn from. Then, when you're
+ // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
+ 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"));
+ }
+ }
+}
diff --git a/Project-Unite/App_Start/FilterConfig.cs b/Project-Unite/App_Start/FilterConfig.cs
new file mode 100644
index 0000000..220151d
--- /dev/null
+++ b/Project-Unite/App_Start/FilterConfig.cs
@@ -0,0 +1,14 @@
+using System.Web;
+using System.Web.Mvc;
+
+namespace Project_Unite
+{
+ public class FilterConfig
+ {
+ public static void RegisterGlobalFilters(GlobalFilterCollection filters)
+ {
+ filters.Add(new HandleErrorAttribute());
+
+ }
+ }
+}
diff --git a/Project-Unite/App_Start/IdentityConfig.cs b/Project-Unite/App_Start/IdentityConfig.cs
new file mode 100644
index 0000000..848daba
--- /dev/null
+++ b/Project-Unite/App_Start/IdentityConfig.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.Data.Entity;
+using System.Linq;
+using System.Net;
+using System.Net.Mail;
+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 Project_Unite.Models;
+
+namespace Project_Unite
+{
+ public class EmailService : IIdentityMessageService
+ {
+ public Task SendAsync(IdentityMessage message)
+ {
+ var smtp = new SmtpClient("in-v3.mailjet.com", 25);
+ smtp.UseDefaultCredentials = false;
+ smtp.Credentials = new NetworkCredential("fcc885a166c73e91ba6592345f64dfeb", "84b7c56e71b6c9bd1b26a98222494823");
+ var sMsg = new MailMessage("[email protected]", message.Destination);
+
+ sMsg.Body = @"<img src=""https://cdn.discordapp.com/attachments/241613675545231360/280020406528901131/unknown.png""/>
+
+<h1>Message from the ShiftOS staff</h1>
+
+<p>" + CommonMark.CommonMarkConverter.Convert(message.Body) + "</p>";
+ sMsg.Subject = "[ShiftOS (Project: Unite)] " + message.Subject;
+ sMsg.IsBodyHtml = true;
+ smtp.Send(sMsg);
+
+ return Task.FromResult(0);
+ }
+ }
+
+ public class SmsService : IIdentityMessageService
+ {
+ public Task SendAsync(IdentityMessage message)
+ {
+ // Plug in your SMS service here to send a text message.
+ return Task.FromResult(0);
+ }
+ }
+
+ // Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.
+ 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>()));
+ // Configure validation logic for usernames
+ manager.UserValidator = new UserValidator<ApplicationUser>(manager)
+ {
+ AllowOnlyAlphanumericUserNames = false,
+ RequireUniqueEmail = true
+ };
+
+ // Configure validation logic for passwords
+ manager.PasswordValidator = new PasswordValidator
+ {
+ RequiredLength = 6,
+ RequireNonLetterOrDigit = false,
+ RequireDigit = true,
+ RequireLowercase = true,
+ RequireUppercase = false,
+ };
+
+ // Configure user lockout defaults
+ manager.UserLockoutEnabledByDefault = true;
+ manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
+ manager.MaxFailedAccessAttemptsBeforeLockout = 5;
+
+ // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
+ // You can write your own provider and plug it in here.
+ manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider<ApplicationUser>
+ {
+ MessageFormat = "Your security code is {0}"
+ });
+ manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<ApplicationUser>
+ {
+ Subject = "Security Code",
+ BodyFormat = "Your security code is {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;
+ }
+ }
+
+ // Configure the application sign-in manager which is used in this application.
+ 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);
+ }
+ }
+}
diff --git a/Project-Unite/App_Start/RouteConfig.cs b/Project-Unite/App_Start/RouteConfig.cs
new file mode 100644
index 0000000..2fc4239
--- /dev/null
+++ b/Project-Unite/App_Start/RouteConfig.cs
@@ -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 Project_Unite
+{
+ 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 }
+ );
+ }
+ }
+}
diff --git a/Project-Unite/App_Start/Startup.Auth.cs b/Project-Unite/App_Start/Startup.Auth.cs
new file mode 100644
index 0000000..5bd6820
--- /dev/null
+++ b/Project-Unite/App_Start/Startup.Auth.cs
@@ -0,0 +1,70 @@
+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 Project_Unite.Models;
+
+namespace Project_Unite
+{
+ public partial class Startup
+ {
+ // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
+ public void ConfigureAuth(IAppBuilder app)
+ {
+ // Configure the db context, user manager and signin manager to use a single instance per request
+ app.CreatePerOwinContext(ApplicationDbContext.Create);
+ app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
+ app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
+
+ // Enable the application to use a cookie to store information for the signed in user
+ // and to use a cookie to temporarily store information about a user logging in with a third party login provider
+ // Configure the sign in cookie
+ app.UseCookieAuthentication(new CookieAuthenticationOptions
+ {
+ AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
+ LoginPath = new PathString("/Account/Login"),
+ Provider = new CookieAuthenticationProvider
+ {
+ // Enables the application to validate the security stamp when the user logs in.
+ // This is a security feature which is used when you change a password or add an external login to your account.
+ OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
+ validateInterval: TimeSpan.FromMinutes(30),
+ regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
+ }
+ });
+ app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
+
+ // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
+ app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
+
+ // Enables the application to remember the second login verification factor such as phone or email.
+ // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
+ // This is similar to the RememberMe option when you log in.
+ app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
+
+ // Uncomment the following lines to enable logging in with third party login providers
+ //app.UseMicrosoftAccountAuthentication(
+ // clientId: "",
+ // clientSecret: "");
+
+ //app.UseTwitterAuthentication(
+ // consumerKey: "",
+ // consumerSecret: "");
+
+ //app.UseFacebookAuthentication(
+ // appId: "",
+ // appSecret: "");
+
+ app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
+ {
+ ClientId = "433137899460-02t7aruq56lddf8hckpgad44rhjc4h7d.apps.googleusercontent.com",
+ ClientSecret = "1TnTKaWFoflG0DFQSrqjUjXP"
+ });
+
+
+ }
+ }
+} \ No newline at end of file