public ActionResult CreateUser(CreateUser model)
 {
     if (ModelState.IsValid)
     {
         User createuser = new Entities.Users.User()
         {
             Username = model.Username,
             Email    = model.Email,
             Password = model.Password
         };
         _userService.UserCreate(createuser);
     }
     return(View(model));
 }
        /// <summary>
        /// Gets a list of customers that have the appropiate type associated with them (Customer)
        /// </summary>
        /// <returns></returns>
        public List <ListMaintenanceGroupModel> GetMaintenanceGroupsList()
        {
            var list = new List <ListMaintenanceGroupModel>();

            // Walk a list of customer profiles and return a list
            var query = from customers in RbacEntities.CustomerProfiles
                        select customers;

            foreach (var customer in query)
            {
                if (customer.CustomerTypeId == (int)CustomerProfileType.MaintenanceGroup)
                {
                    var customerModel = new ListMaintenanceGroupModel()
                    {
                        DisplayName = customer.DisplayName,
                        Id          = customer.CustomerId,
                        Status      = ((CustomerStatus)customer.Status).ToString(),
                        //PemsConnectionStringName = customer.PEMSConnectionStringName,
                        MaintenanceConnectionStringName = customer.MaintenanceConnectionStringName,
                        // ReportingConnectionStringName = customer.ReportingConnectionStringName,
                    };

                    var userFactory          = new UserFactory();
                    Entities.Users.User user = userFactory.GetUserById(customer.CreatedBy ?? -1);

                    customerModel.CreatedBy = user.FullName();
                    customerModel.CreatedOn = customer.CreatedOn ?? DateTime.MinValue;

                    if (customer.ModifiedBy == null)
                    {
                        customerModel.UpdatedBy = "-";
                        customerModel.UpdatedOn = DateTime.MinValue;
                    }
                    else
                    {
                        user = userFactory.GetUserById(customer.ModifiedBy ?? -1);
                        customerModel.UpdatedBy = user.FullName();
                        customerModel.UpdatedOn = customer.ModifiedOn ?? (customer.ModifiedOn ?? DateTime.MinValue);
                    }
                    customerModel.Name = customer.DisplayName;
                    list.Add(customerModel);
                }
            }
            return(list);
        }
Exemplo n.º 3
0
        public async Task <Entities.Users.User> RegisterUserAsync(RegisterUserRequest request)
        {
            IUser oktaUser = null;

            try
            {
                var oktaUserRequest = new CreateUserWithPasswordOptions
                {
                    Activate = true,
                    Profile  = new UserProfile
                    {
                        FirstName = request.FirstName,
                        LastName  = request.LastName,
                        Email     = request.Email,
                        Login     = request.Email
                    },
                    Password = request.Password
                };

                oktaUser = await _oktaClient.Users.CreateUserAsync(oktaUserRequest);

                _logger.LogDebug($"Registered user {request.Email} with Okta. Okta ID: {oktaUser.Id}");

                if (!string.IsNullOrEmpty(_oktaConfig.AppGroupName))
                {
                    var appGroup = await _oktaClient.Groups.FirstOrDefaultAsync(x => x.Profile.Name == _oktaConfig.AppGroupName);

                    if (appGroup != null)
                    {
                        await _oktaClient.Groups.AddUserToGroupAsync(appGroup.Id, oktaUser.Id);
                    }

                    _logger.LogDebug($"Added user {request.Email} to Okta group {_oktaConfig.AppGroupName}");
                }
            }
            catch (OktaApiException oktaEx)
            {
                _logger.LogError(oktaEx, $"Error creating user {request.Email} in Okta. Error Code: {oktaEx.ErrorCode}. Summary: {oktaEx.ErrorSummary}");

                // TODO: throw a more friendly error message
                throw new Exception(oktaEx.ErrorSummary, oktaEx);
            }

            try
            {
                var user = new Entities.Users.User
                {
                    SubjectId    = oktaUser.Id,
                    EmailAddress = request.Email,
                    FirstName    = request.FirstName,
                    LastName     = request.LastName,
                    RegisteredOn = DateTime.UtcNow
                };

                await CreateUserAsync(user);

                _logger.LogDebug($"Registered user {request.Email}");

                return(user);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error registering user {request.Email}");
                throw ex;
            }
        }
Exemplo n.º 4
0
 public async Task CreateUserAsync(Entities.Users.User user)
 {
     await _userRepository.CreateAsync(user);
 }