From cdc61eb4ea5309769ad4db84d92594e4dc3dff67 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 20 Mar 2017 16:45:17 -0400 Subject: Initial commit (azure deploy test) --- Project-Unite/Models/AccountViewModels.cs | 119 ++++++++++++++ Project-Unite/Models/AddUserToRoleViewModel.cs | 17 ++ Project-Unite/Models/AdminViewModels.cs | 87 ++++++++++ Project-Unite/Models/ForumCategory.cs | 211 +++++++++++++++++++++++++ Project-Unite/Models/ForumViewModels.cs | 28 ++++ Project-Unite/Models/IdentityModels.cs | 134 ++++++++++++++++ Project-Unite/Models/ManageViewModels.cs | 86 ++++++++++ Project-Unite/Models/Role.cs | 80 ++++++++++ 8 files changed, 762 insertions(+) create mode 100644 Project-Unite/Models/AccountViewModels.cs create mode 100644 Project-Unite/Models/AddUserToRoleViewModel.cs create mode 100644 Project-Unite/Models/AdminViewModels.cs create mode 100644 Project-Unite/Models/ForumCategory.cs create mode 100644 Project-Unite/Models/ForumViewModels.cs create mode 100644 Project-Unite/Models/IdentityModels.cs create mode 100644 Project-Unite/Models/ManageViewModels.cs create mode 100644 Project-Unite/Models/Role.cs (limited to 'Project-Unite/Models') diff --git a/Project-Unite/Models/AccountViewModels.cs b/Project-Unite/Models/AccountViewModels.cs new file mode 100644 index 0000000..7fe0248 --- /dev/null +++ b/Project-Unite/Models/AccountViewModels.cs @@ -0,0 +1,119 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace Project_Unite.Models +{ + public class ExternalLoginConfirmationViewModel + { + [Required] + [Display(Name = "Email")] + public string Email { get; set; } + } + + public class ExternalLoginListViewModel + { + public string ReturnUrl { get; set; } + } + + public class SendCodeViewModel + { + public string SelectedProvider { get; set; } + public ICollection Providers { get; set; } + public string ReturnUrl { get; set; } + public bool RememberMe { get; set; } + } + + public class VerifyCodeViewModel + { + [Required] + public string Provider { get; set; } + + [Required] + [Display(Name = "Code")] + public string Code { get; set; } + public string ReturnUrl { get; set; } + + [Display(Name = "Remember this browser?")] + public bool RememberBrowser { get; set; } + + public bool RememberMe { get; set; } + } + + public class ForgotViewModel + { + [Required] + [Display(Name = "Email")] + public string Email { get; set; } + } + + public class LoginViewModel + { + [Required] + [Display(Name = "Email")] + [EmailAddress] + public string Email { get; set; } + + [Required] + [DataType(DataType.Password)] + [Display(Name = "Password")] + public string Password { get; set; } + + [Display(Name = "Remember me?")] + public bool RememberMe { get; set; } + } + + public class RegisterViewModel + { + [Required] + [EmailAddress] + [Display(Name = "Email")] + public string Email { get; set; } + + [Required] + [MaxLength(25, ErrorMessage ="Your username must be less than 25 characters long.")] + [MinLength(5, ErrorMessage ="Your username must have a minimum of 5 characters.")] + [Display(Name = "Username")] + public string Username { get; set; } + + + [Required] + [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] + [DataType(DataType.Password)] + [Display(Name = "Password")] + public string Password { get; set; } + + [DataType(DataType.Password)] + [Display(Name = "Confirm password")] + [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] + public string ConfirmPassword { get; set; } + } + + public class ResetPasswordViewModel + { + [Required] + [EmailAddress] + [Display(Name = "Email")] + public string Email { get; set; } + + [Required] + [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] + [DataType(DataType.Password)] + [Display(Name = "Password")] + public string Password { get; set; } + + [DataType(DataType.Password)] + [Display(Name = "Confirm password")] + [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] + public string ConfirmPassword { get; set; } + + public string Code { get; set; } + } + + public class ForgotPasswordViewModel + { + [Required] + [EmailAddress] + [Display(Name = "Email")] + public string Email { get; set; } + } +} diff --git a/Project-Unite/Models/AddUserToRoleViewModel.cs b/Project-Unite/Models/AddUserToRoleViewModel.cs new file mode 100644 index 0000000..4cd37ec --- /dev/null +++ b/Project-Unite/Models/AddUserToRoleViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Web; + +namespace Project_Unite.Models +{ + public class AddUserToRoleViewModel + { + [DisplayName("Username")] + public string Username { get; set; } + + [DisplayName("Role")] + public string RoleId { get; set; } + } +} \ No newline at end of file diff --git a/Project-Unite/Models/AdminViewModels.cs b/Project-Unite/Models/AdminViewModels.cs new file mode 100644 index 0000000..56edbdd --- /dev/null +++ b/Project-Unite/Models/AdminViewModels.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace Project_Unite.Models +{ + public class AdminAccessControlViewModel + { + public AdminAccessControlViewModel() + { + + } + + public AdminAccessControlViewModel(Dictionary modelList) + { + ACLList = new List(); + foreach(var v in modelList.Values) + { + ACLList.AddRange(v); + } + IDs = modelList.Keys.ToList(); + } + + public List IDs { get; set; } + public List ACLList { get; set; } + } + + public class AddForumCategoryViewModel + { + public string Name { get; set; } + public string Description { get; set; } + public string Parent { get; set; } + + public string StealPermissionsFrom { get; set; } + + public IEnumerable PossibleParents { get; set; } + public string Id { get; internal set; } + } + + public enum PermissionPreset + { + None = 0, + CanRead = 1, + CanReply = 2, + CanPost = 3 + } + + public class ModeratorBanListViewModel + { + public IEnumerable UserBans { get; set; } + public IEnumerable IPBans { get; set; } + } + + public class AuditLog + { + public AuditLog() + { + + } + + public AuditLog(string uid, AuditLogLevel lvl, string desc) + { + Id = Guid.NewGuid().ToString(); + Level = lvl; + UserId = uid; + Description = desc; + Timestamp = DateTime.Now; + } + + public string Id { get; set; } + public AuditLogLevel Level { get; set; } + public DateTime Timestamp { get; set; } + public string UserId { get; set; } + public string Description { get; set; } + } + + [Flags] + public enum AuditLogLevel + { + Admin, + Moderator, + User + } +} \ No newline at end of file diff --git a/Project-Unite/Models/ForumCategory.cs b/Project-Unite/Models/ForumCategory.cs new file mode 100644 index 0000000..da5a9c9 --- /dev/null +++ b/Project-Unite/Models/ForumCategory.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace Project_Unite.Models +{ + public class ForumCategory + { + [Key] + [Column(Order = 0)] + public string Id { get; set; } + + public virtual ForumCategory[] Children + { + get + { + var db = new ApplicationDbContext(); + return db.ForumCategories.Where(x => x.Parent == this.Id).ToArray(); + } + } + + public string Name { get; set; } + + public string Description { get; set; } + + public string LinkUrl { get; set; } + + public ForumTopic[] Topics + { + get + { + return new ApplicationDbContext().ForumTopics.Where(x => x.Parent == this.Id).ToArray(); + } + } + + public virtual string Parent { get; set; } + + public ForumPermission[] Permissions { get + { + var db = new ApplicationDbContext(); + return db.ForumPermissions.Where(x => x.CategoryId == this.Id).ToArray(); + } + } + } + + public class ForumPermission + { + [Key] + public string Id { get; set; } + + [Required] + public string CategoryId { get; set; } + + [Required] + public string RoleId { get; set; } + + [Required] + [EnumDataType(typeof(PermissionPreset))] + public PermissionPreset Permissions { get; set; } + } + + public class ForumPost + { + public string Id { get; set; } + + [Required] + public string Parent { get; set; } + + public string AuthorId { get; set; } + [AllowHtml] + public string Body { get; set; } + public DateTime PostedAt { get; set; } + + public virtual ForumPostEdit[] EditHistory + { + get + { + return new ApplicationDbContext().ForumPostEdits.Where(e => e.Parent == this.Id).ToArray(); + } + } + } + + public class ForumPostEdit + { + public string Id { get; set; } + [Required] + public string Parent { get; set; } + + public string UserId { get; set; } + public string EditReason { get; set; } + [AllowHtml] + public string PreviousState { get; set; } + public DateTime EditedAt { get; set; } + } + + public class ForumTopic + { + public string Id { get; set; } + [Required] + public virtual string Parent { get; set; } + + public Like[] Likes + { + get + { + return new ApplicationDbContext().Likes.Where(l => l.Topic == this.Id).Where(x=>x.IsDislike==false).ToArray(); + } + } + + public Like[] Dislikes + { + get + { + return new ApplicationDbContext().Likes.Where(l => l.Topic == this.Id).Where(x => x.IsDislike == true).ToArray(); + } + } + + + public string Discriminator { get; set; } + + public bool IsLocked { get; set; } + + public DateTime StartedAt { get; set; } + public string Subject { get; set; } + public string AuthorId { get; set; } + public bool IsSticky { get; set; } + public bool IsAnnounce { get; set; } + public bool IsUnlisted { get; set; } + public bool IsGlobal { get; set; } + + public virtual ForumPost[] Posts + { + get + { + return new ApplicationDbContext().ForumPosts.Where(x => x.Parent == this.Id).ToArray(); + } + } + + public virtual ForumPoll Poll { get; set; } + + + } + + public class Like + { + public string Id { get; set; } + + [Required] + public string User { get; set; } + + public DateTime LikedAt { get; set; } + + [Required] + public string Topic { get; set; } + public bool IsDislike { get; set; } + } + + public class EditPostViewModel + { + public string Id { get; set; } + [AllowHtml] + public string Contents { get; set; } + public string EditReason { get; set; } + } + + public class ForumPoll + { + public string Id { get; set; } + public string Description { get; set; } + + [Required] + public virtual List Options { get; set; } + public bool IsActive { get; set; } + public bool AllowMultivote { get; set; } + public bool AllowVoteChanges { get; set; } + + [Required] + public virtual ForumTopic Parent { get; set; } + } + + public class ForumPollOption + { + public string Id { get; set; } + public string Name { get; set; } + + [Required] + public virtual List Votes { get; set; } + + + [Required] + public virtual ForumPoll Poll { get; set; } + } + + public class ForumPollVote + { + public string Id { get; set; } + + [Required] + public ApplicationUser User { get; set; } + + [Required] + public virtual ForumPollOption Option { get; set; } + } + + //Unable to generate an explicit migration because the following explicit migrations are pending: [201703161804526_more-relationship-shit]. Apply the pending explicit migrations before attempting to generate a new explicit migration. + +} \ No newline at end of file diff --git a/Project-Unite/Models/ForumViewModels.cs b/Project-Unite/Models/ForumViewModels.cs new file mode 100644 index 0000000..2a03c4a --- /dev/null +++ b/Project-Unite/Models/ForumViewModels.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace Project_Unite.Models +{ + public class CreateTopicViewModel + { + public string Category { get; set; } + + + public string Subject { get; set; } + [AllowHtml] + public string Body { get; set; } + + public bool IsAnnounce { get; set; } + public bool IsGlobal { get; set; } + public bool IsSticky { get; set; } + + public bool HasPoll { get; set; } + public string PollOptions { get; set; } + public bool VotesChangable { get; set; } + public bool Multivote { get; set; } + public string Question { get; set; } + } +} \ No newline at end of file diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs new file mode 100644 index 0000000..1cf9577 --- /dev/null +++ b/Project-Unite/Models/IdentityModels.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Data.Entity.Infrastructure; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using System.Web.Mvc; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.EntityFramework; + +namespace Project_Unite.Models +{ + // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. + public class ApplicationUser : IdentityUser + { + public async Task GenerateUserIdentityAsync(UserManager manager) + { + // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType + var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); + // Add custom user claims here + return userIdentity; + + } + + public Role HighestRole + { + get + { + var roleList = new List(); + foreach (var role in this.Roles) + { + roleList.Add(new ApplicationDbContext().Roles.First(r => r.Id == role.RoleId) as Role); + + } + return roleList.OrderByDescending(x => x.Priority).First(); + } + } + + public string LastKnownIPAddress { get; set; } + + public DateTime JoinedAt { get; set; } + public DateTime LastLogin { get; set; } + + public bool IsBanned { get; set; } + public bool IsMuted { get; set; } + + public DateTime BannedAt { get; set; } + public DateTime MutedAt { get; set; } + public string BannedBy { get; set; } + public string MutedBy { get; set; } + + public int PostCount + { + get + { + using(var db = new ApplicationDbContext()) + { + return db.ForumPosts.Where(x=>x.AuthorId == this.Id).Count(); + } + } + } + + public int TopicCount + { + get + { + using (var db = new ApplicationDbContext()) + { + return db.ForumTopics.Where(x => x.AuthorId == this.Id).Count(); + } + } + } + + public long Codepoints { get; set; } + + [AllowHtml] + public string Bio { get; set; } + + public string BannerUrl { get; set; } + public string AvatarUrl { get; set; } + + public string DisplayName { get; set; } + public string FullName { get; set; } + public string Website { get; set; } + public string YoutubeUrl { get; set; } + public string SystemName { get; set; } + + public string Interests { get; set; } + public string Hobbies { get; set; } + + + + } + + public class BannedIP + { + public string Id { get; set; } + public string Address { get; set; } + } + + public class ApplicationDbContext : IdentityDbContext + { + public ApplicationDbContext() + : base("DefaultConnection", throwIfV1Schema: false) + { + + } + + public void DeleteObject(object obj) + { + ((IObjectContextAdapter)this).ObjectContext.DeleteObject(obj); + } + + public static ApplicationDbContext Create() + { + return new ApplicationDbContext(); + } + + public DbSet ForumPostEdits { get; set; } + public DbSet Likes { get; set; } + public DbSet ForumPermissions { get; set; } + public DbSet BannedIPs { get; set; } + public DbSet AuditLogs { get; set; } + public System.Data.Entity.DbSet IdentityRoles { get; set; } + public DbSet ForumCategories { get; set; } + public DbSet ForumTopics { get; set; } + public DbSet ForumPolls { get; set; } + public DbSet ForumPollOptions { get; set; } + public DbSet ForumPollVotes { get; set; } + public DbSet ForumPosts { get; set; } + + } +} \ No newline at end of file diff --git a/Project-Unite/Models/ManageViewModels.cs b/Project-Unite/Models/ManageViewModels.cs new file mode 100644 index 0000000..7a84bda --- /dev/null +++ b/Project-Unite/Models/ManageViewModels.cs @@ -0,0 +1,86 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNet.Identity; +using Microsoft.Owin.Security; + +namespace Project_Unite.Models +{ + public class IndexViewModel + { + public bool HasPassword { get; set; } + public IList Logins { get; set; } + public string PhoneNumber { get; set; } + public bool TwoFactor { get; set; } + public bool BrowserRemembered { get; set; } + } + + public class ManageLoginsViewModel + { + public IList CurrentLogins { get; set; } + public IList OtherLogins { get; set; } + } + + public class FactorViewModel + { + public string Purpose { get; set; } + } + + public class SetPasswordViewModel + { + [Required] + [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] + [DataType(DataType.Password)] + [Display(Name = "New password")] + public string NewPassword { get; set; } + + [DataType(DataType.Password)] + [Display(Name = "Confirm new password")] + [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] + public string ConfirmPassword { get; set; } + } + + public class ChangePasswordViewModel + { + [Required] + [DataType(DataType.Password)] + [Display(Name = "Current password")] + public string OldPassword { get; set; } + + [Required] + [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] + [DataType(DataType.Password)] + [Display(Name = "New password")] + public string NewPassword { get; set; } + + [DataType(DataType.Password)] + [Display(Name = "Confirm new password")] + [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] + public string ConfirmPassword { get; set; } + } + + public class AddPhoneNumberViewModel + { + [Required] + [Phone] + [Display(Name = "Phone Number")] + public string Number { get; set; } + } + + public class VerifyPhoneNumberViewModel + { + [Required] + [Display(Name = "Code")] + public string Code { get; set; } + + [Required] + [Phone] + [Display(Name = "Phone Number")] + public string PhoneNumber { get; set; } + } + + public class ConfigureTwoFactorViewModel + { + public string SelectedProvider { get; set; } + public ICollection Providers { get; set; } + } +} \ No newline at end of file diff --git a/Project-Unite/Models/Role.cs b/Project-Unite/Models/Role.cs new file mode 100644 index 0000000..1d5cac7 --- /dev/null +++ b/Project-Unite/Models/Role.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Data.Entity; +using Microsoft.AspNet.Identity.EntityFramework; + +namespace Project_Unite.Models +{ + public class Role : IdentityRole + { + public string Description { get; set; } + public string ColorHex { get; set; } + + public int Priority { get; set; } + + public bool CanViewProfiles { get; set; } + public bool CanEditOwnProfile { get; set; } + public bool CanEditProfiles { get; set; } + public bool CanEditUsername { get; set; } + public bool CanEditUsernames { get; set; } + public bool CanIssueBan { get; set; } + public bool CanIssueIPBan { get; set; } + public bool CanIssueEmailBan { get; set; } + public bool CanIssueMute { get; set; } + public bool CanReleaseBuild { get; set; } + public bool CanBlog { get; set; } + public bool CanAccessModCP { get; set; } + public bool CanAccessAdminCP { get; set; } + public bool CanAccessDevCP { get; set; } + public bool CanEditForumCategories { get; set; } + public bool CanDeleteForumCategories { get; set; } + public bool CanPostTopics { get; set; } + public bool CanPostPolls { get; set; } + public bool CanPostReplies { get; set; } + public bool CanPostStatuses { get; set; } + public bool CanEditRoles { get; set; } + public bool CanDeleteRoles { get; set; } + public bool CanDeleteOwnTopics { get; set; } + public bool CanDeleteTopics { get; set; } + public bool CanDeleteOwnPosts { get; set; } + public bool CanDeletePosts { get; set; } + public bool CanDeleteOwnStatuses { get; set; } + public bool CanDeleteStatuses { get; set; } + public bool CanEditOwnTopics { get; set; } + public bool CanEditTopics { get; set; } + public bool CanEditOwnPosts { get; set; } + public bool CanEditPosts { get; set; } + public bool CanEditOwnStatuses { get; set; } + public bool CanVoteInPolls { get; set; } + public bool CanDeleteUsers { get; set; } + public bool CanAnonymizeUsers { get; set; } + public bool CanPostSkins { get; set; } + public bool CanEditOwnSkins { get; set; } + public bool CanEditSkins { get; set; } + public bool CanDeleteOwnSkins { get; set; } + public bool CanDeleteSkins { get; set; } + public bool CanUpvoteSkins { get; set; } + public bool CanDownvoteSkins { get; set; } + public bool CanStickyOwnTopics { get; set; } + public bool CanStickyTopics { get; set; } + public bool CanAnnounceOwnTopics { get; set; } + public bool CanAnnounceTopics { get; set; } + public bool CanGlobalOwnTopics { get; set; } + public bool CanGlobalTopics { get; set; } + public bool CanMoveOwnTopics { get; set; } + public bool CanMoveTopics { get; set; } + public bool CanUnlistOwnTopics { get; set; } + public bool CanUnlistTopics { get; set; } + public bool CanLockOwnTopics { get; set; } + public bool CanUnlockOwnTopics { get; set; } + public bool CanLockTopics { get; set; } + public bool CanUnlockTopics { get; set; } + + public bool CanViewUserInfo { get; set; } + + public bool CanSeeUnlistedTopics { get; set; } + + } +} \ No newline at end of file -- cgit v1.2.3