示例#1
0
            public async Task <CommandResponse <User> > Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await _storage.GetUserByEmail(request.Email);

                if (user == null)
                {
                    return(CommandResponse <User> .Failed(GENERIC_MSG));
                }

                // oauth path where password was not set....
                if (!user.State.IsPasswordAvailable)
                {
                    return(CommandResponse <User> .Failed(GENERIC_MSG));
                }

                var computed = _hash.Generate(request.Password, user.State.GetSalt());

                var matches = user.PasswordHashMatches(computed);

                if (matches)
                {
                    user.LoggedIn(request.IPAddress, DateTimeOffset.UtcNow);

                    await _storage.Save(user);

                    return(CommandResponse <User> .Success(user));
                }

                return(CommandResponse <User> .Failed(GENERIC_MSG));
            }
示例#2
0
            public async Task <Guid?> Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await _storage.GetUserByEmail(request.Email);

                if (user == null)
                {
                    return(null);
                }
                return(user.State.Id);
            }
示例#3
0
            public async Task <CommandResponse <User> > Handle(Command cmd, CancellationToken cancellationToken)
            {
                var exists = await _storage.GetUserByEmail(cmd.Email);

                if (exists != null)
                {
                    return(CommandResponse <User> .Failed($"Account with {cmd.Email} already exists"));
                }

                return(CommandResponse <User> .Success(null));
            }
示例#4
0
            public async Task <Guid> Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await _storage.GetUserByEmail(request.Email);

                if (user == null)
                {
                    user = new User(request.Email, request.Firstname, request.Lastname);
                    await _storage.Save(user);
                }
                return(user.State.Id);
            }
示例#5
0
            public async Task <CommandResponse> Handle(Request request, CancellationToken cancellationToken)
            {
                var user = await _storage.GetUserByEmail(request.Email);

                if (user == null)
                {
                    // not really success, but we are not going to disclose
                    // if user account exists for a given email
                    return(CommandResponse.Success());
                }

                user.RequestPasswordReset(DateTimeOffset.UtcNow);

                await _storage.Save(user);

                return(CommandResponse.Success());
            }
示例#6
0
            public async Task <CommandResponse <User> > Handle(Command cmd, CancellationToken cancellationToken)
            {
                var exists = await _storage.GetUserByEmail(cmd.UserInfo.Email);

                if (exists != null)
                {
                    return(CommandResponse <User> .Failed($"Account with {cmd.UserInfo} already exists"));
                }

                var u = new User(cmd.UserInfo.Email, cmd.UserInfo.Firstname, cmd.UserInfo.Lastname);

                var(hash, salt) = _hash.Generate(cmd.UserInfo.Password, 32);

                u.SetPassword(hash, salt);

                if (cmd.PaymentInfo != null)
                {
                    var result = _subscriptions.Create(
                        u,
                        planId: cmd.PaymentInfo.PlanId,
                        paymentToken: cmd.PaymentInfo.Token.Id,
                        email: cmd.PaymentInfo.Token.Email);

                    if (result.CustomerId != null)
                    {
                        u.SubscribeToPlan(cmd.PaymentInfo.PlanId, result.CustomerId, result.SubscriptionId);
                    }
                    else
                    {
                        return(CommandResponse <User> .Failed(
                                   $"Failed to process the payment, please try again or use a different payment form"
                                   ));
                    }
                }

                await _storage.Save(u);

                return(CommandResponse <User> .Success(u));
            }