static void Test3() { //foreach (var item in DAL.ConnStrs) //{ // Console.WriteLine("{0}\t{1}", item.Key, item.Value); //} //var fact = MySqlClientFactory.Instance; //var fact = SqliteFactory.Instance; //var dal = DAL.Create("Sqlite"); //DAL.AddConnStr("Membership", "Server=.;Port=3306;Database=world;Uid=root;Pwd=root", null, "MySql"); //var dal = DAL.Create("Membership"); //Console.WriteLine(dal.Db.ConnectionString); //var ds = dal.Select("select * from city"); //Console.WriteLine(ds.Tables[0].Rows.Count); var user = UserX.FindByName("admin"); Console.WriteLine("Name:" + user.DisplayName); Console.WriteLine("修改DisplayName:" + user.DisplayName); user.DisplayName = "微信表情符😃666"; user.Save(); user = UserX.Find(UserX._.Name == "admin"); Console.WriteLine("修改后的DisplayName:" + user.DisplayName); //var n = UserX.Meta.Count; //Console.WriteLine(n); }
static void Test1() { var total = UserX.Meta.Count; Console.WriteLine("总行数:{0:n0}", total); // 查询1000万次,不预热 var count = 10_000_000; var sw = Stopwatch.StartNew(); for (var i = 0; i < count; i++) { var user = UserX.FindByName("admin"); } sw.Stop(); var ms = sw.Elapsed.TotalMilliseconds; Console.WriteLine("查询[{0:n0}]次,耗时{1:n0}ms,速度{2:n0}qps", count, ms, count * 1000L / ms); }
/// <summary>登录</summary> /// <param name="name"></param> /// <param name="password"></param> /// <param name="remember">是否记住密码</param> /// <returns></returns> public override IManageUser Login(String name, String password, Boolean remember) { //var user = UserX.Login(name, password, rememberme); UserX user; try { // 用户登录,依次支持用户名、邮箱、手机、编码 var account = name.Trim(); user = UserX.FindByName(account); if (user == null && account.Contains("@")) { user = UserX.FindByMail(account); } if (user == null && account.ToLong() > 0) { user = UserX.FindByMobile(account); } if (user == null) { user = UserX.FindByCode(account); } if (user == null) { throw new EntityException("帐号{0}不存在!", account); } if (!user.Enable) { throw new EntityException("账号{0}被禁用!", account); } // 数据库为空密码,任何密码均可登录 if (!user.Password.IsNullOrEmpty()) { var ss = password.Split(':'); if (ss.Length <= 1) { if (!password.MD5().EqualIgnoreCase(user.Password)) { throw new EntityException("密码不正确!"); } } else { var salt = ss[1]; var pass = (user.Password.ToLower() + salt).MD5(); if (!ss[0].EqualIgnoreCase(pass)) { throw new EntityException("密码不正确!"); } } } // 保存登录信息 user.Logins++; user.LastLogin = DateTime.Now; user.LastLoginIP = UserHost; user.Update(); UserX.WriteLog("登录", true, $"用户[{user}]使用[{name}]登录成功"); } catch (Exception ex) { UserX.WriteLog("登录", false, name + "登录失败!" + ex.Message); throw; } Current = user; // 过期时间 var set = Setting.Current; var expire = TimeSpan.FromMinutes(0); if (remember && user != null) { expire = TimeSpan.FromDays(365); } else { if (set.SessionTimeout > 0) { expire = TimeSpan.FromSeconds(set.SessionTimeout); } } // 保存Cookie var context = Context?.HttpContext; this.SaveCookie(user, expire, context); return(user); }