You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							42 lines
						
					
					
						
							1.3 KiB
						
					
					
				
			
		
		
	
	
							42 lines
						
					
					
						
							1.3 KiB
						
					
					
				| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Security.Claims;
 | |
| using System.Threading.Tasks;
 | |
| using Microsoft.AspNetCore.Authentication;
 | |
| using Microsoft.AspNetCore.Authentication.Cookies;
 | |
| using Microsoft.AspNetCore.Authorization;
 | |
| using Microsoft.AspNetCore.Mvc;
 | |
| using Microsoft.AspNetCore.Mvc.RazorPages;
 | |
| using TestApp02.Data;
 | |
| 
 | |
| namespace BlazorCookieAuth.Server.Pages
 | |
| {
 | |
|     [AllowAnonymous]
 | |
|     public class LoginModel : PageModel
 | |
|     {
 | |
|         public string ReturnUrl { get; set; }
 | |
| 
 | |
|         private readonly BiudAuthService _biudAuthService;
 | |
| 
 | |
|         public LoginModel(BiudAuthService pbiudAuthService)
 | |
|         {
 | |
|             _biudAuthService= pbiudAuthService;
 | |
|         }
 | |
| 
 | |
|         public async Task<IActionResult> OnGetAsync(string paramUsername, string paramPassword)
 | |
|         {
 | |
|             string returnUrl = Url.Content("~/");
 | |
| 
 | |
|             if (ModelState.IsValid)
 | |
|             {
 | |
|                 ClaimsPrincipal claimsPrincipal = _biudAuthService.AuthenticateUser(paramUsername, paramPassword);
 | |
| 
 | |
|                 _biudAuthService.Users.Add(paramUsername,claimsPrincipal);
 | |
|                 await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal);
 | |
|                 return LocalRedirect(returnUrl);
 | |
|             }
 | |
|             return Page();
 | |
| 
 | |
|         }
 | |
|     }
 | |
| } |