コード例 #1
0
        private IEnumerable <UserViewModel> GetUsersForPasswordReset()
        {
            var result = BaseCacheHelper.Get <List <UserViewModel> >("GetUsersForPasswordReset");

            if (result == null)
            {
                result = ADHelper.GetUsersForPasswordReset()
                         .Select(u => new UserViewModel
                {
                    ID       = u.SamAccountName,
                    FullName = (u.Name ?? string.Empty).Trim(),
                    //EmailAddress = (string.IsNullOrWhiteSpace(u.EmailAddress) ? (u.UserPrincipalName ?? string.Empty) : string.Empty),
                    MobileNumber = ADHelper.GetUserPhone(u) ?? string.Empty,
                    Department   = ADHelper.GetUserDepartment(u) ?? string.Empty
                }).ToList();

                BaseCacheHelper.Add("GetUsersForPasswordReset", result);
            }

            return(result);
        }
コード例 #2
0
        public ActionResult ChangePassword(string userName, bool requestPasswordChangeOnLogin)
        {
            try
            {
                var newPassword = new PasswordGenerator(8, 8, 6, 0).Generate();
                //var newPassword = Membership.GeneratePassword(8, 1);

                var user = ADHelper.FindByIdentity(userName);

                if (user == null)
                {
                    throw new Exception(userName + " მომხმარებელი ვერ მოიძებნა");
                }

                var mobile = ADHelper.GetUserPhone(user).ParseMobile();

                if (string.IsNullOrWhiteSpace(mobile))
                {
                    throw new Exception(userName + "-ს მობილური არ აქვს მითითებული!!!");
                }

                ADHelper.ChangeUserPassword(user, newPassword, requestPasswordChangeOnLogin);
                using (var db = new ADDBEntities())
                {
                    db.PasswordChanges.Add(new PasswordChange {
                        CreatorUsername = User.Identity.Name, Password = newPassword, Username = userName, SysDate = DateTime.Now
                    });
                    db.SaveChanges();
                }

                SendSMS(mobile, newPassword);

                return(Json(new { status = true, msg = "პაროლი წარმატებით შეიცვალა" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { status = false, msg = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }