mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-08 02:34:16 -04:00
Allowing account editing
This commit is contained in:
parent
977a0fa1f6
commit
eb132c2da2
@ -9,8 +9,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
namespace Kyoo.Models.DatabaseMigrations.Internal
|
namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||||
{
|
{
|
||||||
[DbContext(typeof(DatabaseContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200307160105_Intial")]
|
[Migration("20200316003155_Initial")]
|
||||||
partial class Intial
|
partial class Initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
|
|
||||||
namespace Kyoo.Models.DatabaseMigrations.Internal
|
namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||||
{
|
{
|
||||||
public partial class Intial : Migration
|
public partial class Initial : Migration
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using IdentityServer4.Extensions;
|
|
||||||
using IdentityServer4.Models;
|
using IdentityServer4.Models;
|
||||||
using IdentityServer4.Services;
|
using IdentityServer4.Services;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
|
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
@ -28,17 +29,30 @@ namespace Kyoo.Api
|
|||||||
public bool StayLoggedIn;
|
public bool StayLoggedIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AccountData
|
||||||
|
{
|
||||||
|
[FromQuery(Name = "email")]
|
||||||
|
public string Email { get; set; }
|
||||||
|
[FromQuery(Name = "username")]
|
||||||
|
public string Username { get; set; }
|
||||||
|
[FromQuery(Name = "picture")]
|
||||||
|
public IFormFile Picture { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class AccountController : Controller, IProfileService
|
public class AccountController : Controller, IProfileService
|
||||||
{
|
{
|
||||||
private readonly UserManager<User> _userManager;
|
private readonly UserManager<User> _userManager;
|
||||||
private readonly SignInManager<User> _signInManager;
|
private readonly SignInManager<User> _signInManager;
|
||||||
|
private readonly string _picturePath;
|
||||||
|
|
||||||
public AccountController(UserManager<User> userManager, SignInManager<User> siginInManager)
|
public AccountController(UserManager<User> userManager, SignInManager<User> siginInManager, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_signInManager = siginInManager;
|
_signInManager = siginInManager;
|
||||||
|
_picturePath = configuration.GetValue<string>("profilePicturePath");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("register")]
|
[HttpPost("register")]
|
||||||
@ -83,6 +97,7 @@ namespace Kyoo.Api
|
|||||||
{
|
{
|
||||||
new Claim("email", user.Email),
|
new Claim("email", user.Email),
|
||||||
new Claim("username", user.UserName),
|
new Claim("username", user.UserName),
|
||||||
|
new Claim("picture", $"api/account/picture/{user.UserName}")
|
||||||
};
|
};
|
||||||
|
|
||||||
context.IssuedClaims.AddRange(claims);
|
context.IssuedClaims.AddRange(claims);
|
||||||
@ -94,5 +109,36 @@ namespace Kyoo.Api
|
|||||||
User user = await _userManager.GetUserAsync(context.Subject);
|
User user = await _userManager.GetUserAsync(context.Subject);
|
||||||
context.IsActive = user != null;
|
context.IsActive = user != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("picture/{username}")]
|
||||||
|
public async Task<IActionResult> GetPicture(string username)
|
||||||
|
{
|
||||||
|
User user = await _userManager.FindByNameAsync(username);
|
||||||
|
if (user == null)
|
||||||
|
return BadRequest();
|
||||||
|
return new PhysicalFileResult(Path.Combine(_picturePath, user.Id), "image/png");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("update")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> Update([FromForm] AccountData data)
|
||||||
|
{
|
||||||
|
User user = await _userManager.GetUserAsync(HttpContext.User);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(data.Email))
|
||||||
|
user.Email = data.Email;
|
||||||
|
if (!string.IsNullOrEmpty(data.Username))
|
||||||
|
user.UserName = data.Username;
|
||||||
|
if (data.Picture?.Length > 0)
|
||||||
|
{
|
||||||
|
string path = Path.Combine(_picturePath, user.Id);
|
||||||
|
await using (FileStream file = System.IO.File.Create(path))
|
||||||
|
{
|
||||||
|
await data.Picture.CopyToAsync(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await _userManager.UpdateAsync(user);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit 6d892fd46e7aa56a7cb0bebd94d4404899382f2b
|
Subproject commit 044132d4bf052f61c99186258e9aaf6da571b4ca
|
@ -16,6 +16,7 @@
|
|||||||
"transmuxTempPath": "/tmp/cached/kyoo/transmux",
|
"transmuxTempPath": "/tmp/cached/kyoo/transmux",
|
||||||
"transcodeTempPath": "/tmp/cached/kyoo/transcode",
|
"transcodeTempPath": "/tmp/cached/kyoo/transcode",
|
||||||
"peoplePath": "/tmp/people",
|
"peoplePath": "/tmp/people",
|
||||||
|
"profilePicturePath": "/tmp/users/",
|
||||||
"plugins": "plugins/",
|
"plugins": "plugins/",
|
||||||
"regex": "(\\/(?<Collection>.*)\\/)?.*\\/(?<ShowTitle>.+?)(( S(?<Season>\\d+)E(?<Episode>\\d+)| (?<Absolute>\\d+)))?\\.",
|
"regex": "(\\/(?<Collection>.*)\\/)?.*\\/(?<ShowTitle>.+?)(( S(?<Season>\\d+)E(?<Episode>\\d+)| (?<Absolute>\\d+)))?\\.",
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user