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/IdentityModels.cs | 134 +++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 Project-Unite/Models/IdentityModels.cs (limited to 'Project-Unite/Models/IdentityModels.cs') 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 -- cgit v1.2.3