This repository has been archived on 2023-04-02. You can view files and clone it, but cannot push or open issues or pull requests.
trainav/trainav.web/Utils/AuthUtil.cs

24 lines
548 B
C#
Raw Normal View History

using System.Linq;
using LinqToDB;
using Microsoft.AspNetCore.Http;
using trainav.web.database;
using trainav.web.database.Tables;
2023-01-24 19:31:00 +01:00
namespace trainav.web.Utils;
public static class AuthUtil {
public static string GetRemoteUser(HttpContext ctx, Database.DbConn db) {
2023-01-24 19:31:00 +01:00
#if (DEBUG)
2023-02-27 16:15:38 +01:00
const string remoteUser = "debuguser";
2023-01-24 19:31:00 +01:00
#else
var remoteUser = ctx.Request.Headers["Remote-User"];
2023-01-24 19:31:00 +01:00
#endif
if (!db.Users.Any(p => p.Username == remoteUser)) {
2023-01-24 19:31:00 +01:00
db.InsertWithInt32Identity(new User { Username = remoteUser });
}
2023-01-24 19:31:00 +01:00
return remoteUser;
}
}