예제 #1
0
        public async Task RegisterUser(RegisterUserDto registerDto)
        {
            Guard.IsValidEmail(registerDto.Email);
            Guard.IsFalse(await accountRepository.AnyAsync(new DirectSpecification <Account>(x => x.Email == registerDto.Email)), "This account already exists");

            var user = User.Register(registerDto.Email, registerDto.Password, registerDto.FirstName, registerDto.LastName);

            userRepository.Insert(user);

            //Accept invitations
            await AcceptInvitation(registerDto.Email, user);

            await UnitOfWork.SaveAsync();

            var token = Security.EncodeText($"{SeparatorSring}{user.Account.Email}{SeparatorSring}{DateTime.UtcNow.ToShortDateString()}{SeparatorSring}", PrivateSecret);

            await emailService.SendEmailAsync(new WelcomeEmail(user.FullName, $"{urlService.GetBaseUrl()}/account/verify?token={token}")
            {
                To = registerDto.Email
            });
        }
예제 #2
0
        public async Task <IActionResult> Index([FromRoute] Guid applicationId)
        {
            ViewData["ApplicationId"] = applicationId;

            var environments = await environmentService.GetEnvironments(applicationId);

            var model = new ExporterPageModel
            {
                BaseUrl      = urlService.GetBaseUrl(),
                Environments = environments.Select(x => new EnvironmentModel {
                    Id = x.Id, Name = x.Name
                }),
            };

            return(View(model));
        }
예제 #3
0
        public async Task InviteUser(string email, Guid applicationId)
        {
            var user = await authService.CurrentUser();

            Guard.IsTrue(await hasApplicationPermission.ToWrite(user.Id, applicationId), new UnauthorizedException());

            var invitations = unitOfWork.Repository <Domain.Invitation, Guid>();
            var users       = unitOfWork.Repository <Domain.User, Guid>();

            var anyInvitationForThisEmail = await invitations.AnyAsync(Domain.Invitation.WithEmail(email).And(Domain.Invitation.WithApplication(applicationId)));

            Guard.IsFalse(anyInvitationForThisEmail, "You already invite this user");

            var applications = unitOfWork.Repository <Domain.Application, Guid>();
            var application  = await applications.GetById(applicationId);

            var invitationUrl = urlService.GetBaseUrl();


            //Check if the user exits
            var invitedUser = await users.FirstOrDefaultAsync(new DirectSpecification <Domain.User>(x => x.Account.Email == email), "Account");

            if (invitedUser != null)
            {
                application.GrantPermissionForUser(invitedUser, Domain.ApplicationPermissions.Admin);
                invitationUrl += $"/account/login";
            }
            else
            {
                var invitation = Domain.Invitation.NewInvitation(email, application);
                invitations.Insert(invitation);
                invitationUrl += $"/account/register?i={invitation.Token}&email={email}";
            }

            activityService.Log(
                LogString.WithName("Invitation", "sent"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Email", email }
            }), applicationId, user.Id);

            await unitOfWork.SaveAsync();

            await emailService.SendEmailAsync(new InvitationEmail(application.Name, invitationUrl, user.FullName) { To = email, Subject = $"{user.FullName} has invited you to join {application.Name}" });
        }