Example #1
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 }));
        }
Example #2
0
        public JsonResult AddUser(UserModel model)
        {
            if (ModelState.IsValid)
            {
                var errorResult = ModelState.GetErrorModel();
                return(Json(errorResult));
            }

            addNewUser.Invoke(model);
            var result = new ResultModel <UserModel>(model);

            return(Json(result));
        }
Example #3
0
        public void SeedUsers(IAddNewUser addNewUser, IConfirmUserEmail confirmUserEmail)
        {
            foreach (var user in users)
            {
                var model = new UserModel
                {
                    Email    = $"{user}@test.com",
                    Password = "******",
                    Name     = user
                };

                if (user == "superadmin")
                {
                    model.IsSuperAdmin = true;
                }

                var userid = addNewUser.Invoke(model);
                confirmUserEmail.Invoke(userid);
            }
        }
Example #4
0
        public void SeedUsers(IAddNewUser addNewUser,
                              IConfirmUserEmailByToken confirmUserEmailByToken,
                              IGetDomainByName getDomainByName,
                              ISetDomainOwner setDomainOwner)
        {
            foreach (var user in users)
            {
                var domain = getDomainByName.Invoke("jan");
                var model  = new UserModel
                {
                    Email    = $"{user}@test.pl",
                    Password = "******",
                    Name     = user,
                    Domain   = domain
                };

                var dbUser = addNewUser.Invoke(model);

                if (dbUser == null)
                {
                    continue;
                }

                var token = dbUser.Tokens.FirstOrDefault().SecretToken;
                confirmUserEmailByToken.Invoke(token);

                var role = roles.Find(x => x.Name == "User");

                if (user != "owner")
                {
                    setDomainOwner.Invoke(dbUser.Id, domain.Id);
                    var domain2 = getDomainByName.Invoke("roland");
                    setDomainOwner.Invoke(dbUser.Id, domain2.Id);

                    role = roles.Find(x => x.Name == "Owner");
                }

                addUserToDomain.Invoke(dbUser.Id, domain.Id, role.Id);
            }
        }
Example #5
0
        public IActionResult Register(RegisterViewModel model)
        {
            var userModel = new UserModel()
            {
                Email = model.Email, Password = model.Password, Name = model.Name
            };
            var userAddAction = addNewUser.Invoke(userModel);

            if (userAddAction == 0)
            {
                Alert.Danger("User Already exists");
                return(View());
            }
            var parser            = new JwtParser();
            var confirmationToken = parser.AcquireEmailConfirmationToken(model.Email, userAddAction).Token;
            var callbackUrl       = Url.Action("ConfirmEmail", "Auth", new { token = confirmationToken }, Request.Scheme);

            var emailConfirmView = RenderViewToString("ConfirmEmail", "", callbackUrl);

            emailService.SendEmailAsync(model.Email, "Confirm your account", emailConfirmView).ConfigureAwait(false);

            Alert.Success("Confirmation email has been sent to your email address");
            return(RedirectToAction("Login", "Auth"));
        }