예제 #1
0
        public bool SeedRoles(IAddNewRole addNewRole)
        {
            var rolesInDb = 0;

            foreach (var role in roles)
            {
                var roleInDb = getRoleByName.Invoke(role.Name);

                if (roleInDb == null || roleInDb.Id == Guid.Empty)
                {
                    var roleId = addNewRole.Invoke(role);

                    if (roleId == Guid.Empty)
                    {
                        continue;
                    }

                    role.Id = roleId;
                    rolesInDb++;
                }
                else
                {
                    role.Id = roleInDb.Id;
                    rolesInDb++;
                }
            }

            return(roles.Count == rolesInDb);
        }
예제 #2
0
        public IActionResult CreateDomain(CreateDomainViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var domain = addNewDomain.Invoke(new DomainModel {
                Name = model.DomainName
            });

            if (domain == Guid.Empty)
            {
                ModelState.AddModelError("DomainName", "This domain already exists in our database");

                return(View(model));
            }

            var userModel = new UserModel {
                Email = model.Email, Password = model.Password, Name = model.Name, Domain = new DomainModel {
                    Id = domain
                }
            };
            var userAddAction = addNewUser.Invoke(userModel);

            if (userAddAction == null)
            {
                Alert.Danger("User already exists");

                return(View());
            }

            var callbackUrl = Url.Action("ConfirmEmail", "Auth", new { token = userAddAction.Tokens.FirstOrDefault().SecretToken },
                                         Request.Scheme);
            var emailinfo     = new EmailBodyHelper().GetRegisterEmailBodyModel(callbackUrl);
            var stringView    = RenderViewToString("EmailTemplate", emailinfo);
            var message       = emailService.CreateMessage(model.Email, "Confirm your account", stringView);
            var mappedMessage = AutoMapper.Mapper.Map <EmailMessageModel>(message);

            addNewEmailMessage.Invoke(mappedMessage);

            setDomainOwner.Invoke(userAddAction.Id, domain);

            var role = getRoleByName.Invoke(RoleNamesConstants.Owner);

            // Add user to UserDomains table
            addUserToDomain.Invoke(userAddAction.Id, domain, role.Id);

            Alert.Success("Confirmation email has been sent to your email address");

            return(RedirectToAction("Login", "Auth", new { domainName = model.DomainName }));
        }