예제 #1
0
        public void Register(RegisterItem item)
        {
            if (qRepository.Entities.Any(o => o.Phone == item.RegisterPhone && o.IsActive && !o.Locked))
            {
                throw new Exception("user has exists");
            }

            var encryptedPassword = this.encryptionService.EncryptText(item.Password1, "9FD84A6B-3345-4726-B4F6-4B5D8C3664AE");

            var user = LoginUser.CreateUser(2, item.RegisterPhone, encryptedPassword);

            user.LockUser();
            this.cmdRepository.Insert(user);
            this.cmdRepository.SaveChanges();
        }
예제 #2
0
        public static List<LoginUser> GetLoginUsers()
        {
            var loginUsers = new List<LoginUser>();

            var roles = IdDb.Roles.ToList();
            var users = IdDb.Users.ToList();

            bool adminFound = false;

            foreach (var loginUser in users)
            {

                var user = new LoginUser
                {
                    Id = loginUser.Id,
                    PasswordHash = loginUser.PasswordHash,
                    UserName = loginUser.UserName,
                    Roles = new List<Role>()
                };
                foreach (var role in loginUser.Roles.Select(identityUserRole => roles.Find(i => i.Id == identityUserRole.RoleId)))
                {
                    user.Roles.Add(new Role {Id = role.Id, Name = role.Name});
                }
                loginUsers.Add(user);

                if (loginUser.UserName == "*****@*****.**")
                {
                    adminFound = true;
                }
            }

            //If admin user does not yet exist create
            if (adminFound) return loginUsers;

            var adminUser = new LoginUser
            {
                UserName = "******",
                PasswordHash = "ALpMLxEVyd1jbBDAXGByZNfof8bJiLEU7G18oXyaKeoMg0f/xhLAAdUTBzSQ1NiFqQ=="
            };
            adminUser.CreateUser();
            var admin = IdDb.Users.First(i => i.UserName == "*****@*****.**");
            adminUser.Id = admin.Id;
            adminUser.AddToRole("Admin");
            adminUser.Roles = new List<Role> {new Role {Name = "Admin"}};
            loginUsers.Add(adminUser);

            return loginUsers;
        }