Esempio n. 1
0
        private static CommentInfo GetCommentInfo(Comment comment, bool isPreview)
        {
            var info = new CommentInfo
            {
                CommentID       = comment.ID.ToString(),
                UserID          = comment.UserID,
                TimeStamp       = comment.Datetime,
                TimeStampStr    = comment.Datetime.Ago(),
                IsRead          = true,
                Inactive        = comment.Inactive,
                CommentBody     = HtmlUtility.GetFull(comment.Content),
                UserFullName    = DisplayUserSettings.GetFullUserName(comment.UserID),
                UserProfileLink = CommonLinkUtility.GetUserProfile(comment.UserID),
                UserAvatarPath  = UserPhotoManager.GetBigPhotoURL(comment.UserID),
                UserPost        = CoreContext.UserManager.GetUsers(comment.UserID).Title
            };

            if (!isPreview)
            {
                info.IsEditPermissions = CommunitySecurity.CheckPermissions(comment, ASC.Blogs.Core.Constants.Action_EditRemoveComment);

                info.IsResponsePermissions = CommunitySecurity.CheckPermissions(comment.Post, ASC.Blogs.Core.Constants.Action_AddComment);
            }

            return(info);
        }
Esempio n. 2
0
        private static List <CommentInfo> BuildCommentsList(Post post, List <Comment> loaded, Guid parentId)
        {
            var result = new List <CommentInfo>();

            foreach (var comment in Comment.SelectChildLevel(parentId, loaded))
            {
                var info = new CommentInfo
                {
                    CommentID             = comment.ID.ToString(),
                    UserID                = comment.UserID,
                    TimeStamp             = comment.Datetime,
                    TimeStampStr          = comment.Datetime.Ago(),
                    IsRead                = true,
                    Inactive              = comment.Inactive,
                    CommentBody           = comment.Content,
                    UserFullName          = DisplayUserSettings.GetFullUserName(comment.UserID),
                    UserProfileLink       = CommonLinkUtility.GetUserProfile(comment.UserID),
                    UserAvatarPath        = UserPhotoManager.GetBigPhotoURL(comment.UserID),
                    UserPost              = CoreContext.UserManager.GetUsers(comment.UserID).Title,
                    IsEditPermissions     = CommunitySecurity.CheckPermissions(comment, Constants.Action_EditRemoveComment),
                    IsResponsePermissions = CommunitySecurity.CheckPermissions(post, Constants.Action_AddComment),
                    CommentList           = BuildCommentsList(post, loaded, comment.ID)
                };

                result.Add(info);
            }
            return(result);
        }
Esempio n. 3
0
 private static object PrepareUserInfo(UserInfo userInfo)
 {
     return(new
     {
         id = userInfo.ID,
         displayName = DisplayUserSettings.GetFullUserName(userInfo),
         title = userInfo.Title,
         avatarSmall = UserPhotoManager.GetSmallPhotoURL(userInfo.ID),
         avatarBig = UserPhotoManager.GetBigPhotoURL(userInfo.ID),
         profileUrl = CommonLinkUtility.ToAbsolute(CommonLinkUtility.GetUserProfile(userInfo.ID.ToString(), false)),
         groups = CoreContext.UserManager.GetUserGroups(userInfo.ID).Select(x => new
         {
             id = x.ID,
             name = x.Name,
             manager = CoreContext.UserManager.GetUsers(CoreContext.UserManager.GetDepartmentManager(x.ID)).UserName
         }).ToList(),
         isPending = userInfo.ActivationStatus == EmployeeActivationStatus.Pending,
         isActivated = userInfo.ActivationStatus == EmployeeActivationStatus.Activated,
         isVisitor = userInfo.IsVisitor(),
         isOutsider = userInfo.IsOutsider(),
         isAdmin = userInfo.IsAdmin(),
         isOwner = userInfo.IsOwner(),
         contacts = GetContacts(userInfo),
         created = userInfo.CreateDate,
         email = userInfo.Email,
         isLDAP = userInfo.Sid != null
     });
 }
Esempio n. 4
0
        public static CommentInfo ConvertComment(Comment comment, IList <Comment> commentList)
        {
            var userID = comment.UserID;

            var c = new CommentInfo
            {
                CommentID             = comment.ID.ToString(),
                UserID                = userID,
                TimeStamp             = comment.Datetime,
                TimeStampStr          = comment.Datetime.Ago(),
                Inactive              = comment.Inactive,
                CommentBody           = HtmlUtility.GetFull(comment.Content),
                UserFullName          = DisplayUserSettings.GetFullUserName(userID),
                UserProfileLink       = CommonLinkUtility.GetUserProfile(userID),
                UserAvatarPath        = UserPhotoManager.GetBigPhotoURL(userID),
                IsEditPermissions     = BookmarkingPermissionsCheck.PermissionCheckEditComment(comment),
                IsResponsePermissions = BookmarkingPermissionsCheck.PermissionCheckCreateComment(),
                UserPost              = BookmarkingServiceHelper.GetUserInfo(userID).Title
            };

            var commentsList = new List <CommentInfo>();

            var childComments = GetChildComments(comment, commentList);

            if (childComments != null)
            {
                foreach (var item in childComments)
                {
                    commentsList.Add(ConvertComment(item, commentList));
                }
            }
            c.CommentList = commentsList;
            return(c);
        }
Esempio n. 5
0
 private static object PrepareUserInfo(UserInfo userInfo)
 {
     return(new
     {
         id = userInfo.ID,
         displayName = DisplayUserSettings.GetFullUserName(userInfo),
         title = userInfo.Title,
         avatarSmall = UserPhotoManager.GetSmallPhotoURL(userInfo.ID),
         avatarBig = UserPhotoManager.GetBigPhotoURL(userInfo.ID),
         profileUrl = CommonLinkUtility.ToAbsolute(CommonLinkUtility.GetUserProfile(userInfo.ID.ToString(), false)),
         groups = CoreContext.UserManager.GetUserGroupsId(userInfo.ID),
         isPending = userInfo.ActivationStatus == EmployeeActivationStatus.Pending,
         isActivated = userInfo.ActivationStatus.HasFlag(EmployeeActivationStatus.Activated),
         isVisitor = userInfo.IsVisitor(),
         isOutsider = userInfo.IsOutsider(),
         isAdmin = userInfo.IsAdmin(),
         isOwner = userInfo.IsOwner(),
         contacts = GetContacts(userInfo),
         created = userInfo.CreateDate,
         email = userInfo.Email,
         isLDAP = userInfo.IsLDAP(),
         isSSO = userInfo.IsSSO(),
         isTerminated = userInfo.Status == EmployeeStatus.Terminated
     });
 }
Esempio n. 6
0
        protected override IEnumerable <KeyValuePair <string, object> > GetClientVariables(HttpContext context)
        {
            var currentProject = "0";

            if (context.Request.GetUrlRewriter() != null)
            {
                currentProject = HttpUtility.ParseQueryString(context.Request.GetUrlRewriter().Query)["prjID"];

                if (string.IsNullOrEmpty(currentProject) && context.Request.UrlReferrer != null)
                {
                    currentProject = HttpUtility.ParseQueryString(context.Request.UrlReferrer.Query)["prjID"];
                }
            }
            using (var scope = DIHelper.Resolve())
            {
                var engineFactory = scope.Resolve <EngineFactory>();

                var team = engineFactory.ProjectEngine.GetTeam(Convert.ToInt32(currentProject))
                           .Select(r => new
                {
                    id          = r.UserInfo.ID,
                    displayName = DisplayUserSettings.GetFullUserName(r.UserInfo.ID),
                    email       = r.UserInfo.Email,
                    userName    = r.UserInfo.UserName,
                    avatarSmall = UserPhotoManager.GetSmallPhotoURL(r.UserInfo.ID),
                    avatar      = UserPhotoManager.GetBigPhotoURL(r.UserInfo.ID),
                    status      = r.UserInfo.Status,
                    groups      = CoreContext.UserManager.GetUserGroups(r.UserInfo.ID).Select(x => new
                    {
                        id      = x.ID,
                        name    = x.Name,
                        manager =
                            CoreContext.UserManager.GetUsers(CoreContext.UserManager.GetDepartmentManager(x.ID))
                            .UserName
                    }).ToList(),
                    isVisitor         = r.UserInfo.IsVisitor(),
                    isAdmin           = r.UserInfo.IsAdmin(),
                    isOwner           = r.UserInfo.IsOwner(),
                    isManager         = r.IsManager,
                    canReadFiles      = r.CanReadFiles,
                    canReadMilestones = r.CanReadMilestones,
                    canReadMessages   = r.CanReadMessages,
                    canReadTasks      = r.CanReadTasks,
                    canReadContacts   = r.CanReadContacts,
                    title             = r.UserInfo.Title,
                    profileUrl        = r.UserInfo.GetUserProfilePageURL()
                }).OrderBy(r => r.displayName).ToList();

                return(new List <KeyValuePair <string, object> >(1)
                {
                    RegisterObject(
                        new
                    {
                        Team = new { response = team },
                        projectFolder = engineFactory.FileEngine.GetRoot(Convert.ToInt32(currentProject))
                    })
                });
            }
        }
Esempio n. 7
0
        public void ProcessRequest(HttpContext context)
        {
            if (string.IsNullOrEmpty(context.Request["userId"])) return;

            var userId = context.Request.QueryString["userId"];
            context.Response.ContentType = "image";
            context.Response.Redirect(UserPhotoManager.GetBigPhotoURL(new Guid(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);
 }
Esempio n. 9
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);
 }
Esempio n. 10
0
        public static string GetHtmlImgUserAvatar(Guid userId)
        {
            var imgPath = UserPhotoManager.GetBigPhotoURL(userId);

            if (imgPath != null)
            {
                return("<img class=\"userMiniPhoto\"  src=\"" + imgPath + "\"/>");
            }
            return(string.Empty);
        }
        public static string GetHTMLUserAvatar(Guid userID)
        {
            string imgPath = UserPhotoManager.GetBigPhotoURL(userID);

            if (imgPath != null)
            {
                return("<img class=\"userMiniPhoto\" alt='' src=\"" + imgPath + "\"/>");
            }

            return(string.Empty);
        }
Esempio n. 12
0
        public static string GetLinkUserAvatar(Guid userID)
        {
            string imgPath = UserPhotoManager.GetBigPhotoURL(userID);

            if (imgPath != null)
            {
                return(String.Format("<a href=\"{0}\"><img class=\"userPhoto\" src=\"{1}\"/></a>",
                                     Constants.UserPostsPageUrl + userID.ToString(),
                                     imgPath));
            }

            return(string.Empty);
        }
Esempio n. 13
0
        private static CommentInfo GetCommentInfo(FeedComment comment)
        {
            var info = new CommentInfo
            {
                CommentID             = comment.Id.ToString(CultureInfo.CurrentCulture),
                UserID                = new Guid(comment.Creator),
                TimeStamp             = comment.Date,
                TimeStampStr          = comment.Date.Ago(),
                IsRead                = true,
                Inactive              = comment.Inactive,
                CommentBody           = comment.Comment,
                UserFullName          = DisplayUserSettings.GetFullUserName(new Guid(comment.Creator)),
                UserProfileLink       = CommonLinkUtility.GetUserProfile(comment.Creator),
                UserAvatarPath        = UserPhotoManager.GetBigPhotoURL(new Guid(comment.Creator)),
                IsEditPermissions     = CommunitySecurity.CheckPermissions(comment, NewsConst.Action_Edit),
                IsResponsePermissions = CommunitySecurity.CheckPermissions(NewsConst.Action_Comment),
                UserPost              = CoreContext.UserManager.GetUsers((new Guid(comment.Creator))).Title
            };

            return(info);
        }
Esempio n. 14
0
        private static CommentInfo GetCommentInfo(Comment comment)
        {
            var info = new CommentInfo
            {
                CommentID             = comment.Id.ToString(),
                UserID                = comment.UserId,
                TimeStamp             = comment.Date,
                TimeStampStr          = comment.Date.Ago(),
                IsRead                = true,
                Inactive              = comment.Inactive,
                CommentBody           = HtmlUtility.GetFull(comment.Body),
                UserFullName          = DisplayUserSettings.GetFullUserName(comment.UserId),
                UserProfileLink       = CommonLinkUtility.GetUserProfile(comment.UserId),
                UserAvatarPath        = UserPhotoManager.GetBigPhotoURL(comment.UserId),
                IsEditPermissions     = CommunitySecurity.CheckPermissions(new WikiObjectsSecurityObject(comment), ASC.Web.Community.Wiki.Common.Constants.Action_EditRemoveComment),
                IsResponsePermissions = CommunitySecurity.CheckPermissions(ASC.Web.Community.Wiki.Common.Constants.Action_AddComment),
                UserPost              = CoreContext.UserManager.GetUsers(comment.UserId).Title
            };

            return(info);
        }
Esempio n. 15
0
        ///<summary>
        ///</summary>
        ///<param name="userInfo"></param>
        ///<exception cref="ArgumentException"></exception>
        public EmployeeWraperFull(UserInfo userInfo) : base(userInfo)
        {
            if (userInfo == Core.Users.Constants.LostUser)
            {
                throw new ArgumentException("user not found");
            }

            Id         = userInfo.ID;
            UserName   = userInfo.UserName;
            FirstName  = userInfo.FirstName;
            LastName   = userInfo.LastName;
            Birthday   = (ApiDateTime)userInfo.BirthDate;
            Sex        = userInfo.Sex.HasValue ? userInfo.Sex.Value ? "male" : "female" : "";
            Status     = userInfo.Status;
            Terminated = (ApiDateTime)userInfo.TerminatedDate;
            Title      = userInfo.Title;
            Department = userInfo.Department;
            WorkFrom   = (ApiDateTime)userInfo.WorkFromDate;
            Email      = userInfo.Email;
            Location   = userInfo.Location;
            Notes      = userInfo.Notes;
            Email      = userInfo.Email;
            FillConacts(userInfo);

            Groups = Core.CoreContext.UserManager.GetUserGroups(userInfo.ID).Select(x => new GroupWrapperSummary(x)).ToList();

            try
            {
                AvatarSmall  = UserPhotoManager.GetSmallPhotoURL(userInfo.ID);
                AvatarMedium = UserPhotoManager.GetMediumPhotoURL(userInfo.ID);
                Avatar       = UserPhotoManager.GetBigPhotoURL(userInfo.ID);
            }
            catch (Exception)
            {
            }
        }
        public override void HandleMessage(XmppStream stream, Message message, XmppHandlerContext context)
        {
            if (!message.HasTo || message.To.IsServer)
            {
                context.Sender.SendTo(stream, XmppStanzaError.ToServiceUnavailable(message));
                return;
            }

            var sessions = context.SessionManager.GetBareJidSessions(message.To);

            if (0 < sessions.Count)
            {
                foreach (var s in sessions)
                {
                    try
                    {
                        context.Sender.SendTo(s, message);
                    }
                    catch
                    {
                        context.Sender.SendToAndClose(s.Stream, message);
                    }
                }
            }
            else
            {
                pushStore = new DbPushStore();
                var properties = new Dictionary <string, string>(1);
                properties.Add("connectionStringName", "default");
                pushStore.Configure(properties);

                if (message.HasTag("active"))
                {
                    var fromFullName = message.HasAttribute("username") ?
                                       message.GetAttribute("username") : message.From.ToString();


                    var messageToDomain = message.To.ToString().Split(new char[] { '@' })[1];
                    var tenant          = CoreContext.TenantManager.GetTenant(messageToDomain);
                    var tenantId        = tenant != null ? tenant.TenantId : -1;

                    var userPushList = new List <UserPushInfo>();
                    userPushList = pushStore.GetUserEndpoint(message.To.ToString().Split(new char[] { '@' })[0]);

                    var firebaseAuthorization = "";
                    try
                    {
                        CallContext.SetData(TenantManager.CURRENT_TENANT, new Tenant(tenantId, ""));
                        firebaseAuthorization = FireBase.Instance.Authorization;
                    }
                    catch (Exception exp)
                    {
                        log.DebugFormat("firebaseAuthorizationERROR: {0}", exp);
                    }
                    foreach (var user in userPushList)
                    {
                        try
                        {
                            var           from = message.From.ToString().Split(new char[] { '@' })[0];
                            List <string> userId;
                            string        photoPath = "";
                            using (var db = new DbManager("core"))
                                using (var command = db.Connection.CreateCommand())
                                {
                                    var q = new SqlQuery("core_user").Select("id").Where(Exp.Like("username", from)).Where("tenant", tenantId);

                                    userId = command.ExecuteList(q, DbRegistry.GetSqlDialect(db.DatabaseId))
                                             .ConvertAll(r => Convert.ToString(r[0]))
                                             .ToList();
                                }
                            if (userId.Count != 0)
                            {
                                var guid = new Guid(userId[0]);
                                photoPath = UserPhotoManager.GetBigPhotoURL(guid);
                            }

                            var tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                            tRequest.Method      = "post";
                            tRequest.ContentType = "application/json";
                            var data = new
                            {
                                to   = user.endpoint,
                                data = new
                                {
                                    msg          = message.Body,
                                    fromFullName = fromFullName,
                                    photoPath    = photoPath
                                }
                            };
                            var serializer = new JavaScriptSerializer();
                            var json       = serializer.Serialize(data);
                            var byteArray  = Encoding.UTF8.GetBytes(json);
                            tRequest.Headers.Add(string.Format("Authorization: key={0}", firebaseAuthorization));
                            tRequest.ContentLength = byteArray.Length;
                            using (var dataStream = tRequest.GetRequestStream())
                            {
                                dataStream.Write(byteArray, 0, byteArray.Length);
                                using (var tResponse = tRequest.GetResponse())
                                {
                                    using (var dataStreamResponse = tResponse.GetResponseStream())
                                    {
                                        using (var tReader = new StreamReader(dataStreamResponse))
                                        {
                                            var sResponseFromServer = tReader.ReadToEnd();
                                            var str = sResponseFromServer;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var str = ex.Message;
                            log.DebugFormat("PushRequestERROR: {0}", str);
                        }
                    }
                }
                StoreOffline(message, context.StorageManager.OfflineStorage);
            }
        }
        public EmployeeWraperFull(UserInfo userInfo, ApiContext context)
            : base(userInfo, context)
        {
            UserName  = userInfo.UserName;
            IsVisitor = userInfo.IsVisitor();
            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 (CheckContext(context, "groups") || CheckContext(context, "department"))
            {
                var groups = CoreContext.UserManager.GetUserGroups(userInfo.ID).Select(x => new GroupWrapperSummary(x)).ToList();

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

            if (CheckContext(context, "avatarMedium"))
            {
                AvatarMedium = UserPhotoManager.GetMediumPhotoURL(userInfo.ID) + "?_=" + userInfo.LastModified.GetHashCode();
            }

            if (CheckContext(context, "avatar"))
            {
                Avatar = UserPhotoManager.GetBigPhotoURL(userInfo.ID) + "?_=" + userInfo.LastModified.GetHashCode();
            }

            IsAdmin = userInfo.IsAdmin();

            if (CheckContext(context, "listAdminModules"))
            {
                var listAdminModules = userInfo.GetListAdminModules();

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

            IsOwner = userInfo.IsOwner();

            IsLDAP = userInfo.IsLDAP();
            IsSSO  = userInfo.IsSSO();
        }
 public static string GetBigPhotoURL(this UserInfo userInfo)
 {
     return(UserPhotoManager.GetBigPhotoURL(userInfo.ID));
 }
Esempio n. 19
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 string GetHTMLImgUserAvatar(Guid userID)
 {
     return("<img alt=\"\" class='userPhoto' src=\"" + UserPhotoManager.GetBigPhotoURL(userID) + "\"/>");
 }
Esempio n. 21
0
 public static string GetBigPhotoURL(this UserInfo userInfo, int tenantId)
 {
     return(UserPhotoManager.GetBigPhotoURL(tenantId, 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. 23
0
        public EmployeeWraperFull(UserInfo userInfo, ApiContext context)
            : base(userInfo)
        {
            UserName  = userInfo.UserName;
            IsVisitor = userInfo.IsVisitor();
            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;
            Terminated       = (ApiDateTime)userInfo.TerminatedDate;

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

            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);

            var groups = Core.CoreContext.UserManager.GetUserGroups(userInfo.ID).Select(x => new GroupWrapperSummary(x)).ToList();

            if (groups.Any())
            {
                Groups = groups;
            }

            try
            {
                if (CheckContext(context, "avatarSmall"))
                {
                    AvatarSmall = UserPhotoManager.GetSmallPhotoURL(userInfo.ID);
                }

                if (CheckContext(context, "avatarMedium"))
                {
                    AvatarMedium = UserPhotoManager.GetMediumPhotoURL(userInfo.ID);
                }

                if (CheckContext(context, "avatar"))
                {
                    Avatar = UserPhotoManager.GetBigPhotoURL(userInfo.ID);
                }
            }
            catch (Exception)
            {
            }

            try
            {
                IsOnline = false;
                IsAdmin  = userInfo.IsAdmin();

                if (CheckContext(context, "listAdminModules"))
                {
                    var listAdminModules = userInfo.GetListAdminModules();

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

                IsOwner = userInfo.IsOwner();
            }
            catch (Exception)
            {
            }
        }