2
0
Fork 0
mirror of https://github.com/sphildreth/roadie synced 2025-03-01 13:47:16 +00:00

Register and initial setup work

This commit is contained in:
Steven Hildreth 2018-12-15 10:53:14 -06:00
parent 6aad709e31
commit 3a42b23ddf
10 changed files with 103 additions and 9 deletions

View file

@ -11,7 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roadie.Library.Tests", "Roa
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{1BA7115B-6E37-4546-BBD6-C8B0787A3FE0}"
ProjectSection(SolutionItems) = preProject
new_setup.sql = new_setup.sql
roadie.sql = roadie.sql
EndProjectSection
EndProject

View file

@ -29,8 +29,10 @@ namespace Roadie.Api.Controllers
private readonly UserManager<ApplicationUser> userManager;
private IRoadieSettings RoadieSettings { get; }
private ICacheManager CacheManager { get; }
private IAdminService AdminService { get; }
public AccountController(
IAdminService adminService,
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager,
IConfiguration configuration,
@ -47,7 +49,7 @@ namespace Roadie.Api.Controllers
this.RoadieSettings = new RoadieSettings();
configuration.GetSection("RoadieSettings").Bind(this.RoadieSettings);
this.AdminService = adminService;
}
[HttpPost]
@ -124,15 +126,31 @@ namespace Roadie.Api.Controllers
var user = new ApplicationUser
{
UserName = registerModel.Username,
Email = registerModel.Email,
CreatedDate = DateTime.UtcNow
Email = registerModel.Email
};
var identityResult = await this.userManager.CreateAsync(user, registerModel.Password);
if (identityResult.Succeeded)
{
if(user.Id == 1)
{
await this.AdminService.DoInitialSetup(user, this.userManager);
}
await signInManager.SignInAsync(user, isPersistent: false);
return Ok(this.tokenService.GenerateToken(user, this.userManager));
var t = await this.tokenService.GenerateToken(user, this.userManager);
this.logger.LogInformation($"Successfully authenticated User [{ registerModel.Username}]");
this.CacheManager.ClearRegion(EntityControllerBase.ControllerCacheRegionUrn);
var avatarUrl = $"{this.Request.Scheme}://{this.Request.Host}/images/user/{ user.RoadieId }/{ this.RoadieSettings.ThumbnailImageSize.Width }/{ this.RoadieSettings.ThumbnailImageSize.Height }";
return Ok(new
{
Username = user.UserName,
user.Email,
user.LastLogin,
avatarUrl,
Token = t,
user.Timeformat,
user.Timezone
});
}
else
{

View file

@ -57,7 +57,8 @@ namespace Roadie.Api.Controllers
{
var result = await this.ArtistService.List(roadieUser: await this.CurrentUserModel(),
request: request,
doRandomize: doRandomize ?? false);
doRandomize: doRandomize ?? false,
onlyIncludeWithReleases: false);
if (!result.IsSuccess)
{
return StatusCode((int)HttpStatusCode.InternalServerError);

View file

@ -1,4 +1,5 @@
using Mapster;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
@ -63,6 +64,65 @@ namespace Roadie.Api.Services
Task.WaitAll(this.LogAndPublish(e.Message, e.Level));
}
/// <summary>
/// This is a very simple way to seed the database or setup configuration when the first (who becomes "Admin") user registers
/// </summary>
public async Task<OperationResult<bool>> DoInitialSetup(ApplicationUser user, UserManager<ApplicationUser> userManager)
{
var sw = new Stopwatch();
sw.Start();
// Create user roles
this.DbContext.UserRoles.Add(new ApplicationRole
{
Name = "Admin",
Description = "Users with Administrative (full) access",
NormalizedName = "ADMIN"
});
this.DbContext.UserRoles.Add(new ApplicationRole
{
Name = "Editor",
Description = "Users who have Edit Permissions",
NormalizedName = "EDITOR"
});
await this.DbContext.SaveChangesAsync();
// Add given user to Admin role
await userManager.AddToRoleAsync(user, "Admin");
// Create special system artists of 'Sound Tracks' and 'Various Artists'
this.DbContext.Artists.Add(new data.Artist
{
AlternateNames = "Sound Track|Film Sound Track|Film Sound Tracks|Les Sound Track|Motion Picture Soundtrack|Original Motion Picture SoundTrack|Original Motion Picture SoundTracks|Original Cast Album|Original Soundtrack|Soundtracks|SoundTrack|soundtracks|Original Cast|Original Cast Soundtrack|Motion Picture Cast Recording|Cast Recording",
ArtistType = "Meta",
BioContext = "A soundtrack, also written sound track, can be recorded music accompanying and synchronized to the images of a motion picture, book, television program or video game; a commercially released soundtrack album of music as featured in the soundtrack of a film or TV show; or the physical area of a film that contains the synchronized recorded sound.",
Name = "Sound Tracks",
SortName = "Sound Tracks",
Status = Statuses.Ok,
Tags = "movie and television soundtracks|video game soundtracks|book soundstracks|composite|compilations",
URLs = "https://en.wikipedia.org/wiki/Soundtrack"
});
this.DbContext.Artists.Add(new data.Artist
{
AlternateNames = "Various Artists|Various BNB artist|variousartist|va",
ArtistType = "Meta",
BioContext = "Songs included on a compilation album may be previously released or unreleased, usually from several separate recordings by either one or several performers. If by one artist, then generally the tracks were not originally intended for release together as a single work, but may be collected together as a greatest hits album or box set. If from several performers, there may be a theme, topic, or genre which links the tracks, or they may have been intended for release as a single work—such as a tribute album. When the tracks are by the same recording artist, the album may be referred to as a retrospective album or an anthology. Compilation albums may employ traditional product bundling strategies",
Name = "Various Artists",
SortName = "Various Artist",
Status = Statuses.Ok,
Tags = "compilations|various",
URLs = "https://en.wikipedia.org/wiki/Compilation_album"
});
await this.DbContext.SaveChangesAsync();
return new OperationResult<bool>
{
Data = true,
IsSuccess = true,
OperationTime = sw.ElapsedMilliseconds
};
}
public async Task<OperationResult<bool>> ScanInboundFolder(ApplicationUser user, bool isReadOnly = false)
{
var d = new DirectoryInfo(this.Configuration.InboundFolder);

View file

@ -1,4 +1,5 @@
using Roadie.Library;
using Microsoft.AspNetCore.Identity;
using Roadie.Library;
using Roadie.Library.Identity;
using System;
using System.Collections.Generic;
@ -9,6 +10,7 @@ namespace Roadie.Api.Services
{
public interface IAdminService
{
Task<OperationResult<bool>> DoInitialSetup(ApplicationUser user, UserManager<ApplicationUser> userManager);
Task<OperationResult<bool>> ScanInboundFolder(ApplicationUser user, bool isReadOnly = false);
}
}

View file

@ -4,6 +4,7 @@ using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
@ -230,6 +231,17 @@ namespace Roadie.Api
.AddXmlSerializerFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Latest);
services.Configure<IdentityOptions>(options =>
{
options.Password.RequireDigit = true;
options.Password.RequireLowercase = true;
options.Password.RequireNonAlphanumeric = true;
options.Password.RequireUppercase = true;
options.Password.RequiredLength = 6;
options.Password.RequiredUniqueChars = 1;
});
services.AddHttpContextAccessor();
services.AddScoped<IHttpContext>(factory =>
{

View file

@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Roadie.Library.Identity;
using Roadie.Library.Models.Releases;
using System;
using System.Collections.Generic;
using System.Threading;
@ -38,6 +37,7 @@ namespace Roadie.Library.Data
DbSet<UserArtist> UserArtists { get; set; }
DbSet<UserQue> UserQues { get; set; }
DbSet<UserRelease> UserReleases { get; set; }
DbSet<ApplicationRole> UserRoles { get; set; }
DbSet<ApplicationUser> Users { get; set; }
DbSet<UserTrack> UserTracks { get; set; }

View file

@ -32,6 +32,7 @@ namespace Roadie.Library.Data
public DbSet<UserArtist> UserArtists { get; set; }
public DbSet<UserRelease> UserReleases { get; set; }
public DbSet<ApplicationUser> Users { get; set; }
public DbSet<ApplicationRole> UserRoles { get; set; }
public DbSet<UserTrack> UserTracks { get; set; }
public DbSet<UserQue> UserQues { get; set; }

View file

@ -132,5 +132,6 @@ namespace Roadie.Library.Identity
//public ICollection<Submission> Submission { get; set; }
}
}

View file

@ -42,7 +42,7 @@ CREATE TABLE `artist` (
`birthDate` date DEFAULT NULL,
`beginDate` date DEFAULT NULL,
`endDate` date DEFAULT NULL,
`artistType` enum('Person','Group','Orchestra','Choir','Character','Other') DEFAULT NULL,
`artistType` enum('Character','Choir','Group','Meta','Orchestra','Other','Person') DEFAULT NULL,
`bioContext` text,
`bandStatus` enum('Active','On Hold','Split Up') DEFAULT NULL,
`discogsId` varchar(50) DEFAULT NULL,