Fixed the issue where we were not validting the correct token when resetting the password #865

Removed the old user (Well commented it out for now)
pull/1488/head
Jamie.Rees 7 years ago
parent 818acd6452
commit 6c3523b21e

@ -7,8 +7,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Security.Claims;
using System.Security.Principal; using System.Security.Principal;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Ombi.Core.Engine.Interfaces; using Ombi.Core.Engine.Interfaces;
@ -21,7 +23,7 @@ namespace Ombi.Core.Engine
public class MovieRequestEngine : BaseMediaEngine, IMovieRequestEngine public class MovieRequestEngine : BaseMediaEngine, IMovieRequestEngine
{ {
public MovieRequestEngine(IMovieDbApi movieApi, IRequestServiceMain requestService, IPrincipal user, public MovieRequestEngine(IMovieDbApi movieApi, IRequestServiceMain requestService, IPrincipal user,
INotificationHelper helper, IRuleEvaluator r, IMovieSender sender, ILogger<MovieRequestEngine> log, IUserIdentityManager manager) : base(user, requestService, r) INotificationHelper helper, IRuleEvaluator r, IMovieSender sender, ILogger<MovieRequestEngine> log, UserManager<OmbiUser> manager) : base(user, requestService, r)
{ {
MovieApi = movieApi; MovieApi = movieApi;
NotificationHelper = helper; NotificationHelper = helper;
@ -34,7 +36,7 @@ namespace Ombi.Core.Engine
private INotificationHelper NotificationHelper { get; } private INotificationHelper NotificationHelper { get; }
private IMovieSender Sender { get; } private IMovieSender Sender { get; }
private ILogger<MovieRequestEngine> Logger { get; } private ILogger<MovieRequestEngine> Logger { get; }
private IUserIdentityManager UserManager { get; } private UserManager<OmbiUser> UserManager { get; }
/// <summary> /// <summary>
/// Requests the movie. /// Requests the movie.
@ -56,7 +58,7 @@ namespace Ombi.Core.Engine
var fullMovieName = var fullMovieName =
$"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}"; $"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}";
var userDetails = await UserManager.GetUser(User.Identity.Name); var userDetails = await UserManager.GetUserAsync(new ClaimsPrincipal(User));
var requestModel = new MovieRequests var requestModel = new MovieRequests
{ {

@ -8,8 +8,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Security.Claims;
using System.Security.Principal; using System.Security.Principal;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Ombi.Core.Engine.Interfaces; using Ombi.Core.Engine.Interfaces;
using Ombi.Core.Helpers; using Ombi.Core.Helpers;
@ -25,7 +27,7 @@ namespace Ombi.Core.Engine
{ {
public TvRequestEngine(ITvMazeApi tvApi, IRequestServiceMain requestService, IPrincipal user, public TvRequestEngine(ITvMazeApi tvApi, IRequestServiceMain requestService, IPrincipal user,
INotificationHelper helper, IMapper map, INotificationHelper helper, IMapper map,
IRuleEvaluator rule, IUserIdentityManager manager, IRuleEvaluator rule, UserManager<OmbiUser> manager,
ITvSender sender) : base(user, requestService, rule) ITvSender sender) : base(user, requestService, rule)
{ {
TvApi = tvApi; TvApi = tvApi;
@ -38,12 +40,12 @@ namespace Ombi.Core.Engine
private INotificationHelper NotificationHelper { get; } private INotificationHelper NotificationHelper { get; }
private ITvMazeApi TvApi { get; } private ITvMazeApi TvApi { get; }
private IMapper Mapper { get; } private IMapper Mapper { get; }
private IUserIdentityManager UserManager { get; } private UserManager<OmbiUser> UserManager { get; }
private ITvSender TvSender {get;} private ITvSender TvSender {get;}
public async Task<RequestEngineResult> RequestTvShow(SearchTvShowViewModel tv) public async Task<RequestEngineResult> RequestTvShow(SearchTvShowViewModel tv)
{ {
var user = await UserManager.GetUser(User.Identity.Name); var user = await UserManager.GetUserAsync(new ClaimsPrincipal(User));
var tvBuilder = new TvShowRequestBuilder(TvApi); var tvBuilder = new TvShowRequestBuilder(TvApi);
(await tvBuilder (await tvBuilder

@ -43,7 +43,7 @@ namespace Ombi.Core.Helpers
return this; return this;
} }
public TvShowRequestBuilder CreateChild(SearchTvShowViewModel model, int userId) public TvShowRequestBuilder CreateChild(SearchTvShowViewModel model, string userId)
{ {
ChildRequest = new ChildRequests ChildRequest = new ChildRequests
{ {

@ -76,14 +76,14 @@ namespace Ombi.DependencyInjection
services.AddScoped<IOmbiContext, OmbiContext>(); services.AddScoped<IOmbiContext, OmbiContext>();
services.AddTransient<ISettingsRepository, SettingsJsonRepository>(); services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
services.AddTransient<IUserRepository, UserRepository>(); //services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<ISettingsResolver, SettingsResolver>(); services.AddTransient<ISettingsResolver, SettingsResolver>();
services.AddTransient<IPlexContentRepository, PlexContentRepository>(); services.AddTransient<IPlexContentRepository, PlexContentRepository>();
services.AddTransient<INotificationTemplatesRepository, NotificationTemplatesRepository>(); services.AddTransient<INotificationTemplatesRepository, NotificationTemplatesRepository>();
services.AddTransient<ITvRequestRepository, TvRequestRepository>(); services.AddTransient<ITvRequestRepository, TvRequestRepository>();
services.AddTransient<IMovieRequestRepository, MovieRequestRepository>(); services.AddTransient<IMovieRequestRepository, MovieRequestRepository>();
services.AddTransient<ITokenRepository, TokenRepository>(); //services.AddTransient<ITokenRepository, TokenRepository>();
services.AddTransient(typeof(ISettingsService<>), typeof(SettingsService<>)); services.AddTransient(typeof(ISettingsService<>), typeof(SettingsService<>));
} }
public static void RegisterServices(this IServiceCollection services) public static void RegisterServices(this IServiceCollection services)
@ -107,7 +107,6 @@ namespace Ombi.DependencyInjection
public static void RegisterIdentity(this IServiceCollection services) public static void RegisterIdentity(this IServiceCollection services)
{ {
services.AddTransient<IUserIdentityManager, UserIdentityManager>();
services.AddAuthorization(auth => services.AddAuthorization(auth =>
{ {
auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()

@ -13,7 +13,7 @@ namespace Ombi.Mapping.Profiles
{ {
public OmbiProfile() public OmbiProfile()
{ {
CreateMap<User, UserDto>().ReverseMap(); //CreateMap<User, UserDto>().ReverseMap();
CreateMap<Claim, ClaimCheckboxes>().ConvertUsing<ClaimsConverter>(); CreateMap<Claim, ClaimCheckboxes>().ConvertUsing<ClaimsConverter>();

@ -10,7 +10,7 @@ namespace Ombi.Notifications
public void Setup(FullBaseRequest req) public void Setup(FullBaseRequest req)
{ {
RequestedUser = string.IsNullOrEmpty(req.RequestedUser.Alias) RequestedUser = string.IsNullOrEmpty(req.RequestedUser.Alias)
? req.RequestedUser.Username ? req.RequestedUser.UserName
: req.RequestedUser.Alias; : req.RequestedUser.Alias;
Title = req.Title; Title = req.Title;
RequestedDate = req.RequestedDate.ToString("D"); RequestedDate = req.RequestedDate.ToString("D");
@ -23,7 +23,7 @@ namespace Ombi.Notifications
public void Setup(ChildRequests req) public void Setup(ChildRequests req)
{ {
RequestedUser = string.IsNullOrEmpty(req.RequestedUser.Alias) RequestedUser = string.IsNullOrEmpty(req.RequestedUser.Alias)
? req.RequestedUser.Username ? req.RequestedUser.UserName
: req.RequestedUser.Alias; : req.RequestedUser.Alias;
Title = req.ParentRequest.Title; Title = req.ParentRequest.Title;
RequestedDate = req.RequestedDate.ToString("D"); RequestedDate = req.RequestedDate.ToString("D");

@ -17,17 +17,16 @@ namespace Ombi.Store.Context
DbSet<PlexContent> PlexContent { get; set; } DbSet<PlexContent> PlexContent { get; set; }
DbSet<RadarrCache> RadarrCache { get; set; } DbSet<RadarrCache> RadarrCache { get; set; }
DatabaseFacade Database { get; } DatabaseFacade Database { get; }
DbSet<User> OldUsers { get; set; }
EntityEntry<T> Entry<T>(T entry) where T : class; EntityEntry<T> Entry<T>(T entry) where T : class;
EntityEntry<TEntity> Attach<TEntity>(TEntity entity) where TEntity : class; EntityEntry<TEntity> Attach<TEntity>(TEntity entity) where TEntity : class;
DbSet<TEntity> Set<TEntity>() where TEntity : class; DbSet<TEntity> Set<TEntity>() where TEntity : class;
DbSet<NotificationTemplates> NotificationTemplates { get; set; } DbSet<NotificationTemplates> NotificationTemplates { get; set; }
void Seed();
DbSet<MovieRequests> MovieRequests { get; set; } DbSet<MovieRequests> MovieRequests { get; set; }
DbSet<TvRequests> TvRequests { get; set; } DbSet<TvRequests> TvRequests { get; set; }
DbSet<ChildRequests> ChildRequests { get; set; } DbSet<ChildRequests> ChildRequests { get; set; }
DbSet<MovieIssues> MovieIssues { get; set; } DbSet<MovieIssues> MovieIssues { get; set; }
DbSet<TvIssues> TvIssues { get; set; } DbSet<TvIssues> TvIssues { get; set; }
DbSet<EmailTokens> EmailTokens { get; set; }
} }
} }

@ -19,28 +19,20 @@ namespace Ombi.Store.Context
Database.Migrate(); Database.Migrate();
// Add the notifcation templates // Add the notifcation templates
AddAllTemplates();
} }
public DbSet<NotificationTemplates> NotificationTemplates { get; set; }
public DbSet<GlobalSettings> Settings { get; set; } public DbSet<GlobalSettings> Settings { get; set; }
public DbSet<User> OldUsers { get; set; }
public DbSet<PlexContent> PlexContent { get; set; } public DbSet<PlexContent> PlexContent { get; set; }
public DbSet<RadarrCache> RadarrCache { get; set; } public DbSet<RadarrCache> RadarrCache { get; set; }
public DbSet<NotificationTemplates> NotificationTemplates { get; set; }
public DbSet<MovieRequests> MovieRequests { get; set; } public DbSet<MovieRequests> MovieRequests { get; set; }
public DbSet<TvRequests> TvRequests { get; set; } public DbSet<TvRequests> TvRequests { get; set; }
public DbSet<ChildRequests> ChildRequests { get; set; } public DbSet<ChildRequests> ChildRequests { get; set; }
public DbSet<MovieIssues> MovieIssues { get; set; } public DbSet<MovieIssues> MovieIssues { get; set; }
public DbSet<TvIssues> TvIssues { get; set; } public DbSet<TvIssues> TvIssues { get; set; }
public DbSet<EmailTokens> EmailTokens { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
@ -48,7 +40,7 @@ namespace Ombi.Store.Context
} }
private void AddAllTemplates() public void Seed()
{ {
// Check if templates exist // Check if templates exist
var templates = NotificationTemplates.ToList(); var templates = NotificationTemplates.ToList();

@ -1,18 +0,0 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace Ombi.Store.Entities
{
[Table("EmailTokens")]
public class EmailTokens : Entity
{
public Guid Token { get; set; }
public int UserId { get; set; }
public DateTime ValidUntil { get; set; }
public bool Used { get; set; }
public DateTime DateUsed { get; set; }
[ForeignKey(nameof(UserId))]
public User User { get; set; }
}
}

@ -10,13 +10,13 @@ namespace Ombi.Store.Entities.Requests
public bool Approved { get; set; } public bool Approved { get; set; }
public DateTime RequestedDate { get; set; } public DateTime RequestedDate { get; set; }
public bool Available { get; set; } public bool Available { get; set; }
public int RequestedUserId { get; set; } public string RequestedUserId { get; set; }
public bool? Denied { get; set; } public bool? Denied { get; set; }
public string DeniedReason { get; set; } public string DeniedReason { get; set; }
public RequestType RequestType { get; set; } public RequestType RequestType { get; set; }
[ForeignKey(nameof(RequestedUserId))] [ForeignKey(nameof(RequestedUserId))]
public User RequestedUser { get; set; } public OmbiUser RequestedUser { get; set; }
[NotMapped] [NotMapped]

@ -34,25 +34,25 @@ using Ombi.Helpers;
namespace Ombi.Store.Entities namespace Ombi.Store.Entities
{ {
public class User : Entity //public class User : Entity
{ //{
public string Username { get; set; } // public string Username { get; set; }
public string Alias { get; set; } // public string Alias { get; set; }
public string ClaimsSerialized { get; set; } // public string ClaimsSerialized { get; set; }
public string EmailAddress { get; set; } // public string EmailAddress { get; set; }
public string Password { get; set; } // public string Password { get; set; }
public byte[] Salt { get; set; } // public byte[] Salt { get; set; }
public UserType UserType { get; set; } // public UserType UserType { get; set; }
[NotMapped] // [NotMapped]
public string UserAlias => string.IsNullOrEmpty(Alias) ? Username : Alias; // public string UserAlias => string.IsNullOrEmpty(Alias) ? Username : Alias;
[NotMapped] // [NotMapped]
public List<Claim> Claims { // public List<Claim> Claims {
get => JsonConvert.DeserializeObject<List<Claim>>(ClaimsSerialized, new ClaimConverter()); // get => JsonConvert.DeserializeObject<List<Claim>>(ClaimsSerialized, new ClaimConverter());
set => ClaimsSerialized = JsonConvert.SerializeObject(value, new ClaimConverter()); // set => ClaimsSerialized = JsonConvert.SerializeObject(value, new ClaimConverter());
} // }
} //}
public enum UserType public enum UserType
{ {

@ -10,7 +10,7 @@ using Ombi.Store.Entities;
namespace Ombi.Store.Migrations namespace Ombi.Store.Migrations
{ {
[DbContext(typeof(OmbiContext))] [DbContext(typeof(OmbiContext))]
[Migration("20170712080109_Initial")] [Migration("20170719072204_Initial")]
partial class Initial partial class Initial
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -125,28 +125,6 @@ namespace Ombi.Store.Migrations
b.ToTable("AspNetUserTokens"); b.ToTable("AspNetUserTokens");
}); });
modelBuilder.Entity("Ombi.Store.Entities.EmailTokens", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("DateUsed");
b.Property<Guid>("Token");
b.Property<bool>("Used");
b.Property<int>("UserId");
b.Property<DateTime>("ValidUntil");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("EmailTokens");
});
modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b => modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -312,7 +290,7 @@ namespace Ombi.Store.Migrations
b.Property<DateTime>("RequestedDate"); b.Property<DateTime>("RequestedDate");
b.Property<int>("RequestedUserId"); b.Property<string>("RequestedUserId");
b.Property<string>("Title"); b.Property<string>("Title");
@ -374,7 +352,7 @@ namespace Ombi.Store.Migrations
b.Property<DateTime>("RequestedDate"); b.Property<DateTime>("RequestedDate");
b.Property<int>("RequestedUserId"); b.Property<string>("RequestedUserId");
b.Property<string>("Status"); b.Property<string>("Status");
@ -437,30 +415,6 @@ namespace Ombi.Store.Migrations
b.ToTable("TvRequests"); b.ToTable("TvRequests");
}); });
modelBuilder.Entity("Ombi.Store.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Alias");
b.Property<string>("ClaimsSerialized");
b.Property<string>("EmailAddress");
b.Property<string>("Password");
b.Property<byte[]>("Salt");
b.Property<int>("UserType");
b.Property<string>("Username");
b.HasKey("Id");
b.ToTable("OldUsers");
});
modelBuilder.Entity("Ombi.Store.Repository.Requests.EpisodeRequests", b => modelBuilder.Entity("Ombi.Store.Repository.Requests.EpisodeRequests", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -542,14 +496,6 @@ namespace Ombi.Store.Migrations
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("Ombi.Store.Entities.EmailTokens", b =>
{
b.HasOne("Ombi.Store.Entities.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b =>
{ {
b.HasOne("Ombi.Store.Entities.PlexContent") b.HasOne("Ombi.Store.Entities.PlexContent")
@ -565,10 +511,9 @@ namespace Ombi.Store.Migrations
.HasForeignKey("ParentRequestId") .HasForeignKey("ParentRequestId")
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
b.HasOne("Ombi.Store.Entities.User", "RequestedUser") b.HasOne("Ombi.Store.Entities.OmbiUser", "RequestedUser")
.WithMany() .WithMany()
.HasForeignKey("RequestedUserId") .HasForeignKey("RequestedUserId");
.OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieIssues", b => modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieIssues", b =>
@ -585,10 +530,9 @@ namespace Ombi.Store.Migrations
modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieRequests", b => modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieRequests", b =>
{ {
b.HasOne("Ombi.Store.Entities.User", "RequestedUser") b.HasOne("Ombi.Store.Entities.OmbiUser", "RequestedUser")
.WithMany() .WithMany()
.HasForeignKey("RequestedUserId") .HasForeignKey("RequestedUserId");
.OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("Ombi.Store.Entities.Requests.TvIssues", b => modelBuilder.Entity("Ombi.Store.Entities.Requests.TvIssues", b =>

@ -146,25 +146,6 @@ namespace Ombi.Store.Migrations
table.PrimaryKey("PK_TvRequests", x => x.Id); table.PrimaryKey("PK_TvRequests", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "OldUsers",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Alias = table.Column<string>(nullable: true),
ClaimsSerialized = table.Column<string>(nullable: true),
EmailAddress = table.Column<string>(nullable: true),
Password = table.Column<string>(nullable: true),
Salt = table.Column<byte[]>(nullable: true),
UserType = table.Column<int>(nullable: false),
Username = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_OldUsers", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "AspNetRoleClaims", name: "AspNetRoleClaims",
columns: table => new columns: table => new
@ -252,46 +233,56 @@ namespace Ombi.Store.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "PlexSeasonsContent", name: "MovieRequests",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(nullable: false) Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
ParentKey = table.Column<int>(nullable: false), Approved = table.Column<bool>(nullable: false),
PlexContentId = table.Column<int>(nullable: false), Available = table.Column<bool>(nullable: false),
SeasonKey = table.Column<int>(nullable: false), Denied = table.Column<bool>(nullable: true),
SeasonNumber = table.Column<int>(nullable: false) DeniedReason = table.Column<string>(nullable: true),
ImdbId = table.Column<string>(nullable: true),
IssueId = table.Column<int>(nullable: true),
Overview = table.Column<string>(nullable: true),
PosterPath = table.Column<string>(nullable: true),
ReleaseDate = table.Column<DateTime>(nullable: false),
RequestType = table.Column<int>(nullable: false),
RequestedDate = table.Column<DateTime>(nullable: false),
RequestedUserId = table.Column<string>(nullable: true),
Status = table.Column<string>(nullable: true),
TheMovieDbId = table.Column<int>(nullable: false),
Title = table.Column<string>(nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_PlexSeasonsContent", x => x.Id); table.PrimaryKey("PK_MovieRequests", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_PlexSeasonsContent_PlexContent_PlexContentId", name: "FK_MovieRequests_AspNetUsers_RequestedUserId",
column: x => x.PlexContentId, column: x => x.RequestedUserId,
principalTable: "PlexContent", principalTable: "AspNetUsers",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Restrict);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "EmailTokens", name: "PlexSeasonsContent",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(nullable: false) Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
DateUsed = table.Column<DateTime>(nullable: false), ParentKey = table.Column<int>(nullable: false),
Token = table.Column<Guid>(nullable: false), PlexContentId = table.Column<int>(nullable: false),
Used = table.Column<bool>(nullable: false), SeasonKey = table.Column<int>(nullable: false),
UserId = table.Column<int>(nullable: false), SeasonNumber = table.Column<int>(nullable: false)
ValidUntil = table.Column<DateTime>(nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_EmailTokens", x => x.Id); table.PrimaryKey("PK_PlexSeasonsContent", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_EmailTokens_OldUsers_UserId", name: "FK_PlexSeasonsContent_PlexContent_PlexContentId",
column: x => x.UserId, column: x => x.PlexContentId,
principalTable: "OldUsers", principalTable: "PlexContent",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
@ -310,7 +301,7 @@ namespace Ombi.Store.Migrations
ParentRequestId = table.Column<int>(nullable: false), ParentRequestId = table.Column<int>(nullable: false),
RequestType = table.Column<int>(nullable: false), RequestType = table.Column<int>(nullable: false),
RequestedDate = table.Column<DateTime>(nullable: false), RequestedDate = table.Column<DateTime>(nullable: false),
RequestedUserId = table.Column<int>(nullable: false), RequestedUserId = table.Column<string>(nullable: true),
Title = table.Column<string>(nullable: true) Title = table.Column<string>(nullable: true)
}, },
constraints: table => constraints: table =>
@ -323,42 +314,37 @@ namespace Ombi.Store.Migrations
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_ChildRequests_OldUsers_RequestedUserId", name: "FK_ChildRequests_AspNetUsers_RequestedUserId",
column: x => x.RequestedUserId, column: x => x.RequestedUserId,
principalTable: "OldUsers", principalTable: "AspNetUsers",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Restrict);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "MovieRequests", name: "MovieIssues",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(nullable: false) Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
Approved = table.Column<bool>(nullable: false), Description = table.Column<string>(nullable: true),
Available = table.Column<bool>(nullable: false),
Denied = table.Column<bool>(nullable: true),
DeniedReason = table.Column<string>(nullable: true),
ImdbId = table.Column<string>(nullable: true),
IssueId = table.Column<int>(nullable: true), IssueId = table.Column<int>(nullable: true),
Overview = table.Column<string>(nullable: true), MovieId = table.Column<int>(nullable: false),
PosterPath = table.Column<string>(nullable: true), Subect = table.Column<string>(nullable: true)
ReleaseDate = table.Column<DateTime>(nullable: false),
RequestType = table.Column<int>(nullable: false),
RequestedDate = table.Column<DateTime>(nullable: false),
RequestedUserId = table.Column<int>(nullable: false),
Status = table.Column<string>(nullable: true),
TheMovieDbId = table.Column<int>(nullable: false),
Title = table.Column<string>(nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_MovieRequests", x => x.Id); table.PrimaryKey("PK_MovieIssues", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_MovieRequests_OldUsers_RequestedUserId", name: "FK_MovieIssues_MovieRequests_IssueId",
column: x => x.RequestedUserId, column: x => x.IssueId,
principalTable: "OldUsers", principalTable: "MovieRequests",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_MovieIssues_MovieRequests_MovieId",
column: x => x.MovieId,
principalTable: "MovieRequests",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
@ -411,34 +397,6 @@ namespace Ombi.Store.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable(
name: "MovieIssues",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Description = table.Column<string>(nullable: true),
IssueId = table.Column<int>(nullable: true),
MovieId = table.Column<int>(nullable: false),
Subect = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_MovieIssues", x => x.Id);
table.ForeignKey(
name: "FK_MovieIssues_MovieRequests_IssueId",
column: x => x.IssueId,
principalTable: "MovieRequests",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_MovieIssues_MovieRequests_MovieId",
column: x => x.MovieId,
principalTable: "MovieRequests",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "EpisodeRequests", name: "EpisodeRequests",
columns: table => new columns: table => new
@ -491,11 +449,6 @@ namespace Ombi.Store.Migrations
table: "AspNetUserRoles", table: "AspNetUserRoles",
column: "RoleId"); column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_EmailTokens_UserId",
table: "EmailTokens",
column: "UserId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "EmailIndex", name: "EmailIndex",
table: "AspNetUsers", table: "AspNetUsers",
@ -575,9 +528,6 @@ namespace Ombi.Store.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "AspNetUserTokens"); name: "AspNetUserTokens");
migrationBuilder.DropTable(
name: "EmailTokens");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "GlobalSettings"); name: "GlobalSettings");
@ -602,9 +552,6 @@ namespace Ombi.Store.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "AspNetRoles"); name: "AspNetRoles");
migrationBuilder.DropTable(
name: "AspNetUsers");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "PlexContent"); name: "PlexContent");
@ -621,7 +568,7 @@ namespace Ombi.Store.Migrations
name: "TvRequests"); name: "TvRequests");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "OldUsers"); name: "AspNetUsers");
} }
} }
} }

@ -124,28 +124,6 @@ namespace Ombi.Store.Migrations
b.ToTable("AspNetUserTokens"); b.ToTable("AspNetUserTokens");
}); });
modelBuilder.Entity("Ombi.Store.Entities.EmailTokens", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("DateUsed");
b.Property<Guid>("Token");
b.Property<bool>("Used");
b.Property<int>("UserId");
b.Property<DateTime>("ValidUntil");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("EmailTokens");
});
modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b => modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -311,7 +289,7 @@ namespace Ombi.Store.Migrations
b.Property<DateTime>("RequestedDate"); b.Property<DateTime>("RequestedDate");
b.Property<int>("RequestedUserId"); b.Property<string>("RequestedUserId");
b.Property<string>("Title"); b.Property<string>("Title");
@ -373,7 +351,7 @@ namespace Ombi.Store.Migrations
b.Property<DateTime>("RequestedDate"); b.Property<DateTime>("RequestedDate");
b.Property<int>("RequestedUserId"); b.Property<string>("RequestedUserId");
b.Property<string>("Status"); b.Property<string>("Status");
@ -436,30 +414,6 @@ namespace Ombi.Store.Migrations
b.ToTable("TvRequests"); b.ToTable("TvRequests");
}); });
modelBuilder.Entity("Ombi.Store.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Alias");
b.Property<string>("ClaimsSerialized");
b.Property<string>("EmailAddress");
b.Property<string>("Password");
b.Property<byte[]>("Salt");
b.Property<int>("UserType");
b.Property<string>("Username");
b.HasKey("Id");
b.ToTable("OldUsers");
});
modelBuilder.Entity("Ombi.Store.Repository.Requests.EpisodeRequests", b => modelBuilder.Entity("Ombi.Store.Repository.Requests.EpisodeRequests", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -541,14 +495,6 @@ namespace Ombi.Store.Migrations
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("Ombi.Store.Entities.EmailTokens", b =>
{
b.HasOne("Ombi.Store.Entities.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b =>
{ {
b.HasOne("Ombi.Store.Entities.PlexContent") b.HasOne("Ombi.Store.Entities.PlexContent")
@ -564,10 +510,9 @@ namespace Ombi.Store.Migrations
.HasForeignKey("ParentRequestId") .HasForeignKey("ParentRequestId")
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
b.HasOne("Ombi.Store.Entities.User", "RequestedUser") b.HasOne("Ombi.Store.Entities.OmbiUser", "RequestedUser")
.WithMany() .WithMany()
.HasForeignKey("RequestedUserId") .HasForeignKey("RequestedUserId");
.OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieIssues", b => modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieIssues", b =>
@ -584,10 +529,9 @@ namespace Ombi.Store.Migrations
modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieRequests", b => modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieRequests", b =>
{ {
b.HasOne("Ombi.Store.Entities.User", "RequestedUser") b.HasOne("Ombi.Store.Entities.OmbiUser", "RequestedUser")
.WithMany() .WithMany()
.HasForeignKey("RequestedUserId") .HasForeignKey("RequestedUserId");
.OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("Ombi.Store.Entities.Requests.TvIssues", b => modelBuilder.Entity("Ombi.Store.Entities.Requests.TvIssues", b =>

@ -4,9 +4,9 @@ using Ombi.Store.Entities;
namespace Ombi.Store.Repository namespace Ombi.Store.Repository
{ {
public interface ITokenRepository //public interface ITokenRepository
{ //{
Task CreateToken(EmailTokens token); // Task CreateToken(EmailTokens token);
Task<EmailTokens> GetToken(Guid tokenId); // Task<EmailTokens> GetToken(Guid tokenId);
} //}
} }

@ -4,13 +4,13 @@ using Ombi.Store.Entities;
namespace Ombi.Store.Repository namespace Ombi.Store.Repository
{ {
public interface IUserRepository //public interface IUserRepository
{ //{
Task CreateUser(User user); // Task CreateUser(User user);
Task<User> GetUser(string username); // Task<User> GetUser(string username);
Task<IEnumerable<User>> GetUsers(); // Task<IEnumerable<User>> GetUsers();
Task DeleteUser(User user); // Task DeleteUser(User user);
Task<User> UpdateUser(User user); // Task<User> UpdateUser(User user);
Task<User> GetUser(int userId); // Task<User> GetUser(int userId);
} //}
} }

@ -6,25 +6,25 @@ using System.Threading.Tasks;
namespace Ombi.Store.Repository namespace Ombi.Store.Repository
{ {
public class TokenRepository : ITokenRepository //public class TokenRepository : ITokenRepository
{ //{
public TokenRepository(IOmbiContext db) // public TokenRepository(IOmbiContext db)
{ // {
Db = db; // Db = db;
} // }
private IOmbiContext Db { get; } // private IOmbiContext Db { get; }
public async Task CreateToken(EmailTokens token) // public async Task CreateToken(EmailTokens token)
{ // {
token.Token = Guid.NewGuid(); // token.Token = Guid.NewGuid();
await Db.EmailTokens.AddAsync(token); // await Db.EmailTokens.AddAsync(token);
await Db.SaveChangesAsync(); // await Db.SaveChangesAsync();
} // }
public async Task<EmailTokens> GetToken(Guid tokenId) // public async Task<EmailTokens> GetToken(Guid tokenId)
{ // {
return await Db.EmailTokens.FirstOrDefaultAsync(x => x.Token == tokenId); // return await Db.EmailTokens.FirstOrDefaultAsync(x => x.Token == tokenId);
} // }
} //}
} }

@ -34,53 +34,53 @@ using Ombi.Store.Entities;
namespace Ombi.Store.Repository namespace Ombi.Store.Repository
{ {
public class UserRepository : IUserRepository //public class UserRepository : IUserRepository
{ //{
public UserRepository(IOmbiContext ctx) // public UserRepository(IOmbiContext ctx)
{ // {
Db = ctx; // Db = ctx;
} // }
private IOmbiContext Db { get; } // private IOmbiContext Db { get; }
public async Task<User> GetUser(string username) // public async Task<User> GetUser(string username)
{ // {
var user = await Db.OldUsers.FirstOrDefaultAsync(x => x.Username.ToLower() == username.ToLower()); // var user = await Db.OldUsers.FirstOrDefaultAsync(x => x.Username.ToLower() == username.ToLower());
Db.Entry(user).Reload(); // Db.Entry(user).Reload();
return user; // return user;
} // }
public async Task<User> GetUser(int userId) // public async Task<User> GetUser(int userId)
{ // {
var user = await Db.OldUsers.FirstOrDefaultAsync(x => x.Id == userId); // var user = await Db.OldUsers.FirstOrDefaultAsync(x => x.Id == userId);
Db.Entry(user).Reload(); // Db.Entry(user).Reload();
return user; // return user;
} // }
public async Task CreateUser(User user) // public async Task CreateUser(User user)
{ // {
Db.OldUsers.Add(user); // Db.OldUsers.Add(user);
await Db.SaveChangesAsync(); // await Db.SaveChangesAsync();
} // }
public async Task<IEnumerable<User>> GetUsers() // public async Task<IEnumerable<User>> GetUsers()
{ // {
return await Db.OldUsers.ToListAsync(); // return await Db.OldUsers.ToListAsync();
} // }
public async Task DeleteUser(User user) // public async Task DeleteUser(User user)
{ // {
Db.OldUsers.Remove(user); // Db.OldUsers.Remove(user);
await Db.SaveChangesAsync(); // await Db.SaveChangesAsync();
} // }
public async Task<User> UpdateUser(User user) // public async Task<User> UpdateUser(User user)
{ // {
Db.Entry(user).State = EntityState.Modified; // Db.Entry(user).State = EntityState.Modified;
Db.Entry(user).Property(x => x.Salt).IsModified = false; // Db.Entry(user).Property(x => x.Salt).IsModified = false;
Db.Entry(user).Property(x => x.Password).IsModified = false; // Db.Entry(user).Property(x => x.Password).IsModified = false;
await Db.SaveChangesAsync(); // await Db.SaveChangesAsync();
return user; // return user;
} // }
} //}
} }

@ -435,7 +435,7 @@ namespace Ombi.Controllers
} }
// We have the user // We have the user
var token = await UserManager.GenerateEmailConfirmationTokenAsync(user); var token = await UserManager.GeneratePasswordResetTokenAsync(user);
// We now need to email the user with this token // We now need to email the user with this token
var emailSettings = await EmailSettings.GetSettingsAsync(); var emailSettings = await EmailSettings.GetSettingsAsync();
var customizationSettings = await CustomizationSettings.GetSettingsAsync(); var customizationSettings = await CustomizationSettings.GetSettingsAsync();

@ -169,6 +169,7 @@ namespace Ombi
#endif #endif
// Make sure you have memory cache available unless you're using another storage provider // Make sure you have memory cache available unless you're using another storage provider
services.AddMemoryCache(); services.AddMemoryCache();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -232,9 +233,9 @@ namespace Ombi
// Setup the scheduler // Setup the scheduler
var jobSetup = (IJobSetup)app.ApplicationServices.GetService(typeof(IJobSetup)); var jobSetup = (IJobSetup)app.ApplicationServices.GetService(typeof(IJobSetup));
var ctx = (IOmbiContext)app.ApplicationServices.GetService(typeof(IOmbiContext));
jobSetup.Setup(); jobSetup.Setup();
ctx.Seed();
//ConfigureAuth(app, (IOptions<TokenAuthenticationOptions>)app.ApplicationServices.GetService(typeof(IOptions<TokenAuthenticationOptions>)));
var provider = new FileExtensionContentTypeProvider(); var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".map"] = "application/octet-stream"; provider.Mappings[".map"] = "application/octet-stream";

Loading…
Cancel
Save