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["Remote-User"];
		if (!db.Users.Any(p => p.Username == remoteUser)) {
			db.InsertWithInt32Identity(new User {Username = remoteUser});
		}
		return ctx.Request.Headers["Remote-User"];
	}
}
