Esempio n. 1
0
            public async Task <Result> Handle(Command request, CancellationToken ct)
            {
                request.ReturnUrl ??= "/";

                var user = new User();

                await _userStore.SetUserNameAsync(user, request.Email, ct);

                await _emailStore.SetEmailAsync(user, request.Email, ct);

                var result = await _userManager.CreateAsync(user, request.Password);

                if (result.Succeeded)
                {
                    await _mailer.SendLaterAsync(new AccountRegisteredMail(user));

                    await _userSession.LoginAsync(request.Email, request.Password);
                }
                else
                {
                    throw new DomainException(result.Errors.Select(x => x.Description).Join(". "));
                }

                return(new Result
                {
                    RedirectTo = request.ReturnUrl,
                    IdentityResult = result
                });
            }
Esempio n. 2
0
            public async Task <Result> Handle(Command request, CancellationToken ct)
            {
                request.ReturnUrl ??= "/";

                var user = new User
                {
                    Name = request.Name
                };

                await _userStore.SetUserNameAsync(user, request.Email, ct);

                await _emailStore.SetEmailAsync(user, request.Email, ct);

                var result = await _userManager.CreateAsync(user, request.Password);

                if (result.Succeeded)
                {
                    await _mailer.SendLaterAsync(new AccountRegisteredMail(user));

                    // TODO: configurable LoginAfterRegister?
                    // await _userSession.LoginAsync(request.Email, request.Password);
                }
                else
                {
                    throw result.Errors.ToDomainException();
                }

                return(new Result
                {
                    IdentityResult = result
                });
            }
Esempio n. 3
0
 public static async Task SendLaterAsync <TMailable>(
     this IMailer mailer,
     IReceivesEmail to,
     TMailable mailable) where TMailable : Mailable
 {
     await mailer.SendLaterAsync(mailable, email =>
     {
         email.To(to.Email, to.Name);
     });
 }
Esempio n. 4
0
            public async Task <Result> Handle(Command command, CancellationToken ct)
            {
                var user = await _userManager.FindByIdAsync(_userSession.CurrentUserId.ToString());

                var result = await _userManager.ChangePasswordAsync(user, command.CurrentPassword, command.NewPassword);

                if (result.Succeeded == false)
                {
                    throw result.Errors.ToDomainException();
                }

                await _mailer.SendLaterAsync(new PasswordEditMail(user));

                return(new Result());
            }
Esempio n. 5
0
            public async Task <Result> Handle(Command request, CancellationToken ct)
            {
                var user = await _userManager.FindByEmailAsync(request.Email);

                // dont reveal that user exist
                if (user == null)
                {
                    return(new Result());
                }

                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                request.Code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                await _mailer.SendLaterAsync(new PasswordForgotMail(user, request));

                return(new Result());
            }
Esempio n. 6
0
            public async Task <Result> Handle(Command command, CancellationToken ct)
            {
                var user = await _userManager.FindByEmailAsync(command.Email);

                // if user does not exist don't tell the user
                if (user == null)
                {
                    return(new Result());
                }

                var result = await _userManager.ResetPasswordAsync(user, command.Code, command.Password);

                await _mailer.SendLaterAsync(new PasswordResetMail());

                if (result.Succeeded)
                {
                    return(new Result());
                }

                throw result.Errors.ToDomainException();
            }
Esempio n. 7
0
            public async Task <Result> Handle(Command request, CancellationToken ct)
            {
                // here is commented the steps a Handle usually does

                // fetch all entities or data. fail fast if some data doesn't exist
                var donor = await _db.Users.ByIdAsync(_userSession.CurrentUserId, ct);

                var project = await _db.Projects.ByIdOrFailAsync(request.ProjectId, ct);

                // create the entities, call entities' methods to set properties or to do domain validations
                var donation = new Donation(request, project, donor);

                // save entities, send emails, queue works or any work
                await _db.Donations.AddAsync(donation, ct);

                await _mailer.SendLaterAsync(new ThankMail(donation));

                return(new Result
                {
                    Project = project
                });
            }