public override void OnActionExecuting(ActionExecutingContext filterContext) { string cultureName; // Attempt to read the culture cookie from Request HttpCookie cultureCookie = filterContext.HttpContext.Request.Cookies["_culture"]; if (cultureCookie != null) { cultureName = cultureCookie.Value; } else { cultureName = "vi-VN"; } Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(cultureName); //Check login var currentUser = filterContext.HttpContext.Session["User"] == null ? null : (BriefUser)filterContext.HttpContext.Session["User"]; if (currentUser == null) { var code = filterContext.HttpContext.Request.Cookies["_code"]; var pwd = filterContext.HttpContext.Request.Cookies["_emm"]; if (code != null && pwd != null) { var userName = HttpUtility.UrlDecode(code.Value); var user = db.Users.FirstOrDefault(item => item.UserName.ToLower().Equals(userName.ToLower())); var pass = HttpUtility.UrlDecode(pwd.Value); try { if (!Common.ATIDecrypt(pass).Equals(Common.MD5Endcoding(user.Password).ToLower())) { base.OnActionExecuting(filterContext); return; } currentUser = new BriefUser { Id = user.ID, UserName = user.UserName, FullName = user.FullName, Image = user.Image }; filterContext.HttpContext.Session["User"] = currentUser; } catch (Exception) { filterContext.HttpContext.Session["User"] = null; } } } filterContext.Controller.ViewBag.CurrentUser = currentUser; base.OnActionExecuting(filterContext); }
private async Task <EmailModel> LoadAsync(BriefUser user, string status = "") { EmailModel userInfo = new EmailModel { Email = await _userManager.GetEmailAsync(user), NewEmail = "", StatusMessage = status, IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user) }; return(userInfo); }
public async Task <IActionResult> MakeAdmin(string email) { BriefUser user = await _userManager.FindByEmailAsync(email); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } await _userManager.AddToRoleAsync(user, "Admin"); return(View("Index")); }
public ScopeContext(IHttpContextAccessor contextAccessor) { CurrentUser = contextAccessor.HttpContext.GetCurrentUser(); }