Пример #1
0
        public IActionResult OnGet(string errorMessage = "", string successMessage = "")
        {
            ErrorMessage   = errorMessage;
            SuccessMessage = successMessage;

            var email = Request.Cookies["EmailCookie"];

            Account = _accountServiceProvider.Get(email);

            ReviewsReceived = _reviewServiceProvider.GetAllByReviewee(email);
            ReviewsGiven    = _reviewServiceProvider.GetAllByReviewer(email);

            return(Page());
        }
Пример #2
0
        public async Task <IActionResult> OnPostLoginAsync(
            [FromForm] string email,
            [FromForm] string password)
        {
            var token = _accountServiceProvider.Login(email, password);

            if (string.IsNullOrEmpty(token))
            {
                return(RedirectToPage("Index", new { loginFail = true }));
            }

            var account = _accountServiceProvider.Get(email);

            // Create the identity from the user info
            var claims = new List <Claim> {
                new Claim(ClaimTypes.NameIdentifier, email),
                new Claim(ClaimTypes.Role, "User")
            };

            var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

            // Authenticate using the identity
            var principal = new ClaimsPrincipal(identity);
            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

            //Values stored in the cookies for 12 months
            var cookieOptions = new CookieOptions
            {
                Expires = DateTime.Now.AddMonths(12),
                Secure  = true
            };

            Response.Cookies.Append("EmailCookie", $"{account.Email}", cookieOptions);
            Response.Cookies.Append("FirstNameCookie", $"{account.FirstName}", cookieOptions);
            Response.Cookies.Append("LastNameCookie", $"{account.LastName}", cookieOptions);
            Response.Cookies.Append("DateOfBirthCookie", $"{account.DateOfBirth}", cookieOptions);
            Response.Cookies.Append("PhoneCookie", $"{account.Phone}", cookieOptions);
            Response.Cookies.Append("TokenCookie", $"{token}", cookieOptions);

            return(RedirectToPage("Miscellaneous/MainLoggedIn"));
        }