/// <summary>
        /// 保存访问历史记录
        /// </summary>
        /// <param name="context"></param>
        /// <param name="v"></param>
        public static void Save(HttpContext context, OnlineUser v)
        {
            if (context.User.Identity.IsAuthenticated)
            {
                var user = UserHelper.RetrieveUserByUserName(context.User.Identity);

                // user == null 以前登录过客户端保留了 Cookie 但是用户名可能被系统删除
                // link bug: https://gitee.com/LongbowEnterprise/BootstrapAdmin/issues/I123MH
                if (user == null)
                {
                    return;
                }

                v.UserName    = user.UserName;
                v.DisplayName = user.DisplayName;
                DbContextManager.Create <Trace>().Save(new Trace
                {
                    Ip         = v.Ip,
                    RequestUrl = v.RequestUrl,
                    LogTime    = v.LastAccessTime,
                    City       = v.Location,
                    Browser    = v.Browser,
                    OS         = v.OS,
                    UserName   = v.UserName,
                    UserAgent  = v.UserAgent,
                    Referer    = v.Referer
                });
            }
        }
Exemple #2
0
        public void RetrieveUserByUserName_Ok()
        {
            var usr = UserHelper.RetrieveUserByUserName("Admin");

            Assert.Equal("Administrator", usr.DisplayName);

            // 新建用户 默认角色为 Default
            var user = new User {
                UserName = "******", Password = "******", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = ""
            };

            Assert.True(UserHelper.Save(user));
            var u = UserHelper.RetrieveUserByUserName(user.UserName);

            Assert.Equal("default.jpg", u.Icon);
            Assert.True(UserHelper.Delete(UserHelper.Retrieves().Where(usr => usr.UserName == user.UserName).Select(usr => usr.Id)));
        }
 /// <summary>
 /// 保存访问历史记录
 /// </summary>
 /// <param name="context"></param>
 /// <param name="v"></param>
 public static void Save(HttpContext context, OnlineUser v)
 {
     if (context.User.Identity.IsAuthenticated)
     {
         var user = UserHelper.RetrieveUserByUserName(context.User.Identity.Name);
         v.UserName    = user.UserName;
         v.DisplayName = user.DisplayName;
         DbContextManager.Create <Trace>().Save(new Trace
         {
             Id         = null,
             Ip         = v.Ip,
             RequestUrl = v.RequestUrl,
             LogTime    = v.LastAccessTime,
             City       = v.Location,
             Browser    = v.Browser,
             OS         = v.OS,
             UserName   = v.UserName,
             UserAgent  = v.UserAgent
         });
     }
 }