コード例 #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);
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: Amangeldi/CRM
 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());
 }
コード例 #3
0
ファイル: AdminController.cs プロジェクト: Amangeldi/pharmacy
 public IActionResult GetCurrentAdmin()
 {
     return(Ok(userService.GetCurrent(User.Identity.Name)));
 }