mirror of
https://github.com/fergalmoran/podnoms.git
synced 2025-12-24 02:07:50 +00:00
Basic re-auth framework in place
This commit is contained in:
33
server/Controllers/UserController.cs
Normal file
33
server/Controllers/UserController.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PodNoms.Api.Models;
|
||||
using PodNoms.Api.Persistence;
|
||||
|
||||
namespace PodNoms.Api.Controllers {
|
||||
[Authorize]
|
||||
[Obsolete("This should be superceded by the new identity stuff")]
|
||||
public class UserController : Controller {
|
||||
protected IUserRepository _userRepository { get; }
|
||||
|
||||
public UserController(IUserRepository repository) {
|
||||
this._userRepository = repository;
|
||||
}
|
||||
protected async Task<User> GetUserAsync() {
|
||||
var identifier = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value;
|
||||
var user = await this._userRepository.GetAsync(identifier);
|
||||
return user;
|
||||
}
|
||||
protected async Task<string> GetUserUidAsync() {
|
||||
var user = await GetUserAsync();
|
||||
return user.Uid;
|
||||
}
|
||||
protected async Task<int> GetUserIdAsync() {
|
||||
var user = await GetUserAsync();
|
||||
return user.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user