summaryrefslogtreecommitdiff
path: root/Project-Unite/Models/IdentityModels.cs
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/Models/IdentityModels.cs
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/Models/IdentityModels.cs')
-rw-r--r--Project-Unite/Models/IdentityModels.cs134
1 files changed, 134 insertions, 0 deletions
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<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> 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<Role>();
+ 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<ApplicationUser>
+ {
+ 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<ForumPostEdit> ForumPostEdits { get; set; }
+ public DbSet<Like> Likes { get; set; }
+ public DbSet<ForumPermission> ForumPermissions { get; set; }
+ public DbSet<BannedIP> BannedIPs { get; set; }
+ public DbSet<AuditLog> AuditLogs { get; set; }
+ public System.Data.Entity.DbSet<Project_Unite.Models.Role> IdentityRoles { get; set; }
+ public DbSet<ForumCategory> ForumCategories { get; set; }
+ public DbSet<ForumTopic> ForumTopics { get; set; }
+ public DbSet<ForumPoll> ForumPolls { get; set; }
+ public DbSet<ForumPollOption> ForumPollOptions { get; set; }
+ public DbSet<ForumPollVote> ForumPollVotes { get; set; }
+ public DbSet<ForumPost> ForumPosts { get; set; }
+
+ }
+} \ No newline at end of file