public void Visit(IAuditableVisitor <Registration> logger, DbContext dbContext, string navigation) { var entry = dbContext.Entry(this); if (entry.State == EntityState.Added) { logger.LogChange($"{navigation} Felnőtt tartalom megjelenítése", NSFWContent); logger.LogChange($"{navigation} Helyi hír értesítések", RecieveLocalNewsAlerts); } if (entry.State == EntityState.Modified) { AuditHelpers.LogAttributeIfChanged(logger, entry, $"{navigation} Felnőtt tartalom megjelenítése", nameof(NSFWContent), NSFWContent); AuditHelpers.LogAttributeIfChanged(logger, entry, $"{navigation} Helyi hír értesítések", nameof(RecieveLocalNewsAlerts), RecieveLocalNewsAlerts); } foreach (var regionPref in RegionPreferences) { regionPref.Visit(logger, dbContext, "Régió preferenciák"); } var removed = dbContext.ChangeTracker .Entries <RegionPreference>() .Where(e => e.State == EntityState.Deleted && (int)e.Property(nameof(RegionPreference.Preferences) + "Id").OriginalValue == Id) .Select(e => e.Entity) .ToList(); foreach (var regionPref in removed) { regionPref.Visit(logger, dbContext, "Régió preferenciák"); } }
public PartialViewResult DeleteUserReturnPartialView(int userId) { ApplicationUserManager.DeleteUser(userId); ApplicationUser _user = ApplicationUserManager.GetUser(userId); AuditHelpers.AppEventInfo(AppSession.Profile.Id.ToString(), String.Format("Delete User \"{0}\"<{1}>", _user.UserName, _user.Email)); return(this.filterReset()); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { List <string> _errors = new List <string>(); try { RBACStatus _retVal = this.Login(model, this.UserManager, this.SignInManager, out _errors); switch (_retVal) { case RBACStatus.Success: { var user = UserManager.FindByName(model.UserName); Session["UserProfile"] = user; RBAC_ExtendedMethods.Parameters.RefreshAppParameters(); AuditHelpers.AppEventInfo(user.Id.ToString(), String.Format(AuditHelpers.MemberLoggedIn, user.UserName, user.Email)); return(RedirectToLocal(returnUrl)); } case RBACStatus.EmailUnconfirmed: { //Do nothing, message will be display on login page... break; } case RBACStatus.PhoneNumberUnconfirmed: { var user = UserManager.FindByName(model.UserName); if (user != null) { if (this.SendOTP2Phone(this.UserManager, user.Id, user.PhoneNumber)) { return(RedirectToAction("OTP4PhoneVerification", new { UserId = user.Id, phoneNumber = user.PhoneNumber, displayError = true })); } } break; } case RBACStatus.RequiresVerification: return(RedirectToAction("SendSecurityCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); } } catch (Exception ex) { AddErrors(new IdentityResult(ex.Message)); } if (_errors.Count() > 0) { AddErrors(new IdentityResult(_errors)); } } // If we reach this point, something failed, redisplay form displaying error message(s)... return(View(model)); }
private void Visit(IAuditableVisitor <Registration> logger, EntityEntry entityEntry) { if (entityEntry.State == EntityState.Added) { logger.LogChange("Email", Email); } if (entityEntry.State == EntityState.Modified) { AuditHelpers.LogAttributeIfChanged(logger, entityEntry, "Email", nameof(Email), Email); } }
public PartialViewResult DeleteUserRoleReturnPartialView(int id, int userId) { ApplicationUserManager.RemoveUser4Role(userId, id); SetViewBagData(userId); ApplicationUser _user = ApplicationUserManager.GetUser(userId); ApplicationRole _role = database.Roles.Where(p => p.Id == id).FirstOrDefault(); AuditHelpers.AppEventInfo(AppSession.Profile.Id.ToString(), String.Format("Remove User <{0}> from Role <{1}>", _user.UserName, _role.Name)); return(PartialView("_ListUserRoleTable", ApplicationUserManager.GetUser(userId))); }
public void Visit(IAuditableVisitor <Registration> logger, DbContext dbContext, string navigation) { var entry = dbContext.Entry(this); if (entry.State == EntityState.Added) { logger.LogChange("Fizetési mód", PaymentMethod); } else if (entry.State == EntityState.Modified) { AuditHelpers.LogAttributeIfChanged(logger, entry, "Fizetési mód", nameof(PaymentMethod), PaymentMethod); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { List <string> _errors = new List <string>(); try { RBACStatus _retVal = this.Register(model, this.UserManager, this.SignInManager, out _errors); switch (_retVal) { case RBACStatus.Success: { ViewBag.Message = "Your account has been created successfully. You can now continue and login..."; AuditHelpers.AppEventInfo(AppSession.Profile.Id.ToString(), String.Format("The Account \"{0}\"<{1}> account has be created succesfully", model.UserName, model.Email)); return(View("Confirmation")); } case RBACStatus.RequiresAccountActivation: { ViewBag.Username = model.UserName; ViewBag.Email = model.Email; return(View("ConfirmEmailSent")); } case RBACStatus.EmailVerification: { return(RedirectToAction("RequestEmailVerification", new { Username = model.UserName })); //return RedirectToAction("TOTPEmailVerification4Registration", new { UserId = model.Id, email = model.Email }); } case RBACStatus.PhoneVerification: { return(RedirectToAction("OTP4PhoneVerification", new { UserId = model.Id, phoneNumber = model.Mobile })); } } } catch (Exception ex) { AddErrors(new IdentityResult(ex.Message)); } if (_errors.Count() > 0) { AddErrors(new IdentityResult(_errors)); } } //If we got this far, something failed, redisplay form //Errors will be displayed back to the user because we have set the ModelState object with our _errors list... return(View(model)); }
public ActionResult UserEdit(UserViewModel user) { bool retval = ApplicationUserManager.UpdateUser(user); ApplicationUser _user = ApplicationUserManager.GetUser(user.Id); if (retval) { AuditHelpers.AppEventInfo("", String.Format("Success editing User \"{0}\"<{1}>", _user.UserName, _user.Email)); } else { AuditHelpers.AppEventInfo("", String.Format("Error editing User \"{0}\"<{1}>", _user.UserName, _user.Email)); } return(RedirectToAction("UserDetails", new RouteValueDictionary(new { id = user.Id }))); }
public void Visit(IAuditableVisitor <Registration> logger, DbContext dbContext, string navigation) { var huCulture = CultureInfo.GetCultures(CultureTypes.SpecificCultures).FirstOrDefault(c => c.Name == "hu"); var entry = dbContext.Entry(this); if (entry.State == EntityState.Added) { logger.LogChange($"{navigation} Téma", Theme.ToString()); logger.LogChange($"{navigation} Menü megjelenítése", HideMenu.ToString(huCulture)); } if (entry.State == EntityState.Modified) { AuditHelpers.LogAttributeIfChanged(logger, entry, $"{navigation} Téma", nameof(Theme), Theme); AuditHelpers.LogAttributeIfChanged(logger, entry, $"{navigation} Menü megjelenítése", nameof(HideMenu), HideMenu); } }
public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var _retVal = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); if (_retVal.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); } AuditHelpers.AppEventInfo(AppSession.Profile.Id.ToString(), String.Format(AuditHelpers.AccountPassChanged, user.UserName, user.Email)); return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess })); } AddErrors(_retVal); return(View(model)); }
public ActionResult LogOff() { AuditHelpers.AppEventInfo(AppSession.Profile.Id.ToString(), String.Format(AuditHelpers.MemberLogOut, this.User.Identity.Name, this.User.Identity.GetUserEmail())); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(RedirectToAction("Index", "Main")); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { AuditHelpers.Log(AuditingLevel); base.OnActionExecuting(filterContext); }
public static bool CustomSignIn(string userName, string password, bool RememberMeCheckBox) { ApplicationUserManager manager = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>(); ApplicationSignInManager signinManager = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationSignInManager>(); var user = manager.Find <ApplicationUser, string>(userName, password); if (user != null && user.Locked == false) { // Validate the user password IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication; //authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); ClaimsIdentity identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); //Claims added to ClaimsIdentity getting lost in ASP.NET Core Identity System //identity.AddClaim(new Claim("FullName", user.FullName ?? "")); //identity.AddClaim(new Claim("Email", user.Email ?? "")); //identity.AddClaim(new Claim("ImagePath", user.ImagePath ?? "")); identity.AddClaims(new[] { new Claim("FullName", user.FullName ?? ""), new Claim("Email", user.Email ?? ""), new Claim("ImagePath", user.ImagePath ?? ""), }); AuthenticationProperties props = new AuthenticationProperties(); props.IsPersistent = RememberMeCheckBox; authenticationManager.SignIn(props, identity); UserInfoVM userItem = new UserInfoVM() { UserName = user.UserName ?? "", FullName = user.FullName ?? "", Email = user.Email ?? "", ImagePath = user.ImagePath ?? "", Roles = string.Join(";", identity.Claims.Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value).ToList()), IsAuthenticated = identity.IsAuthenticated }; HttpContext.Current.Session["User"] = userItem; //HttpContext.Current.Session["User"] = user; // Mock user data // Nếu chọn lưu thông tin, đưa vào cookie if (RememberMeCheckBox == true) { HttpContext.Current.Response.Cookies["USERNAME"].Value = userName; HttpContext.Current.Response.Cookies["USERNAME"].Expires = DateTime.Now.AddMonths(1); HttpContext.Current.Response.Cookies["PASSWORD"].Value = password; HttpContext.Current.Response.Cookies["PASSWORD"].Expires = DateTime.Now.AddMonths(1); } // Nếu không chọn lưu thông tin, xóa cookie else { HttpContext.Current.Response.Cookies["USERNAME"].Expires = DateTime.Now.AddMonths(-1); HttpContext.Current.Response.Cookies["PASSWORD"].Expires = DateTime.Now.AddMonths(-1); } //chuyển đến trang chính của hệ thống //Context.User = mUserInfo; AuditHelpers.Log(0, identity.Name); return(true); } else { return(false); } }