コード例 #1
0
 public ActionResult LoginInfo(int? id)
 {
     var ret = AuthenticateDeveloper();
     if (ret.StartsWith("!"))
         return Content($"<LoginInfo error=\"{ret.Substring(1)}\" />");
     if (!id.HasValue)
         return Content("<LoginInfo error=\"Missing id\" />");
     var p = DbUtil.Db.People.Single(pp => pp.PeopleId == id);
     var api = new APIFunctions(DbUtil.Db);
     return Content(api.Login(p), "text/xml");
 }
コード例 #2
0
        public ActionResult Login(string user, string password)
        {
            var ret = AuthenticateDeveloper();
            if (ret.StartsWith("!"))
                return Content($"<Login error=\"{ret.Substring(1)}\" />");

            var validationStatus = AccountModel.AuthenticateLogon(user, password, Request.Url.OriginalString);
            if (!validationStatus.IsValid)
                return Content($"<Login error=\"{user ?? "(null)"} not valid\">{validationStatus.ErrorMessage}</Login>");

            var api = new APIFunctions(DbUtil.Db);
            return Content(api.Login(validationStatus.User.Person), "text/xml");
        }
コード例 #3
0
        public string Login(Person p)
        {
            var script = Db.Content("API-LoginInfo");

            if (script == null)
            {
                script      = new Content();
                script.Body = @"
from System import *
from System.Text import *

class LoginInfo(object):

	def Run(self, m, w, p):
		w.Start('Login')
		w.Attr('PeopleId', p.PeopleId)
		w.Attr('PreferredName', p.PreferredName)
		w.Attr('Last', p.LastName)
		w.Attr('EmailAddress', p.EmailAddress)
		w.Attr('IsMember', p.MemberStatusId == 10)
		for b in m.StatusFlags(p.PeopleId):
			w.Add('StatusFlag', b);
		w.End()
		return w.ToString()
";
            }
            var engine = Python.CreateEngine();
            var sc     = engine.CreateScriptSourceFromString(script.Body);

            try
            {
                var code  = sc.Compile();
                var scope = engine.CreateScope();
                code.Execute(scope);

                dynamic LoginInfo = scope.GetVariable("LoginInfo");
                dynamic m         = LoginInfo();
                var     api       = new APIFunctions(Db);
                var     w         = new APIWriter();
                return(m.Run(api, w, p));
            }
            catch (Exception ex)
            {
                return("<login error=\"API-LoginInfo script error: {0}\" />".Fmt(ex.Message));
            }
        }
コード例 #4
0
ファイル: APIFunctions.cs プロジェクト: alexserdyuk/bvcms
        public string Login(Person p)
        {
            var script = Db.Content("API-LoginInfo");
            if (script == null)
            {
                script = new Content();
                script.Body = @"
            from System import *
            from System.Text import *

            class LoginInfo(object):

            def Run(self, m, w, p):
            w.Start('Login')
            w.Attr('PeopleId', p.PeopleId)
            w.Attr('PreferredName', p.PreferredName)
            w.Attr('Last', p.LastName)
            w.Attr('EmailAddress', p.EmailAddress)
            w.Attr('IsMember', p.MemberStatusId == 10)
            for b in m.StatusFlags(p.PeopleId):
            w.Add('StatusFlag', b);
            w.End()
            return w.ToString()
            ";
            }
            var engine = Python.CreateEngine();
            var sc = engine.CreateScriptSourceFromString(script.Body);
            try
            {
                var code = sc.Compile();
                var scope = engine.CreateScope();
                code.Execute(scope);

                dynamic LoginInfo = scope.GetVariable("LoginInfo");
                dynamic m = LoginInfo();
                var api = new APIFunctions(Db);
                var w = new APIWriter();
                return m.Run(api, w, p);
            }
            catch (Exception ex)
            {
                return $"<login error=\"API-LoginInfo script error: {ex.Message}\" />";
            }
        }
コード例 #5
0
 public ActionResult Login(string user, string password)
 {
     var ret = AuthenticateDeveloper();
     if (ret.StartsWith("!"))
         return Content("<Login error=\"{0}\" />".Fmt(ret.Substring(1)));
     var o = AccountModel.AuthenticateLogon(user, password, Request.Url.OriginalString);
     if (o is string)
         return Content("<Login error=\"{0} not valid\">{1}</Login>".Fmt(user ?? "(null)", o));
     var u = o as User;
     var api = new APIFunctions(DbUtil.Db);
     return Content(api.Login(u.Person),"text/xml");
 }
コード例 #6
0
 public ActionResult SqlScriptXml(string id, string p1 = null)
 {
     var f = new APIFunctions(DbUtil.Db);
     var e = $"<SqlScriptXml id={id}><Error>{{0}}</Error></SqlScriptXml>";
     return Content(SqlScript(id, p1, f.SqlScriptXml, e), "application/xml");
 }
コード例 #7
0
 public ActionResult SqlScriptJson(string id, string p1 = null)
 {
     var f = new APIFunctions(DbUtil.Db);
     var e = $@"{{ ""id"": ""{id}"", ""Error"": ""{{0}}"" }}";
     return Content(SqlScript(id, p1, f.SqlScriptJson, e), "application/json");
 }