Ejemplo n.º 1
0
        public async Task <LoginResult> Login(LoginModel loginModel)
        {
            var loginAsJson = JsonSerializer.Serialize(loginModel);
            var response    = await _httpClient.PostAsync("Login", new StringContent(loginAsJson, Encoding.UTF8, "application/json"));

            var loginResult = JsonSerializer.Deserialize <LoginResult>(await response.Content.ReadAsStringAsync(), new JsonSerializerOptions {
                PropertyNameCaseInsensitive = true
            });

            if (!response.IsSuccessStatusCode)
            {
                return(loginResult);
            }

            await _localStorage.SetItemAsync("authToken", loginResult.Token);

            ((ApiAuthenticationStateProvider)_authenticationStateProvider).MarkUserAsAuthenticated(loginModel.Email);
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", loginResult.Token);

            _tempService.CurrentUser = await _userRegistrationService.GetCurrent(loginModel.Email);

            User user = await _userManager.FindByEmailAsync(loginModel.Email);

            LogDTO logDTO = new LogDTO
            {
                Action = "Успешно авторизовался",
                UserId = user.Id
            };
            await _logService.AddLog(logDTO);

            return(loginResult);
        }
Ejemplo n.º 2
0
 public async Task <IActionResult> Index()
 {
     if (User.Identity.IsAuthenticated)
     {
         tempServ.CurrentUser = await userRegistrationServ.GetCurrent(User.Identity.Name);
     }
     ViewData["Title"]   = "Титуль";
     ViewData["footer"]  = "Футер";
     ViewData["sidebar"] = "";
     ViewData["header"]  = "Хедр";
     //ViewData["companies"] = await companyServ.GetCompanies();
     return(View());
 }
Ejemplo n.º 3
0
 public IActionResult GetCurrentAdmin()
 {
     return(Ok(userService.GetCurrent(User.Identity.Name)));
 }