コード例 #1
0
        public IHttpActionResult GetUserInfo()
        {
            int userId = ControllerContext.GetAuthUserId();

            // clear temp file
            try
            {
                string userFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\";
                if (!Directory.Exists(userFolder))
                {
                    Directory.CreateDirectory(userFolder);
                }
                if (!Directory.Exists(userFolder + @"\thumbnail\"))
                {
                    Directory.CreateDirectory(userFolder + @"\thumbnail\");
                }

                DirectoryInfo dInfo = new DirectoryInfo(userFolder);
                foreach (FileInfo fInfo in dInfo.GetFiles())
                {
                    if (fInfo.CreationTime.AddDays(1).CompareTo(DateTime.Now) < 0)
                    {
                        File.Delete(fInfo.FullName);
                    }
                }

                dInfo = new DirectoryInfo(userFolder + @"\thumbnail\");
                foreach (FileInfo fInfo in dInfo.GetFiles())
                {
                    if (fInfo.CreationTime.AddDays(1).CompareTo(DateTime.Now) < 0)
                    {
                        File.Delete(fInfo.FullName);
                    }
                }
            }
            catch { }
            //

            BLL.AccountMng           bll = new BLL.AccountMng();
            Library.DTO.Notification notification;
            DTO.AccountMng.User      userInfo = bll.GetUserInformation(userId, out notification);

            // implement mem cache - clear memcache
            Library.CacheHelper.ClearCache(Library.CacheHelper.USER_DATA + userId.ToString());

            if (notification.Type == Library.DTO.NotificationType.Error)
            {
                return(InternalServerError(new Exception(notification.Message)));
            }
            return(Ok(new Library.DTO.ReturnData <DTO.AccountMng.User>()
            {
                Data = userInfo, Message = notification
            }));
        }
コード例 #2
0
        public bool ResetPassword(string userName, string newPassword)
        {
            String                   hashedNewPassword = _userMng.PasswordHasher.HashPassword(newPassword);
            var                      hashResult        = _userMng.PasswordHasher.VerifyHashedPassword(hashedNewPassword, newPassword);
            IdentityUser             cUser             = _userMng.FindByName(userName);
            UserStore <IdentityUser> store             = new UserStore <IdentityUser>();

            cUser.PasswordHash = hashedNewPassword;
            _userMng.Update(cUser);

            // password change compleled update last password change
            BLL.AccountMng accBll = new BLL.AccountMng();
            accBll.UpdateLastPasswordChange(cUser.Id);

            return(true);
        }
コード例 #3
0
        public IHttpActionResult GetUsers(DTO.Search iSearch)
        {
            BLL.AccountMng           bll = new BLL.AccountMng();
            Library.DTO.Notification notification;
            int TotalRows = 0;

            List <DTO.AccountMng.User> users = bll.GetUserInformationWithFilter(ControllerContext.GetAuthUserId(), iSearch.Filters, iSearch.SortedBy, iSearch.SortedDirection, iSearch.PageSize, iSearch.PageIndex, out TotalRows, out notification);

            if (notification.Type == Library.DTO.NotificationType.Error)
            {
                return(InternalServerError(new Exception(notification.Message)));
            }
            return(Ok(new Library.DTO.ReturnData <List <DTO.AccountMng.User> >()
            {
                Data = users, TotalRows = TotalRows, Message = notification
            }));
        }
コード例 #4
0
        public bool ChangePassword(string userName, string newPassword, string oldPassword, out string errMsg)
        {
            errMsg = string.Empty;
            try
            {
                if (newPassword == oldPassword)
                {
                    throw new Exception("New password can not be the same as old password!");
                }

                IdentityUser   cUser  = _userMng.FindByName(userName);
                IdentityResult result = _userMng.ChangePassword(cUser.Id, oldPassword, newPassword);
                if (result.Errors.Count() > 0)
                {
                    foreach (string msg in result.Errors)
                    {
                        if (!string.IsNullOrEmpty(errMsg))
                        {
                            errMsg += Environment.NewLine + msg;
                        }
                        else
                        {
                            errMsg += msg;
                        }
                    }
                    throw new Exception(errMsg);
                }

                // password change compleled update last password change
                BLL.AccountMng accBll = new BLL.AccountMng();
                accBll.UpdateLastPasswordChange(cUser.Id);
            }
            catch
            {
                return(false);
            }

            return(true);
        }