Example #1
0
        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());
        }
Example #2
0
        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));
        }
Example #3
0
        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)));
        }
Example #4
0
        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));
        }
Example #5
0
        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 })));
        }
Example #6
0
        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));
        }
Example #7
0
 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"));
 }