Beispiel #1
0
        public UserAccount Create(Guid id, string name, string email, string password, string jobTitle, UserRole roles)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentException("An ID must be supplied to create a user");
            }
            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentException("A password must be supplied to create a user");
            }
            if (!CurrentUser.HasRole(UserRole.Admin))
            {
                throw new DomainValidationException(Messages.InsufficientSecurityClearance, "CurrentUser");
            }
            var userAccount = new UserAccount
            {
                Id           = id,
                EmailAddress = email,
                Name         = name,
                JobTitle     = jobTitle,
                Roles        = roles
            };

            SetPassword(userAccount, password);
            ValidateAnnotatedObjectThrowOnFailure(userAccount);
            _userAccountValidator.ValidateThrowOnFailure(userAccount);
            _userAccountRepository.Create(userAccount);
            return(userAccount);
        }
        public void Register(RegisterUserAccountRequest regAccountDTO, string origin)
        {
            //check if the account already exists
            if (_repo.Exists(regAccountDTO.Email))
            {
                //potentially send an email
                return;
            }

            var account = _mapper.Map <UserAccount>(regAccountDTO);
            //the first registered user is the admin
            bool isFirstAccount = _repo.Count() == 0;

            account.Role              = isFirstAccount? Role.Admin : Role.User;
            account.CreatedOn         = DateTime.UtcNow;
            account.VerificationToken = randomTokenString();

            //hash password
            account.PasswordHash = BC.HashPassword(regAccountDTO.Password);
            //save the account
            _repo.Create(account);
            //send the registration email
        }
 public IActionResult Post([FromBody] UserAccount model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(InvalidModelStateResult());
         }
         var modelStateDic = repository.Validate(model);
         if (modelStateDic.Count > 0)
         {
             ModelState.AddModelErrors(modelStateDic);
             return(InvalidModelStateResult());
         }
         return(Accepted(repository.Create(model)));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.GetExceptionMessages());
         return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError));
     }
 }
 public TAccount Create()
 {
     return(inner.Create());
 }
Beispiel #5
0
        //public List<SelectGroupDto> GetAccountComboMultiple(int idUser)
        //{
        //    var accounts = _userAccountRepository.GetAccounts(idUser);

        //    return null;
        //}

        public UserAccount Create(UserAccount userAccount)
        {
            return(_userAccountRepository.Create(userAccount));
        }