Example #1
0
 public UserModel(Kooboo.Data.Models.User user)
 {
     if (user != null)
     {
         this.UserName  = user.UserName;
         this.FirstName = user.FirstName;
         this.Language  = user.Language;
         this.LastName  = user.LastName;
     }
 }
Example #2
0
File: User.cs Project: xhute/Kooboo
 public SimpleUser(Kooboo.Data.Models.User user)
 {
     if (user != null)
     {
         this.Id             = user.Id;
         this.CurrentOrgId   = user.CurrentOrgId;
         this.CurrentOrgName = user.CurrentOrgName;
         this.UserName       = user.UserName;
         this.EmailAddress   = user.EmailAddress;
         this.Language       = user.Language;
     }
 }
Example #3
0
        public async Task Invoke(RenderContext context)
        {
            if (!options.ShouldTryHandle(context, this.options))
            {
                await Next.Invoke(context); return;
            }

            if (this.options.InitData != null)
            {
                foreach (var item in this.options.InitData)
                {
                    context.DataContext.Push(item.Key, item.Value);
                }
            }

            Kooboo.Data.Models.User currentUser = null;

            if (context.User != null)
            {
                currentUser = context.User;
            }
            else
            {
                currentUser = new Data.Models.User();
            }

            context.DataContext.Push("User", context.User);

            var currentwebsite = context.WebSite;

            if (this.options.RequireSpeicalSite)
            {
                context.WebSite = null;

                //var website = new Kooboo.Data.Models.WebSite();
                //website.Name = "_____kooboorendertempspecialsitename";
                //context.WebSite = website;
            }

            if (this.options.RequireUser && !IsIgnorePath(context.Request.RelativeUrl))
            {
                var user = context.User;
                if (user == null)
                {
                    string relative = context.Request.RelativeUrl;

                    if (!string.IsNullOrEmpty(this.options.LoginPage))
                    {
                        int index = relative.IndexOf("&accesstoken");
                        if (index > -1)
                        {
                            relative = relative.Substring(0, index);
                        }

                        Dictionary <string, string> returnurl = new Dictionary <string, string>();
                        returnurl.Add("returnurl", relative);
                        string fullurl = Kooboo.Lib.Helper.UrlHelper.AppendQueryString(this.options.LoginPage, returnurl);
                        context.Response.Redirect(503, fullurl);
                        return;
                    }
                    else
                    {
                        context.Response.StatusCode = 503;
                        return;
                    }
                }
            }

            if (context.Response.End)
            {
                return;
            }

            if (!string.IsNullOrEmpty(this.options.LoginPage) && context.Request.RelativeUrl.StartsWith(this.options.LoginPage, System.StringComparison.OrdinalIgnoreCase))
            {
                if (context.User != null)
                {
                    string afterlogin = Kooboo.Data.Service.StartService.AfterLoginPage(context);
                    context.Response.Redirect(302, afterlogin);
                    return;
                }
            }

            var culture = GetCulture(context);

            if (culture != null)
            {
                context.Culture = culture;
            }

            var Response = RenderEngine.Render(context, this.options, RenderHelper.GetRelativeUrl(context.Request.RawRelativeUrl, options));

            // Set System version.
            context.Response.AppendCookie("_system_version_", Data.AppSettings.Version.ToString());
            if (Response != null)
            {
                if (this.options.Log != null)
                {
                    this.options.Log(context, Response);
                }

                context.Response.ContentType = Response.ContentType;

                context.Response.StatusCode = 200;
                if (Response.Stream != null)
                {
                    context.Response.Stream = Response.Stream;
                    return;
                }
                else if (Response.BinaryBytes != null)
                {
                    context.Response.Body = Response.BinaryBytes;
                    return;
                }
                else if (!string.IsNullOrEmpty(Response.Body))
                {
                    context.Response.Body = System.Text.Encoding.UTF8.GetBytes(Response.Body);
                    return;
                }
            }

            else
            {
                // try render controller...
                if (this.options.Render != null)
                {
                    string relativeurl = RenderHelper.GetRelativeUrl(context.Request.RawRelativeUrl, options);
                    var    resposne    = this.options.Render(context, relativeurl);
                    if (resposne != null)
                    {
                        SetResponse(context, resposne);
                        return;
                    }
                }
            }

            // Render controller here...
            //  context.Request.RelativeUrl = null; //restore change if any.
            if (this.options.RequireSpeicalSite)
            {
                context.WebSite = currentwebsite;  // restore...
            }
            await Next.Invoke(context);
        }