コード例 #1
0
        /// <inheritdoc/>
        public async Task <Guid> LoginAsync(UserLoginModel loginModel, CancellationToken cancellationToken)
        {
            using (var scope = _serviceProvider.CreateScope())
                using (var context = scope.ServiceProvider.GetRequiredService <DatabaseContext>())
                {
                    var user = await context.Users
                               .AsNoTracking()
                               .FirstOrDefaultAsync(
                        x => x.Email == loginModel.Login &&
                        x.Password == _cryptoProvider.EncodeValue(loginModel.Password), cancellationToken)
                               .ConfigureAwait(false);

                    if (user == null)
                    {
                        throw new InvalidDataException("Invalid email and password");
                    }

                    return(user.Id);
                }
        }