Implement LastLogin Field In User Model
Move `ServerConfig.json` Into Resources Folder
This commit is contained in:
parent
b2d824accd
commit
95618ceed7
@ -23,7 +23,7 @@ namespace qtc_api.Controllers
|
||||
private readonly IHubContext<ChatHub> _chatGWContext;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
private readonly ServerConfig serverConfig;
|
||||
private readonly ServerConfig? serverConfig;
|
||||
private readonly DataContext dataContext;
|
||||
|
||||
public AuthController(IUserService userService, ITokenService tokenService, IHubContext<ChatHub> chatGWContext, DataContext dataContext, IConfiguration configuration, IEmailService emailService)
|
||||
@ -34,7 +34,7 @@ namespace qtc_api.Controllers
|
||||
_configuration = configuration;
|
||||
_emailService = emailService;
|
||||
|
||||
serverConfig = JsonSerializer.Deserialize<ServerConfig>(JsonDocument.Parse(System.IO.File.ReadAllText("./ServerConfig.json")));
|
||||
serverConfig = JsonSerializer.Deserialize<ServerConfig>(JsonDocument.Parse(System.IO.File.ReadAllText("./Resources/ServerConfig.json")));
|
||||
this.dataContext = dataContext;
|
||||
}
|
||||
|
||||
@ -94,23 +94,16 @@ namespace qtc_api.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
if (dbUser.Data.Id == serverConfig.AdminUserId && dbUser.Data.Role != "Admin")
|
||||
if (dbUser.Data.Id == serverConfig?.AdminUserId && dbUser.Data.Role != "Admin")
|
||||
{
|
||||
dbUser.Data.Role = "Admin";
|
||||
dataContext.SaveChanges();
|
||||
}
|
||||
|
||||
if (dbUser.Data.Status == 1)
|
||||
{
|
||||
return Ok(new ServiceResponse<string>
|
||||
{
|
||||
Message = "User is already signed in.",
|
||||
Success = false
|
||||
});
|
||||
}
|
||||
|
||||
var token = await _tokenService.GenerateAccessTokenAndRefreshToken(dbUser.Data, true, request.RememberMe);
|
||||
|
||||
dbUser.Data.LastLogin = DateTime.UtcNow;
|
||||
|
||||
await dataContext.SaveChangesAsync();
|
||||
return Ok(token);
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
public string Role { get; set; } = string.Empty;
|
||||
public DateTime DateOfBirth { get; set; } = new DateTime();
|
||||
public DateTime CreatedAt { get; set; } = new DateTime();
|
||||
public DateTime LastLogin { get; set; } = new DateTime();
|
||||
public int Status { get; set; } = 0;
|
||||
public int CurrencyAmount { get; set; } = 0;
|
||||
public int ProfileCosmeticId { get; set; } = 0;
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
public DateTime LastCurrencySpin { get; set; }
|
||||
public int ActiveProfileCosmetic { get; set; } = 0;
|
||||
public string CurrentRoomId { get; set; } = string.Empty;
|
||||
public DateTime LastLogin { get; set; }
|
||||
|
||||
public virtual IEnumerable<RefreshToken>? RefreshTokens { get; }
|
||||
public virtual IEnumerable<Contact>? ContactsMade { get; }
|
||||
|
||||
@ -115,6 +115,7 @@ namespace qtc_api.Services.UserService
|
||||
x.Status = user.Status;
|
||||
x.CreatedAt = user.CreatedAt;
|
||||
x.ProfileCosmeticId = user.ActiveProfileCosmetic;
|
||||
x.LastLogin = user.LastLogin;
|
||||
|
||||
userInfoList.Add(x);
|
||||
}
|
||||
@ -146,6 +147,7 @@ namespace qtc_api.Services.UserService
|
||||
x.CurrencyAmount = user.CurrencyAmount;
|
||||
x.CreatedAt = user.CreatedAt;
|
||||
x.ProfileCosmeticId = user.ActiveProfileCosmetic;
|
||||
x.LastLogin = user.LastLogin;
|
||||
|
||||
onlineUsers.Add(x);
|
||||
}
|
||||
@ -184,6 +186,7 @@ namespace qtc_api.Services.UserService
|
||||
dto.Status = user.Status;
|
||||
dto.CurrencyAmount = user.CurrencyAmount;
|
||||
dto.ProfileCosmeticId = user.ActiveProfileCosmetic;
|
||||
dto.LastLogin = user.LastLogin;
|
||||
|
||||
serviceResponse.Success = true;
|
||||
serviceResponse.Data = dto;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user