fix some stuff
This commit is contained in:
parent
dda4d55e5a
commit
85f3933af5
@ -15,6 +15,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Xml;
|
||||
using MBS.Core;
|
||||
using MBS.Web;
|
||||
using MBS.Web.UI;
|
||||
@ -58,7 +59,7 @@ public abstract class MochaWebApplication : WebApplication
|
||||
protected virtual Oms CreateOms()
|
||||
{
|
||||
Oms oms = new MemoryOms();
|
||||
|
||||
|
||||
TenantHandle super = oms.CreateTenant("super");
|
||||
oms.SelectTenant(super);
|
||||
|
||||
@ -66,6 +67,38 @@ public abstract class MochaWebApplication : WebApplication
|
||||
return oms;
|
||||
}
|
||||
|
||||
class HomeWebPage : WebPage
|
||||
{
|
||||
protected override void OnInit(RenderEventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
string tenantName = e.Context.Request.GetExtraData<string>("TenantName");
|
||||
if (!e.Context.Session.ContainsKey(tenantName + ".UserToken"))
|
||||
{
|
||||
e.Context.Response.Redirect("~/" + e.Context.Request.PathVariables["tenant"] + "/d/login.htmld");
|
||||
}
|
||||
|
||||
Console.WriteLine("req app path: " + e.Context.Request.Path);
|
||||
}
|
||||
|
||||
protected override void CreateChildControls()
|
||||
{
|
||||
base.CreateChildControls();
|
||||
|
||||
|
||||
Oms oms = (Oms)((MochaWebApplication)Application.Instance).Oms;
|
||||
|
||||
InstanceHandle c_Tenant = oms.GetInstance(KnownInstanceGuids.Classes.Tenant);
|
||||
InstanceHandle i_Tenant = oms.GetInstancesOf(c_Tenant).First();
|
||||
|
||||
string loginHeaderText = oms.GetTranslationValue(i_Tenant, oms.GetInstance(KnownRelationshipGuids.Tenant__has_login_header__Translation));
|
||||
|
||||
Controls.Add(new Heading(1, loginHeaderText));
|
||||
Controls.Add(new Heading(3, "It works!"));
|
||||
}
|
||||
}
|
||||
|
||||
class LoginWebPage : WebPage
|
||||
{
|
||||
protected override void InitializeInternal()
|
||||
@ -119,11 +152,14 @@ font-weight: lighter;
|
||||
{
|
||||
e.Context.Session[tenantName + ".UserToken"] = (new Guid()).ToString("b");
|
||||
e.Context.Response.Redirect(String.Format("~/{0}/d/home.htmld", tenantName));
|
||||
return;
|
||||
}
|
||||
}
|
||||
litPasswordWarning.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
private Literal litPasswordWarning = null;
|
||||
|
||||
protected override void CreateChildControls()
|
||||
{
|
||||
@ -135,6 +171,7 @@ font-weight: lighter;
|
||||
InstanceHandle i_Tenant = oms.GetInstancesOf(c_Tenant).First();
|
||||
|
||||
string loginHeaderText = oms.GetTranslationValue(i_Tenant, oms.GetInstance(KnownRelationshipGuids.Tenant__has_login_header__Translation));
|
||||
string loginFooterText = oms.GetTranslationValue(i_Tenant, oms.GetInstance(KnownRelationshipGuids.Tenant__has_login_footer__Translation));
|
||||
|
||||
Panel panel = new Panel();
|
||||
panel.ContentControls.Add(new Container());
|
||||
@ -144,6 +181,12 @@ font-weight: lighter;
|
||||
new FormView.FormViewItem("User _name", new TextBox() { Name = "username" }),
|
||||
new FormView.FormViewItem("_Password", new TextBox(TextBoxType.Password) { Name = "password" } )
|
||||
}));
|
||||
panel.ContentControls.Add(new Heading(3, loginFooterText));
|
||||
|
||||
litPasswordWarning = new Literal("<p style=\"color: #ff0000;\">The user name or password is incorrect.</p>");
|
||||
litPasswordWarning.Visible = false;
|
||||
panel.ContentControls.Add(litPasswordWarning);
|
||||
|
||||
panel.FooterControls.Add(new Button("_Log In") { ThemeColorPreset = ThemeColorPreset.Primary, UseSubmitBehavior = true });
|
||||
Controls.Add(panel);
|
||||
|
||||
@ -216,21 +259,33 @@ font-weight: lighter;
|
||||
|
||||
// set up the routes
|
||||
// e.Server.Routes.Add(new WebRoute("/{tenant}", new RedirectWebHandler("~/{tenant}/d/home.htmld")));
|
||||
e.Server.Routes.Add(new WebRoute("/{tenant}/d/home.htmld", new WebHandler(delegate(WebContext ctx)
|
||||
|
||||
// FIXME: these routes should be loaded from the tenant; requires Mocha.Web.mcl
|
||||
InstanceHandle c_Route = Oms.GetInstance(KnownInstanceGuids.Classes.Route);
|
||||
IEnumerable<InstanceHandle> routes = Oms.GetInstancesOf(c_Route);
|
||||
if (routes.Count() > 0)
|
||||
{
|
||||
string tenantName = ctx.Request.GetExtraData<string>("TenantName");
|
||||
if (!ctx.Session.ContainsKey(tenantName + ".UserToken"))
|
||||
Console.WriteLine("cup: using tenanted WebRoutes");
|
||||
foreach (InstanceHandle route in routes)
|
||||
{
|
||||
ctx.Response.Redirect("~/" + ctx.Request.PathVariables["tenant"] + "/d/login.htmld");
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine("req app path: " + ctx.Request.Path);
|
||||
})));
|
||||
e.Server.Routes.Add(new WebRoute("/{tenant}/d/login.htmld", new RedirectWebHandler("~/madi/authgwy/{tenant}/login.htmld")));
|
||||
e.Server.Routes.Add(new WebRoute("/madi/authgwy/{tenant}/login.htmld", new LoginWebPage()));
|
||||
e.Server.Routes.Add(new WebRoute("/madi/asset/{name}/{version}/{path}", new AssetWebHandler()));
|
||||
e.Server.Routes.Add(new WebRoute("/{tenant}/attachment/{iid}/{accesskey}", new AttachmentWebHandler()));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("cup: no tenanted WebRoutes found; using hardcoded ones for now");
|
||||
e.Server.Routes.Add(new WebRoute("/{tenant}/d/home.htmld", new HomeWebPage()));
|
||||
e.Server.Routes.Add(new WebRoute("/{tenant}/d/login.htmld", new RedirectWebHandler("~/madi/authgwy/{tenant}/login.htmld")));
|
||||
e.Server.Routes.Add(new WebRoute("/{tenant}/d/logout.htmld", new RedirectWebHandler("~/madi/authgwy/{tenant}/logout.htmld")));
|
||||
e.Server.Routes.Add(new WebRoute("/madi/authgwy/{tenant}/login.htmld", new LoginWebPage()));
|
||||
e.Server.Routes.Add(new WebRoute("/madi/authgwy/{tenant}/logout.htmld", new WebHandler(delegate (WebContext ctx)
|
||||
{
|
||||
ctx.Session.Clear();
|
||||
ctx.Response.Redirect("~/" + ctx.Request.PathVariables["tenant"]);
|
||||
})));
|
||||
e.Server.Routes.Add(new WebRoute("/madi/asset/{name}/{version}/{path}", new AssetWebHandler()));
|
||||
e.Server.Routes.Add(new WebRoute("/{tenant}/attachment/{iid}/{accesskey}", new AttachmentWebHandler()));
|
||||
}
|
||||
Console.WriteLine("Mocha User Interface Service started - http://localhost:{0}", DefaultPort);
|
||||
}
|
||||
|
||||
|
||||
@ -45,8 +45,10 @@ public class Program : MochaWebApplication
|
||||
InstanceHandle i_Tenant = oms.GetInstancesOf(c_Tenant).First();
|
||||
InstanceHandle i_English = oms.GetInstance(KnownInstanceGuids.Languages.English);
|
||||
InstanceHandle r_Tenant__has_login_header__Translation = oms.GetInstance(KnownRelationshipGuids.Tenant__has_login_header__Translation);
|
||||
InstanceHandle r_Tenant__has_login_footer__Translation = oms.GetInstance(KnownRelationshipGuids.Tenant__has_login_footer__Translation);
|
||||
|
||||
oms.SetTranslationValue(i_Tenant, r_Tenant__has_login_header__Translation, i_English, "Welcome to your New Tenant");
|
||||
oms.SetTranslationValue(i_Tenant, r_Tenant__has_login_footer__Translation, i_English, "Please enter your user name and password to continue.");
|
||||
}
|
||||
|
||||
TenantHandle t_wdoms = oms.CreateTenant("wdoms");
|
||||
@ -56,8 +58,10 @@ public class Program : MochaWebApplication
|
||||
InstanceHandle i_Tenant = oms.GetInstancesOf(c_Tenant).First();
|
||||
InstanceHandle i_English = oms.GetInstance(KnownInstanceGuids.Languages.English);
|
||||
InstanceHandle r_Tenant__has_login_header__Translation = oms.GetInstance(KnownRelationshipGuids.Tenant__has_login_header__Translation);
|
||||
InstanceHandle r_Tenant__has_login_footer__Translation = oms.GetInstance(KnownRelationshipGuids.Tenant__has_login_footer__Translation);
|
||||
|
||||
oms.SetTranslationValue(i_Tenant, r_Tenant__has_login_header__Translation, i_English, "OMS Tenant Manager");
|
||||
oms.SetTranslationValue(i_Tenant, r_Tenant__has_login_footer__Translation, i_English, "The default credentials are mocha / testing");
|
||||
}
|
||||
return oms;
|
||||
}
|
||||
|
||||
@ -168,6 +168,11 @@ namespace Mocha.Core
|
||||
public static Guid RelationalOperator { get; } = new Guid("{f1b5d26f-2347-49cb-8aae-d80dd706fce2}");
|
||||
public static Guid LogicalOperator { get; } = new Guid("{340d464a-b47d-40a2-a185-be4d974b5899}");
|
||||
public static Guid ArithmeticOperator { get; } = new Guid("{8196e8b1-849d-4b18-a78b-5684dca7b7f4}");
|
||||
|
||||
|
||||
|
||||
public static Guid Route { get; } = new Guid("{6c589422-3f1e-4402-afc7-27b6956aa588}");
|
||||
public static Guid RouteTable { get; } = new Guid("{76e5ce90-5f64-4355-a0ee-f659cf615a63}");
|
||||
}
|
||||
public static class Methods
|
||||
{
|
||||
|
||||
@ -21,11 +21,14 @@ public class SecurityModule : MiniOmsModule
|
||||
{
|
||||
private InstanceHandle c_User, c_UserLogin, c_Role;
|
||||
private InstanceHandle r_User__has__Role;
|
||||
private InstanceHandle a_Token;
|
||||
|
||||
protected override void BuildInternal(Oms oms)
|
||||
{
|
||||
c_User = oms.CreateClass("User", KnownInstanceGuids.Classes.User);
|
||||
c_UserLogin = oms.CreateClass("User Login", KnownInstanceGuids.Classes.UserLogin);
|
||||
a_Token = oms.CreateInstanceOf(c_TextAttribute, KnownAttributeGuids.Text.Token);
|
||||
|
||||
// c_Role = oms.CreateClass("Role", KnownInstanceGuids.Classes.Role);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
namespace Mocha.Core.OmsImplementations.Mini.Modules;
|
||||
|
||||
public class WebModule : MiniOmsModule
|
||||
{
|
||||
private InstanceHandle c_Route;
|
||||
private InstanceHandle a_TargetURL;
|
||||
|
||||
private InstanceHandle CreateRoute(Oms oms, string targetUrl, InstanceHandle processedByControlTransactionMethod)
|
||||
{
|
||||
InstanceHandle rt = oms.CreateInstanceOf(c_Route);
|
||||
oms.SetAttributeValue(rt, a_TargetURL, "/{tenant}/d/home.htmld");
|
||||
return rt;
|
||||
}
|
||||
|
||||
protected override void BuildInternal(Oms oms)
|
||||
{
|
||||
a_TargetURL = oms.CreateInstanceOf(c_Attribute, KnownAttributeGuids.Text.TargetURL);
|
||||
|
||||
c_Route = oms.CreateClass("Route", KnownInstanceGuids.Classes.Route);
|
||||
oms.AddAttribute(c_Route, a_TargetURL);
|
||||
|
||||
// oms.CreateRelationship(c_Route, "processed by", c_ControlTransactionMethod, KnownRelationshipGuids.Route__processed_by__Control_Transaction_Method, true, "processes", KnownRelationshipGuids.Control_Transaction_Method__processes__Route);
|
||||
|
||||
// Route.processed by CT - Control Transaction Method
|
||||
// CT - Control Transaction Method.uses Build Response Method Binding
|
||||
// Build Response Method Binding.executes Method -- Build UI Response Method
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class CalculateDateMethod : Method
|
||||
{
|
||||
public override Guid ClassId => KnownInstanceGuids.MethodClasses.CalculateDateMethod;
|
||||
internal CalculateDateMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
|
||||
public struct CalculateDateMethodIncrement
|
||||
{
|
||||
public InstanceHandle AmountRAMB { get; }
|
||||
public InstanceHandle DateIntervalOrDateIntervalRSMB { get; }
|
||||
public bool Subtract { get; }
|
||||
|
||||
public CalculateDateMethodIncrement(InstanceHandle amountRAMB, InstanceHandle dateIntervalOrDateIntervalRSMB, bool subtract)
|
||||
{
|
||||
AmountRAMB = amountRAMB;
|
||||
DateIntervalOrDateIntervalRSMB = dateIntervalOrDateIntervalRSMB;
|
||||
Subtract = subtract;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Mocha.Core.OmsImplementations.Mini;
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.Oop.Methods;
|
||||
|
||||
namespace Mocha.Core.Tests;
|
||||
|
||||
public class CalculateDateMethodTests : MethodTestsBase
|
||||
{
|
||||
/*
|
||||
[Test]
|
||||
public void CalculateDateMethodTest()
|
||||
{
|
||||
InstanceHandle c_CommonDate = Oms.GetInstance(KnownInstanceGuids.Classes.CommonDate);
|
||||
OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms);
|
||||
CalculateDateMethod cdMethod = methodBuilder.CreateCalculateDateMethod(c_CommonDate, "adjust", "Date And Time parm to 'Nth of month'", AccessModifier.RootA2, true, Oms.GetInstance(KnownAttributeGuids.Date.DateAndTime), Oms.GetInstance(KnownAttributeGuids.Date.DateAndTime));
|
||||
ReturnAttributeMethodBinding gasMethodRamb = methodBuilder.CreateReturnAttributeMethodBinding(gasMethod);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
string value = Oms.ExecuteReturningAttributeValue<string>(context, gasMethodRamb);
|
||||
|
||||
Assert.That(value, Is.EqualTo(TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE));
|
||||
}
|
||||
*/
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user