Esempio n. 1
0
 public ThumbnailsDataWrapper(Guid userId, UserPhotoManager userPhotoManager)
 {
     Original = userPhotoManager.GetPhotoAbsoluteWebPath(userId);
     Retina   = userPhotoManager.GetRetinaPhotoURL(userId);
     Max      = userPhotoManager.GetMaxPhotoURL(userId);
     Big      = userPhotoManager.GetBigPhotoURL(userId);
     Medium   = userPhotoManager.GetMediumPhotoURL(userId);
     Small    = userPhotoManager.GetSmallPhotoURL(userId);
 }
 public ThumbnailsDataWrapper(Tenant tenant, Guid userId)
 {
     Original = UserPhotoManager.GetPhotoAbsoluteWebPath(tenant, userId);
     Retina   = UserPhotoManager.GetRetinaPhotoURL(tenant.TenantId, userId);
     Max      = UserPhotoManager.GetMaxPhotoURL(tenant.TenantId, userId);
     Big      = UserPhotoManager.GetBigPhotoURL(tenant.TenantId, userId);
     Medium   = UserPhotoManager.GetMediumPhotoURL(tenant.TenantId, userId);
     Small    = UserPhotoManager.GetSmallPhotoURL(tenant.TenantId, userId);
 }
        private void InitProfileFields(ProfileHelper profileHelper)
        {
            FirstName     = Profile.FirstName.HtmlEncode();
            LastName      = Profile.LastName.HtmlEncode();
            Email         = Profile.Email.HtmlEncode();
            Phone         = Profile.MobilePhone.HtmlEncode();
            Position      = Profile.Title.HtmlEncode();
            Place         = Profile.Location.HtmlEncode();
            Login         = Profile.UserName.HtmlEncode();
            Comment       = Profile.Notes.HtmlEncode();
            ProfileGender = Profile.Sex.HasValue ? Profile.Sex.Value ? "1" : "0" : "-1";
            PhotoPath     = UserPhotoManager.GetMaxPhotoURL(Profile.ID);
            WorkFromDate  = Profile.WorkFromDate.HasValue ? Profile.WorkFromDate.Value.ToShortDateString() : "";
            BirthDate     = Profile.BirthDate.HasValue ? Profile.BirthDate.Value.ToShortDateString() : "";
            Departments   = CoreContext.UserManager.GetUserGroups(Profile.ID);

            SocContacts = profileHelper.Contacts;

            OtherContacts = new List <MyContact>();
            OtherContacts.AddRange(profileHelper.Emails);
            OtherContacts.AddRange(profileHelper.Messengers);
            OtherContacts.AddRange(profileHelper.Phones);
        }
 public static string GetMaxPhotoURL(this UserInfo userInfo)
 {
     return(UserPhotoManager.GetMaxPhotoURL(userInfo.ID));
 }
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            var result = new FileUploadResult();

            try
            {
                if (context.Request.Files.Count != 0)
                {
                    Guid userId;
                    try
                    {
                        userId = new Guid(context.Request["userId"]);
                    }
                    catch
                    {
                        userId = SecurityContext.CurrentAccount.ID;
                    }
                    SecurityContext.DemandPermissions(new UserSecurityProvider(userId), Constants.Action_EditUser);

                    var userPhoto = context.Request.Files[0];

                    if (userPhoto.InputStream.Length > SetupInfo.MaxImageUploadSize)
                    {
                        result.Success = false;
                        result.Message = FileSizeComment.FileImageSizeExceptionString;
                        return(result);
                    }

                    var data = new byte[userPhoto.InputStream.Length];

                    var br = new BinaryReader(userPhoto.InputStream);
                    br.Read(data, 0, (int)userPhoto.InputStream.Length);
                    br.Close();

                    CheckImgFormat(data);

                    if (context.Request["autosave"] == "true")
                    {
                        if (data.Length > SetupInfo.MaxImageUploadSize)
                        {
                            throw new ImageSizeLimitException();
                        }

                        var mainPhoto = UserPhotoManager.SaveOrUpdatePhoto(userId, data);

                        result.Data =
                            new
                        {
                            main   = mainPhoto,
                            retina = UserPhotoManager.GetRetinaPhotoURL(userId),
                            max    = UserPhotoManager.GetMaxPhotoURL(userId),
                            big    = UserPhotoManager.GetBigPhotoURL(userId),
                            medium = UserPhotoManager.GetMediumPhotoURL(userId),
                            small  = UserPhotoManager.GetSmallPhotoURL(userId),
                        };
                    }
                    else
                    {
                        result.Data = UserPhotoManager.SaveTempPhoto(data, SetupInfo.MaxImageUploadSize, UserPhotoManager.OriginalFotoSize.Width, UserPhotoManager.OriginalFotoSize.Height);
                    }

                    result.Success = true;
                }
                else
                {
                    result.Success = false;
                    result.Message = PeopleResource.ErrorEmptyUploadFileSelected;
                }
            }
            catch (UnknownImageFormatException)
            {
                result.Success = false;
                result.Message = PeopleResource.ErrorUnknownFileImageType;
            }
            catch (ImageWeightLimitException)
            {
                result.Success = false;
                result.Message = PeopleResource.ErrorImageWeightLimit;
            }
            catch (ImageSizeLimitException)
            {
                result.Success = false;
                result.Message = PeopleResource.ErrorImageSizetLimit;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message.HtmlEncode();
            }

            return(result);
        }
Esempio n. 6
0
 public static string GetMaxPhotoURL(this UserInfo userInfo, int tenantId)
 {
     return(UserPhotoManager.GetMaxPhotoURL(tenantId, userInfo.ID));
 }
Esempio n. 7
0
        public EmployeeWraperFull GetFull(UserInfo userInfo)
        {
            var result = new EmployeeWraperFull
            {
                UserName         = userInfo.UserName,
                FirstName        = userInfo.FirstName,
                LastName         = userInfo.LastName,
                Birthday         = ApiDateTime.FromDate(TenantManager, TimeZoneConverter, userInfo.BirthDate),
                Status           = userInfo.Status,
                ActivationStatus = userInfo.ActivationStatus & ~EmployeeActivationStatus.AutoGenerated,
                Terminated       = ApiDateTime.FromDate(TenantManager, TimeZoneConverter, userInfo.TerminatedDate),
                WorkFrom         = ApiDateTime.FromDate(TenantManager, TimeZoneConverter, userInfo.WorkFromDate),
                Email            = userInfo.Email,
                IsVisitor        = userInfo.IsVisitor(UserManager),
                IsAdmin          = userInfo.IsAdmin(UserManager),
                IsOwner          = userInfo.IsOwner(Context.Tenant),
                IsLDAP           = userInfo.IsLDAP(),
                IsSSO            = userInfo.IsSSO()
            };

            Init(result, userInfo);

            if (userInfo.Sex.HasValue)
            {
                result.Sex = userInfo.Sex.Value ? "male" : "female";
            }

            if (!string.IsNullOrEmpty(userInfo.Location))
            {
                result.Location = userInfo.Location;
            }

            if (!string.IsNullOrEmpty(userInfo.Notes))
            {
                result.Notes = userInfo.Notes;
            }

            if (!string.IsNullOrEmpty(userInfo.MobilePhone))
            {
                result.MobilePhone = userInfo.MobilePhone;
            }

            result.MobilePhoneActivationStatus = userInfo.MobilePhoneActivationStatus;

            if (!string.IsNullOrEmpty(userInfo.CultureName))
            {
                result.CultureName = userInfo.CultureName;
            }

            FillConacts(result, userInfo);

            if (Context.Check("groups") || Context.Check("department"))
            {
                var groups = UserManager.GetUserGroups(userInfo.ID)
                             .Select(x => new GroupWrapperSummary(x, UserManager))
                             .ToList();

                if (groups.Count > 0)
                {
                    result.Groups     = groups;
                    result.Department = string.Join(", ", result.Groups.Select(d => d.Name.HtmlEncode()));
                }
                else
                {
                    result.Department = "";
                }
            }

            var userInfoLM = userInfo.LastModified.GetHashCode();

            if (Context.Check("avatarMax"))
            {
                result.AvatarMax = UserPhotoManager.GetMaxPhotoURL(userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
            }

            if (Context.Check("avatarMedium"))
            {
                result.AvatarMedium = UserPhotoManager.GetMediumPhotoURL(userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
            }

            if (Context.Check("avatar"))
            {
                result.Avatar = UserPhotoManager.GetBigPhotoURL(userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
            }

            if (Context.Check("listAdminModules"))
            {
                var listAdminModules = userInfo.GetListAdminModules(WebItemSecurity);

                if (listAdminModules.Any())
                {
                    result.ListAdminModules = listAdminModules;
                }
            }

            return(result);
        }
        public EmployeeWraperFull(UserInfo userInfo, ApiContext context)
            : base(userInfo, context)
        {
            UserName  = userInfo.UserName;
            FirstName = userInfo.FirstName;
            LastName  = userInfo.LastName;
            Birthday  = (ApiDateTime)userInfo.BirthDate;

            if (userInfo.Sex.HasValue)
            {
                Sex = userInfo.Sex.Value ? "male" : "female";
            }

            Status           = userInfo.Status;
            ActivationStatus = userInfo.ActivationStatus & ~EmployeeActivationStatus.AutoGenerated;
            Terminated       = (ApiDateTime)userInfo.TerminatedDate;

            WorkFrom = (ApiDateTime)userInfo.WorkFromDate;
            Email    = userInfo.Email;

            if (!string.IsNullOrEmpty(userInfo.Location))
            {
                Location = userInfo.Location;
            }

            if (!string.IsNullOrEmpty(userInfo.Notes))
            {
                Notes = userInfo.Notes;
            }

            if (!string.IsNullOrEmpty(userInfo.MobilePhone))
            {
                MobilePhone = userInfo.MobilePhone;
            }

            MobilePhoneActivationStatus = userInfo.MobilePhoneActivationStatus;

            if (!string.IsNullOrEmpty(userInfo.CultureName))
            {
                CultureName = userInfo.CultureName;
            }

            FillConacts(userInfo);

            if (context.Check("groups") || context.Check("department"))
            {
                var groups = CoreContext.UserManager.GetUserGroups(context.Tenant, userInfo.ID)
                             .Select(x => new GroupWrapperSummary(x, context))
                             .ToList();

                if (groups.Count > 0)
                {
                    Groups     = groups;
                    Department = string.Join(", ", Groups.Select(d => d.Name.HtmlEncode()));
                }
                else
                {
                    Department = "";
                }
            }

            var userInfoLM = userInfo.LastModified.GetHashCode();

            if (context.Check("avatarDefault"))
            {
                AvatarDefault = Convert.ToBase64String(CoreContext.UserManager.GetUserPhoto(context.Tenant.TenantId, userInfo.ID));
            }

            if (context.Check("avatarMax"))
            {
                AvatarMax = UserPhotoManager.GetMaxPhotoURL(context.Tenant.TenantId, userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
            }

            if (context.Check("avatarMedium"))
            {
                AvatarMedium = UserPhotoManager.GetMediumPhotoURL(context.Tenant.TenantId, userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
            }

            if (context.Check("avatar"))
            {
                Avatar = UserPhotoManager.GetBigPhotoURL(context.Tenant.TenantId, userInfo.ID, out var isdef) + (isdef ? "" : $"?_={userInfoLM}");
            }

            if (context.Check("listAdminModules"))
            {
                var listAdminModules = userInfo.GetListAdminModules(context.Tenant);

                if (listAdminModules.Any())
                {
                    ListAdminModules = listAdminModules;
                }
            }

            IsVisitor = userInfo.IsVisitor(context.Tenant);
            IsAdmin   = userInfo.IsAdmin(context.Tenant);
            IsOwner   = userInfo.IsOwner(context.Tenant);
            IsLDAP    = userInfo.IsLDAP();
            IsSSO     = userInfo.IsSSO();
        }