Esempio n. 1
0
            public async Task <CommandResponse <User> > Handle(Command cmd, CancellationToken cancellationToken)
            {
                var r = await _storage.GetUserAssociation(cmd.Id.Value);

                if (r == null)
                {
                    return(CommandResponse <User> .Failed(
                               "Invalid password reset token. Check the link in the email or request a new password reset"));
                }

                if (r.IsOlderThan(15))
                {
                    return(CommandResponse <User> .Failed(
                               "Password reset link has expired. Please request a new password reset"));
                }

                var u = await _storage.GetUser(r.UserId);

                if (u == null)
                {
                    return(CommandResponse <User> .Failed(
                               "User account is no longer valid"));
                }

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

                u.SetPassword(hash.Hash, hash.Salt);

                await _storage.Save(u);

                return(CommandResponse <User> .Success(u));
            }
Esempio n. 2
0
            public async Task <CommandResponse <User> > Handle(Command cmd, CancellationToken cancellationToken)
            {
                var r = await _storage.GetUserAssociation(cmd.Id);

                if (r == null)
                {
                    return(CommandResponse <User> .Failed(
                               "Invalid confirmation identifier."));
                }

                if (r.IsOlderThan(60 * 24 * 30)) // 30 day expiration?
                {
                    return(CommandResponse <User> .Failed(
                               "Account confirmation link is expired. Please request a new one."));
                }

                var u = await _storage.GetUser(r.UserId);

                if (u == null)
                {
                    return(CommandResponse <User> .Failed(
                               "User account is no longer valid"));
                }

                u.Confirm();

                await _storage.Save(u);

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