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.
BWPM/APP/ViewComponents/UserStatusViewComponent.cs

48 lines
1.5 KiB

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Security.Claims;
using Microsoft.AspNetCore.Http;
using BWPMModels;
using App.Models;
using Microsoft.AspNetCore.Identity;
using APP.Models;
namespace APP.ViewComponents
{
public class UserStatusViewComponent : ViewComponent
{
private readonly UserManager<AppUser> _userManager;
private readonly SignInManager<AppUser> _signInManager;
public UserStatusViewComponent(UserManager<AppUser> userManager, SignInManager<AppUser> signInManager)
{
this._userManager = userManager;
this._signInManager = signInManager;
}
public async Task<IViewComponentResult> InvokeAsync()
{
if (_signInManager.IsSignedIn(HttpContext.User))
{
ViewBag.loggedin = "True";
ViewBag.username = _userManager.GetUserName(HttpContext.User);
}
else
{
ViewBag.loggedin = "false";
}
App.Helper.ParameterHelper ph = new App.Helper.ParameterHelper();
ViewBag.defaultuser = ph.GetParameter("DefaultUser");
ViewBag.defaultpassword = ph.GetParameter("DefaultPassword");
return await Task.FromResult((IViewComponentResult)View("UserStatus"));
}
[HttpPost]
public async Task<IActionResult> Login(LoginViewModel model)
{
return (IActionResult)View(model);
}
}
}