Ejemplo n.º 1
0
 public void PerTestSetUp()
 {
     // no mocks/stubs required.  m_repository is a RealAdministratorRepository
     // because that's our production class and that's what we want to test!
     m_repository = new RealAdministratorRepository();
     m_repository.Add(new Administrator(new Guid(AdminId)));
 }
Ejemplo n.º 2
0
        public void Create(string username, string password)
        {
            var account = new Administrator();

            account.Name     = username;
            account.UserName = username;
            account.Password = _cryptographyService.Encrypt(password);
            _administratorRepository.Add(account);
            _administratorRepository.SaveChanges();
        }
Ejemplo n.º 3
0
        public IActionResult CreatePassword(AdminViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newAdmin = new Administrator()
                {
                    HashedPassword = BCrypt.Net.BCrypt.HashPassword(model.Password)
                };

                _adminRepo.Add(newAdmin);
                _adminRepo.Commit();

                TempData["InfoAlert"] = "Congrats! Administrator account successfully created.";

                return(RedirectToAction("Index", "Home"));
            }
            TempData["WarningAlert"] = "Oh snap! Unable to save password.";
            return(View());
        }
        public async Task <ActionResult <String> > Register(RegisterDTO model)
        {
            IdentityUser user = new IdentityUser {
                UserName = model.Email, Email = model.Email
            };
            Administrator admin = new Administrator {
                Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                _administratorRepository.Add(admin);
                _administratorRepository.SaveChanges();
                string token = GetToken(user);
                return(Created("", token));
            }
            return(BadRequest());
        }
Ejemplo n.º 5
0
        public Administrator Create(Administrator user, string password)
        {
            // 验证
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("密码不能为空!");
            }

            if (string.IsNullOrEmpty(user.AdminName.Trim()))
            {
                throw new AppException("用户名不能为空!");
            }

            if (string.IsNullOrEmpty(user.Email.Trim()))
            {
                throw new AppException("邮箱不能为空!");
            }

            //if (_iUserRepository.Any(x => x.Email == user.Email))
            //    throw new AppException("Email \"" + user.Email + "\" is already taken");

            //if (_iUserRepository.Any(x => x.UserName == user.UserName))
            //    throw new AppException("Username \"" + user.UserName + "\" is already taken");

            CreatePasswordHash(password, out var passwordHash, out var passwordSalt);

            user.AdminId = Guid.NewGuid().ToString();
            user.RoleId  = 1;
            if (user.Avatar == null)
            {
                user.Avatar = "https://ng-alain.com/assets/img/logo-color.svg";
            }
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.School       = user.School;
            user.Status       = 0;
            user.UpdateTime   = DateTime.Now;

            _iAdministratorRepository.Add(user);

            return(user);
        }
Ejemplo n.º 6
0
        private void addPrivileges(int userID, int priveleges)
        {
            List <int> AdminIDs = getAdminIDs();

            if (priveleges == 2)
            {
                if (!AdminIDs.Contains(userID))
                {
                    Administrator administrator = new Administrator();
                    administrator.UserID = userID;
                    administratorRepositroy.Add(administrator);
                }
            }
            else if (priveleges == 1)
            {
                if (AdminIDs.Contains(userID))
                {
                    administratorRepositroy.Delete(userID);
                }
            }
        }
Ejemplo n.º 7
0
 public Task CreateAsync(Administrator user)
 {
     _administratorRepository.Add(user);
     return(_administratorRepository.SaveChangesAsync());
 }
Ejemplo n.º 8
0
 public Administrator Create(Administrator a)
 {
     repo.Add(a);
     repo.Save();
     return(a);
 }