20 lines
551 B
C#
20 lines
551 B
C#
using System.Linq;
|
|
using LinqToDB;
|
|
using Microsoft.AspNetCore.Http;
|
|
using trainav.web.database;
|
|
using trainav.web.database.Tables;
|
|
|
|
namespace trainav.web.Utils;
|
|
|
|
public static class AuthUtil {
|
|
public static string GetRemoteUser(HttpContext ctx, Database.DbConn db) {
|
|
var remoteUser = ctx.Request.Headers.ContainsKey("Remote-User") ? ctx.Request.Headers["Remote-User"].ToString() : "_debuguser";
|
|
|
|
if (!db.Users.Any(p => p.Username == remoteUser)) {
|
|
db.InsertWithInt32Identity(new User { Username = remoteUser });
|
|
}
|
|
|
|
return remoteUser;
|
|
}
|
|
}
|