60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using MistoxWebsite.Server.Entities;
|
|
using MistoxWebsite.Server.Services.DatabaseService;
|
|
|
|
namespace MistoxWebsite.Server.Controllers {
|
|
|
|
public class MistoxControllerBase : ControllerBase {
|
|
|
|
public DatabaseService _databaseService;
|
|
|
|
public MistoxControllerBase(DatabaseService databaseService) {
|
|
_databaseService = databaseService;
|
|
}
|
|
|
|
public bool isLoggedIn() {
|
|
if (User.Identity != null && User.Identity.IsAuthenticated) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public int getLoggedInUserID() {
|
|
return Convert.ToInt32(User.FindFirst("ID")?.Value);
|
|
}
|
|
|
|
public async Task<Account> getLoggedInUser() {
|
|
try {
|
|
Account? test = await _databaseService.GetAccount(getLoggedInUserID());
|
|
if (test != null) {
|
|
return test;
|
|
}
|
|
return new Account();
|
|
} catch {
|
|
return new Account();
|
|
}
|
|
}
|
|
|
|
public string Substitue(string message, string subString, string Replacement) {
|
|
for (int i = 0; i < (message.Length - subString.Length); i++) {
|
|
if (message.Substring(i, subString.Length) == subString) {
|
|
string before = message.Substring(0, i);
|
|
string after = message.Substring(i + subString.Length);
|
|
return before + Replacement + after;
|
|
}
|
|
}
|
|
return message;
|
|
}
|
|
|
|
public bool contains(string outer, string inner) {
|
|
if (outer.Length >= inner.Length) {
|
|
for (int i = 0; i < outer.Length - inner.Length; i++) {
|
|
if (outer.Substring(i, inner.Length) == inner) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
} |