Ejemplo n.º 1
0
        public override bool Submit()
        {
            if (!base.Submit())
            {
                return(false);
            }

            using (SnokyeContainer container = new SnokyeContainer())
            {
                string hashValue = Password.GetMD5();
#if DEBUG
                if (!container.UserInfoSet.Any())
                {
                    UserInfo __admin = new UserInfo {
                        DisplayName = "系统管理员", Password = "******".GetMD5(), UserName = "******", UserGuid = Guid.NewGuid()
                    };
                    container.AddToUserInfoSet(__admin);

                    for (int i = 0; i < 100; i++)
                    {
                        //0xB0A1 - 0xF7FE
                        UserInfo u = new UserInfo
                        {
                            UserName    = "******" + i,
                            DisplayName = "User" + i,
                            Password    = "******".GetMD5()
                        };
                        container.AddToUserInfoSet(u);

                        container.SaveChanges();
                    }
                }
#endif
                var user = container.UserInfoSet.FirstOrDefault(u => u.UserName == UserName && u.Password == hashValue);

                if (user == null)
                {
                    ValidateFailed?.Invoke(nameof(UserName), "用户名不存在或密码错误!");
                    return(false);
                }
                if (user.Disabled)
                {
                    ValidateFailed?.Invoke(nameof(UserName), "该用户已被禁用!");
                    return(false);
                }

                ClientInfo.CurrentUser = user;
                ClientInfo.UserProfile = new ServerUserProfile(user.UserGuid);
            }

            if (RememberPwd)
            {
                LocalUserProfile.SaveContent(UserName, "password", Password);
            }
            else
            {
                LocalUserProfile.Delete(UserName, "password");
            }
            return(true);
        }
Ejemplo n.º 2
0
        public override void LoadByID(long id)
        {
            if (id < 1)
            {
                //_eneity = UserInfo.CreateUserInfo(0, "", "", "123456".GetMD5(), Guid.NewGuid());
                _eneity = new UserInfo();
                _container.AddToUserInfoSet(_eneity);
            }
            else
            {
                _eneity = _container.UserInfoSet.FirstOrDefault(u => u.Id == id) ?? new UserInfo();
            }

            Map(nameof(UserName), _eneity, () => _eneity.UserName);
            Map(nameof(DisplayName), _eneity, () => _eneity.DisplayName);
            ReadMappedPropertyValues();
        }