public async Task <IActionResult> CheckIn(LogInViewModel model)
        {
            var user = AutheticationService.CheckPassword(model.Email, model.Password);

            if (user == null)
            {
                return(Unauthorized());
            }

            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, user.Name),
                new Claim(ClaimTypes.Email, user.Email),
                new Claim("AuthorizedPersonType", user.AuthorizedPersonType.ToString()),
            };

            if (user.AuthorizedPersonType == Data.AuthorizedPersonType.Guest)
            {
                claims.Add(new Claim("RoomNumber", new Random().Next(10, 55).ToString()));
            }

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

            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal
                                          , new AuthenticationProperties { IsPersistent = model.RememberLogin });

            return(LocalRedirect(model.ReturnUrl));
        }
Exemplo n.º 2
0
        protected override async Task OnParametersSetAsync()
        {
            var authState = await authenticationStateTask;

            if (authState.User.Identity.IsAuthenticated)
            {
                Navigation.NavigateTo("Index");
            }
            else
            {
                var url = Navigation.Uri;

                var result = await AutheticationService.LoginUser(url);

                if (result)
                {
                    Navigation.NavigateTo("Index");
                }
            }
        }