services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/User/SignIn";
options.AccessDeniedPath = "/User/SignIn";
options.ExpireTimeSpan = TimeSpan.MaxValue;
options.SlidingExpiration = true;
});
services.AddAuthorization();
options.SlidingExpiration = true;
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/User/SignIn";
options.AccessDeniedPath = "/User/SignIn";
options.ExpireTimeSpan = TimeSpan.MaxValue;
options.SlidingExpiration = true;
});
services.AddAuthorization();
public class AuthenticationService : IAuthenticationService
{
private readonly IHttpContextAccessor _accessor;
public AuthenticationService(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
public void SignIn(UserEntity userEntity)
{
List<Claim> claims = new List<Claim>()
{
new Claim(ClaimsIdentity.DefaultNameClaimType, userEntity.Login),
new Claim(ClaimsIdentity.DefaultRoleClaimType, userEntity.Type.ToString()),
new Claim(ClaimTypes.Email, userEntity.Email),
};
ClaimsIdentity identity = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
_accessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));
}
[IgnoreAntiforgeryToken]
[HttpPost]
public async Task<IActionResult> SignIn([FromBody]SignInViewModel viewModel)
{
if (!ModelState.IsValid)
{
return BadRequest(new { responseMessage = "Invalid data" });
}
var userList = _userService.GetByLoginAndPass(viewModel.Login, viewModel.Password);
if (userList.Count == 0)
{
return NotFound(new { responseMessage = "User not found" });
}
UserEntity userEntity = userList[0];
_authenticationService.SignIn(userEntity);
return Ok(new { responseMessage = "Success" });
}
// Считываем количество чисел из разных текстбоксов
int pisitiveNumber = int.Parse(textBox1.Text);
int negativeNumber = int.Parse(textBox2.Text);
// Переменная для рандома
Random random = new Random();
// Генерация и вывод положительных чисел
for (int i = 0; i < positiveNumber; i++) {
listBox1.Items.Add(random.Next(0, 10));
}
// Генерация и вывод отрицательных чисел
for (int i = 0; i < negativeNumber; i++) {
listBox1.Items.Add(random.Next(-10, 0));
}
mas2[i] = rnd.Next(0, -11);