Beispiel #1
0
        public static User GetUser(HttpRequest request, RenderContext context = null)
        {
            var user = _GetUserFromToken(request);

            // the user first login with token, should try to find the last page of this user.
            if (user != null)
            {
                if (Kooboo.Data.Service.StartService.IsDefaultStartPage(request.RelativeUrl) && string.IsNullOrWhiteSpace(RequestManager.GetHttpValue(request, "returnurl")))
                {
                    var lasturl = Service.UserLoginService.GetLastPath(user.Id);
                    if (!string.IsNullOrEmpty(lasturl))
                    {
                        context.Response.Redirect(302, lasturl);
                        context.Response.End = true;
                    }
                }
            }
            else
            {
                user = _GetUserFromBasicAuthentication(request);
            }

            if (user != null && context != null)
            {
                string remember = context.Request.QueryString.Get("remember");
                int    days     = 1;
                if (!string.IsNullOrEmpty(remember))
                {
                    days = 60;
                }
                context.Response.AppendCookie(DataConstants.UserApiSessionKey, user.Id.ToString(), days);
            }

            if (user == null)
            {
                user = _GetUserFromCookie(request);
            }

            if (user == null)
            {
                //Two factors is only use to validate access to remote servers.
                user = Kooboo.Data.Service.TwoFactorService.Validate(request);
                if (user != null)
                {
                    return(user);
                }
            }

            if (string.IsNullOrEmpty(Data.Service.UserLoginService.GetUserPassword(user)))
            {
                return(null);
            }

            return(user);
        }