Browse Source
Moved Models and ViewModels into their respective Areas. Added Groups/Roles to models.pull/29/head
29 changed files with 337 additions and 220 deletions
@ -1,7 +1,8 @@
@@ -1,7 +1,8 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using Teknik.Areas.Profile.Models; |
||||
|
||||
namespace Teknik.Models |
||||
namespace Teknik.Areas.Blog.Models |
||||
{ |
||||
public class Blog |
||||
{ |
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Web; |
||||
using System.Web.Mvc; |
||||
using System.Web.Security; |
||||
using Teknik.Areas.Profile.ViewModels; |
||||
using Teknik.Controllers; |
||||
using Teknik.Models; |
||||
using Teknik.ViewModels; |
||||
|
||||
namespace Teknik.Areas.Profile.Controllers |
||||
{ |
||||
public class ProfileController : DefaultController |
||||
{ |
||||
private TeknikEntities db = new TeknikEntities(); |
||||
|
||||
// GET: Profile/Profile
|
||||
public ActionResult Index() |
||||
{ |
||||
ViewBag.Title = Config.Title + " - Profile"; |
||||
ViewBag.Message = "View Your Profile"; |
||||
|
||||
return View(); |
||||
} |
||||
|
||||
[HttpGet] |
||||
[AllowAnonymous] |
||||
// GET: Profile
|
||||
public ActionResult Login() |
||||
{ |
||||
return View(); |
||||
} |
||||
|
||||
[HttpPost] |
||||
[AllowAnonymous] |
||||
public ActionResult Login(LoginViewModel model) |
||||
{ |
||||
if (ModelState.IsValid) |
||||
{ |
||||
if (model.IsValid()) |
||||
{ |
||||
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe); |
||||
return Json(new { result = "true" }); |
||||
} |
||||
} |
||||
return Json(new { error = "Invalid User name or Password." }); |
||||
} |
||||
|
||||
public ActionResult Logout() |
||||
{ |
||||
FormsAuthentication.SignOut(); |
||||
return RedirectToAction("Index", "Home", new { Area = "Home" }); |
||||
} |
||||
|
||||
[HttpPost] |
||||
[AllowAnonymous] |
||||
public ActionResult Register(RegisterViewModel model) |
||||
{ |
||||
if (ModelState.IsValid) |
||||
{ |
||||
var foundUser = db.Users.Where(b => b.Username == model.Username); |
||||
if (foundUser.Any()) |
||||
{ |
||||
return Json(new { error = "That username already exists." }); |
||||
} |
||||
if (model.Password != model.ConfirmPassword) |
||||
{ |
||||
return Json(new { error = "Passwords must match." }); |
||||
} |
||||
if (model.Insert()) |
||||
{ |
||||
return RedirectToAction("Login", "Profile", new LoginViewModel { Username = model.Username, Password = model.Password }); |
||||
} |
||||
return Json(new { error = "You must include all fields." }); |
||||
} |
||||
return Json(new { error = "You must include all fields." }); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
using Microsoft.AspNet.Identity.EntityFramework; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.Areas.Profile.Models |
||||
{ |
||||
public class AuthUser : IdentityUser |
||||
{ |
||||
public User User { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.Areas.Profile.Models |
||||
{ |
||||
public class Group |
||||
{ |
||||
public int GroupId { get; set; } |
||||
|
||||
public string Name { get; set; } |
||||
|
||||
public string Description { get; set; } |
||||
|
||||
public List<Role> Roles { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.Areas.Profile.Models |
||||
{ |
||||
public enum PermissionTarget |
||||
{ |
||||
Blog, |
||||
User, |
||||
Profile |
||||
} |
||||
} |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.Areas.Profile.Models |
||||
{ |
||||
public enum PermissionType |
||||
{ |
||||
Add, |
||||
Edit, |
||||
Delete |
||||
} |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.Areas.Profile.Models |
||||
{ |
||||
public class Role |
||||
{ |
||||
public int RoleId { get; set; } |
||||
|
||||
public string Name { get; set; } |
||||
|
||||
public string Description { get; set; } |
||||
|
||||
public PermissionType Permission { get; set; } |
||||
|
||||
public PermissionTarget Target { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.Areas.Profile.Models |
||||
{ |
||||
public class UserIdentity : User |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
using System.Web.Mvc; |
||||
|
||||
namespace Teknik.Areas.Profile |
||||
{ |
||||
public class ProfileAreaRegistration : AreaRegistration |
||||
{ |
||||
public override string AreaName |
||||
{ |
||||
get |
||||
{ |
||||
return "Profile"; |
||||
} |
||||
} |
||||
|
||||
public override void RegisterArea(AreaRegistrationContext context) |
||||
{ |
||||
context.MapSubdomainRoute( |
||||
"Profile_dev", // Route name
|
||||
"dev", |
||||
"Profile/{controller}/{action}", // URL with parameters
|
||||
new { controller = "Profile", action = "Index" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ProfileController).Namespace } |
||||
); |
||||
context.MapSubdomainRoute( |
||||
"Profile_default", // Route name
|
||||
"profile", |
||||
"{controller}/{action}", // URL with parameters
|
||||
new { controller = "Profile", action = "Index" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ProfileController).Namespace } |
||||
); |
||||
} |
||||
} |
||||
} |
@ -1,9 +1,10 @@
@@ -1,9 +1,10 @@
|
||||
using System; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using Teknik.Areas.Profile.Models; |
||||
using Teknik.Helpers; |
||||
using Teknik.Models; |
||||
|
||||
namespace Teknik.ViewModels |
||||
namespace Teknik.Areas.Profile.ViewModels |
||||
{ |
||||
public class RegisterViewModel |
||||
{ |
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
@using Teknik.Models |
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
||||
@model Teknik.ViewModels.LoginViewModel |
||||
@model Teknik.Areas.Profile.ViewModels.LoginViewModel |
||||
|
||||
<form role="form" id="loginForm" action="@Url.Action("Login", "Profile", new { area = "Home" })" method="post" accept-charset="UTF-8"> |
||||
<form role="form" id="loginForm" action="@Url.Action("Login", "Profile", new { area = "Profile" })" method="post" accept-charset="UTF-8"> |
||||
@Html.ValidationSummary(true, "Login failed. Check your login details.") |
||||
<div class="form-group"> |
||||
<input type="text" class="form-control" id="Username" value="" placeholder="Username" name="Username" data-val-required="The Username field is required." data-val="true" /> |
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
@model Teknik.ViewModels.RegisterViewModel |
||||
@model Teknik.Areas.Profile.ViewModels.RegisterViewModel |
||||
|
||||
<form role="form" id="registrationForm" action="@Url.Action("Register", "Profile", new { area = "Profile" })" method="post" accept-charset="UTF-8"> |
||||
@Html.ValidationSummary(true, "Registration failed. Check your registration details.") |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
@{ |
||||
Layout = "~/Views/Shared/_Layout.cshtml"; |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0"?> |
||||
|
||||
<configuration> |
||||
<configSections> |
||||
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> |
||||
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> |
||||
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> |
||||
</sectionGroup> |
||||
</configSections> |
||||
|
||||
<system.web.webPages.razor> |
||||
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> |
||||
<pages pageBaseType="System.Web.Mvc.WebViewPage"> |
||||
<namespaces> |
||||
<add namespace="System.Web.Mvc" /> |
||||
<add namespace="System.Web.Mvc.Ajax" /> |
||||
<add namespace="System.Web.Mvc.Html" /> |
||||
<add namespace="System.Web.Routing" /> |
||||
<add namespace="System.Web.Optimization" /> |
||||
<add namespace="Teknik" /> |
||||
|
||||
</namespaces> |
||||
</pages> |
||||
</system.web.webPages.razor> |
||||
|
||||
<appSettings> |
||||
<add key="webpages:Enabled" value="false" /> |
||||
</appSettings> |
||||
|
||||
<system.webServer> |
||||
<handlers> |
||||
<remove name="BlockViewHandler"/> |
||||
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> |
||||
</handlers> |
||||
</system.webServer> |
||||
</configuration> |
@ -1,193 +0,0 @@
@@ -1,193 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Data; |
||||
using System.Data.Entity; |
||||
using System.Linq; |
||||
using System.Net; |
||||
using System.Security.Cryptography; |
||||
using System.Security.Policy; |
||||
using System.Text; |
||||
using System.Web; |
||||
using System.Web.Mvc; |
||||
using System.Web.Security; |
||||
using SecurityDriven.Inferno.Hash; |
||||
using SecurityDriven.Inferno.Mac; |
||||
using Teknik.Models; |
||||
using Teknik.ViewModels; |
||||
using SHA384 = Teknik.Helpers.SHA384; |
||||
|
||||
namespace Teknik.Controllers |
||||
{ |
||||
public class ProfileController : DefaultController |
||||
{ |
||||
private TeknikEntities db = new TeknikEntities(); |
||||
|
||||
[AllowAnonymous] |
||||
// GET: Profile
|
||||
public ActionResult Index() |
||||
{ |
||||
return View(); |
||||
} |
||||
|
||||
[HttpGet] |
||||
[AllowAnonymous] |
||||
// GET: Profile
|
||||
public ActionResult Login() |
||||
{ |
||||
return View(); |
||||
} |
||||
|
||||
[HttpPost] |
||||
[AllowAnonymous] |
||||
public ActionResult Login(LoginViewModel model) |
||||
{ |
||||
if (ModelState.IsValid) |
||||
{ |
||||
if (model.IsValid()) |
||||
{ |
||||
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe); |
||||
return Json(new {result = "true"}); |
||||
} |
||||
} |
||||
return Json(new { error = "Invalid User name or Password." }); |
||||
} |
||||
|
||||
public ActionResult Logout() |
||||
{ |
||||
FormsAuthentication.SignOut(); |
||||
return RedirectToAction("Index", "Home"); |
||||
} |
||||
|
||||
[HttpPost] |
||||
[AllowAnonymous] |
||||
public ActionResult Register(RegisterViewModel model) |
||||
{ |
||||
if (ModelState.IsValid) |
||||
{ |
||||
var foundUser = db.Users.Where(b => b.Username == model.Username); |
||||
if (foundUser.Any()) |
||||
{ |
||||
return Json(new {error = "That username already exists."}); |
||||
} |
||||
if (model.Password != model.ConfirmPassword) |
||||
{ |
||||
return Json(new {error = "Passwords must match."}); |
||||
} |
||||
if (model.Insert()) |
||||
{ |
||||
return RedirectToAction("Login", "Profile", new LoginViewModel { Username = model.Username, Password = model.Password }); |
||||
} |
||||
return Json(new { error = "You must include all fields." }); |
||||
} |
||||
return Json(new { error = "You must include all fields." }); |
||||
} |
||||
|
||||
// GET: Profile/Details/5
|
||||
public ActionResult Details(int? id) |
||||
{ |
||||
if (ModelState.IsValid) |
||||
{ |
||||
if (id == null) |
||||
{ |
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); |
||||
} |
||||
User user = db.Users.Find(id); |
||||
if (user == null) |
||||
{ |
||||
return HttpNotFound(); |
||||
} |
||||
return View(user); |
||||
} |
||||
return HttpNotFound(); |
||||
} |
||||
|
||||
// GET: Profile/Create
|
||||
public ActionResult Create() |
||||
{ |
||||
return View(); |
||||
} |
||||
|
||||
// POST: Profile/Create
|
||||
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost] |
||||
[ValidateAntiForgeryToken] |
||||
public ActionResult Create([Bind(Include = "UserId,Username")] User user) |
||||
{ |
||||
if (ModelState.IsValid) |
||||
{ |
||||
db.Users.Add(user); |
||||
db.SaveChanges(); |
||||
return RedirectToAction("Index"); |
||||
} |
||||
|
||||
return View(user); |
||||
} |
||||
|
||||
// GET: Profile/Edit/5
|
||||
public ActionResult Edit(int? id) |
||||
{ |
||||
if (id == null) |
||||
{ |
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); |
||||
} |
||||
User user = db.Users.Find(id); |
||||
if (user == null) |
||||
{ |
||||
return HttpNotFound(); |
||||
} |
||||
return View(user); |
||||
} |
||||
|
||||
// POST: Profile/Edit/5
|
||||
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost] |
||||
[ValidateAntiForgeryToken] |
||||
public ActionResult Edit([Bind(Include = "UserId,Username")] User user) |
||||
{ |
||||
if (ModelState.IsValid) |
||||
{ |
||||
db.Entry(user).State = EntityState.Modified; |
||||
db.SaveChanges(); |
||||
return RedirectToAction("Index"); |
||||
} |
||||
return View(user); |
||||
} |
||||
|
||||
// GET: Profile/Delete/5
|
||||
public ActionResult Delete(int? id) |
||||
{ |
||||
if (id == null) |
||||
{ |
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); |
||||
} |
||||
User user = db.Users.Find(id); |
||||
if (user == null) |
||||
{ |
||||
return HttpNotFound(); |
||||
} |
||||
return View(user); |
||||
} |
||||
|
||||
// POST: Profile/Delete/5
|
||||
[HttpPost, ActionName("Delete")] |
||||
[ValidateAntiForgeryToken] |
||||
public ActionResult DeleteConfirmed(int id) |
||||
{ |
||||
User user = db.Users.Find(id); |
||||
db.Users.Remove(user); |
||||
db.SaveChanges(); |
||||
return RedirectToAction("Index"); |
||||
} |
||||
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
if (disposing) |
||||
{ |
||||
db.Dispose(); |
||||
} |
||||
base.Dispose(disposing); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
namespace Teknik.Migrations |
||||
{ |
||||
using System; |
||||
using System.Data.Entity; |
||||
using System.Data.Entity.Migrations; |
||||
using System.Linq; |
||||
|
||||
internal sealed class Configuration : DbMigrationsConfiguration<Teknik.Models.TeknikEntities> |
||||
{ |
||||
public Configuration() |
||||
{ |
||||
AutomaticMigrationsEnabled = true; |
||||
AutomaticMigrationDataLossAllowed = true; |
||||
} |
||||
|
||||
protected override void Seed(Teknik.Models.TeknikEntities context) |
||||
{ |
||||
// This method will be called after migrating to the latest version.
|
||||
|
||||
// You can use the DbSet<T>.AddOrUpdate() helper extension method
|
||||
// to avoid creating duplicate seed data. E.g.
|
||||
//
|
||||
// context.People.AddOrUpdate(
|
||||
// p => p.FullName,
|
||||
// new Person { FullName = "Andrew Peters" },
|
||||
// new Person { FullName = "Brice Lambson" },
|
||||
// new Person { FullName = "Rowan Miller" }
|
||||
// );
|
||||
//
|
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue