Exemplo n.º 1
0
        public async Task <ActionResult> ResetPassword(int id)
        {
            BL.UserInfo empBL = new BL.UserInfo();
            if (empBL.GetItemByIdForDelete(id) != null)
            {
                return(Redirect(Url.Action("HttpError", "Error", new { area = "" })));
            }
            IPasswordPolicy Password        = new RandomPassword();
            string          orginalPassword = Password.GeneratePassword();

            orginalPassword = "******";
            string md5Password = HashEncrypt.MD5(orginalPassword);

            VM.UserInfoItem model = new VM.UserInfoItem();
            model = empBL.GetItemById(id);
            //IdentityModel user = await UserManager.FindByNameAsync(model.LogonName);
            //string password = UserManager.PasswordHasher.HashPassword(md5Password);
            //UserStore store = new UserStore(UserHelper.GetCurrentUser().LogonName);
            //var set = store.SetPasswordHashAsync(user, password);
            //var result = store.UpdateAsync(user);

            model.Password = md5Password;
            empBL.UpdatePasswordDb(model);
            if (model != null)
            {
                // empBL.SendEmail(model, orginalPassword, "User_ResetPassword");
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        //[AllowAnonymous]
        public async Task <ActionResult> Create(VM.UserInfoItem model)
        {
            BL.UserInfo empBL = new BL.UserInfo();
            if (empBL.ValidateName(-1, model.LogonName))
            {
                return(Content(ResourceHelper.GetValue("SMM_UserInfo_SameLogonName")));
            }
            if (!new EmailExAttribute().IsValid(model.EmailAddress))
            {
                return(Content("False"));
            }
            var user = new IdentityModel();

            user.UserName            = model.LogonName;
            user.LogonName           = model.UserName;
            user.StrStatus           = model.StrStatus;
            user.RoleId              = model.RoleId;
            user.UserCompangValue    = model.UserCompanyValue;
            user.UserGasStationValue = model.UserGasStationValue;
            user.DomainAccount       = model.DomainAccount;
            user.EmailAddress        = model.EmailAddress;
            user.CreateBy            = "sysAdmin";//UserHelper.GetCurrentUser().LogonName;
            IPasswordPolicy Password        = new RandomPassword();
            string          orginalPassword = Password.GeneratePassword();
            string          md5Password     = HashEncrypt.MD5(orginalPassword);
            var             result          = await UserManager.CreateAsync(user, md5Password);

            if (result.Succeeded)
            {
                if (user.StrStatus == "1")
                {
                    //empBL.SendEmail(model, orginalPassword, "User_New");
                }
                return(Content("Success"));
            }

            return(Content("False"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> UserRests(string Email, string UserName)
        {
            BL.Login empBL = new BL.Login();
            if (empBL.ValiableEmail(Email, UserName) == "true")
            {
                return(Json("validateEmail", JsonRequestBehavior.AllowGet));
            }
            else if (empBL.ValiableEmail(Email, UserName) == "error")
            {
                return(Json("error", JsonRequestBehavior.AllowGet));
            }
            UserInfo userBL = new UserInfo();

            IPasswordPolicy Password        = new RandomPassword();
            string          orginalPassword = Password.GeneratePassword();
            string          md5Password     = HashEncrypt.MD5(orginalPassword);
            UserInfoItem    model           = new UserInfoItem();

            model = userBL.GetItemByName(UserName);
            IdentityModel user = await UserManager.FindByNameAsync(UserName);

            string    password = UserManager.PasswordHasher.HashPassword(md5Password);
            UserStore store    = new UserStore();
            var       set      = store.SetPasswordHashAsync(user, password);
            var       results  = store.UpdateAsync(user);

            if (results != null)
            {
                userBL.SendEmail(model, orginalPassword, "User_ResetPassword");
                return(Json("true", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("false", JsonRequestBehavior.AllowGet));
            }
        }