Inheritance: GenericContent, IUser, IADSyncable
Exemplo n.º 1
0
        public static void Subscribe(User subscriber, Node target, NotificationFrequency frequency, string language, string sitePath, string siteUrl, bool isActive)
        {
            if (subscriber.Email == null)
                throw new InvalidOperationException("Subscriber's email cannot be null.");
            if (subscriber.Email.Length == 0)
                throw new InvalidOperationException("Subscriber's email cannot be empty.");

            var userName = subscriber.FullName;
            if (String.IsNullOrEmpty(userName))
                userName = subscriber.Username;

            var subscription = new Subscription
            {
                UserEmail = subscriber.Email,
                UserId = subscriber.Id,
                UserPath = subscriber.Path,
                UserName = userName,
                ContentPath = target.Path,
                Frequency = frequency,
                Language = language,
                IsActive = true,
                SitePath = sitePath,
                SiteUrl = siteUrl,
            };
            subscription.Save();
        }
Exemplo n.º 2
0
		internal static string GetUserName(User user)
		{
			if (user == null)
				return String.Empty;

			if (String.IsNullOrEmpty(user.FullName))
				return user.Name;
			return user.FullName;
		}
Exemplo n.º 3
0
        public User GetApprover(int budgetLimit, User CEO)
        {
            var manager = this.CreatedBy.GetReference<User>("Manager");

            if (this.Sum > budgetLimit || manager == null)
                return CEO;
            else
                return manager;
        }
Exemplo n.º 4
0
        // ======================================================================================== static methods
        public static IEnumerable<WorkspaceGroupList> GetWorkspaceGroupLists(User user)
        {
            // 1. query groups under workspaces
            var settings = new QuerySettings { EnableAutofilters = false };
            var groups = SenseNet.Search.ContentQuery.Query("+TypeIs:Group +Workspace:*", settings).Nodes;

            // 2. select groups in which the current user is a member (Owner, Editor)
            var wsGroups = groups.Select(g => new WorkspaceGroup { Workspace = (g as SenseNet.ContentRepository.Group).Workspace, Group = (g as SenseNet.ContentRepository.Group) });
            wsGroups = wsGroups.Where(wsg => user.IsInGroup(wsg.Group));

            // 3. group by workspaces
            var wsGroupLists = from wsg in wsGroups
                               orderby wsg.Workspace.DisplayName
                               group wsg by wsg.Workspace into w
                               select new WorkspaceGroupList { Workspace = w.Key, Groups = w };
            
            return wsGroupLists;
        }
Exemplo n.º 5
0
        public static ManagerData GetManagerData(User manager)
        {
            var imgSrc = "/Root/Global/images/orgc-missinguser.png?dynamicThumbnail=1&width=48&height=48";
            var managerName = "No manager associated";
            var manUrl = string.Empty;

            if (manager != null)
            {
                managerName = manager.FullName;
                var managerC = SenseNet.ContentRepository.Content.Create(manager);
                manUrl = Actions.ActionUrl(managerC, "Profile");

                var imgField = managerC.Fields["Avatar"] as SenseNet.ContentRepository.Fields.ImageField;
                imgField.GetData(); // initialize image field
                var param = SenseNet.ContentRepository.Fields.ImageField.GetSizeUrlParams(imgField.ImageMode, 48, 48);
                if (!string.IsNullOrEmpty(imgField.ImageUrl))
                    imgSrc = imgField.ImageUrl + param;
            }

            return new ManagerData { ManagerName = managerName, ManagerUrl = manUrl, ManagerImgPath = imgSrc };
        }
Exemplo n.º 6
0
 private static void SetActivation(User subscriber, Node target, bool value)
 {
     using (var context = new DataHandler())
     {
         var subscription = context.Subscriptions.Where(x =>
             x.UserPath == subscriber.Path &&
             x.ContentPath == target.Path &&
             x.Active == (byte)(value ? 0 : 1)).FirstOrDefault();
         if (subscription == null)
             return;
         subscription.IsActive = value;
         context.SubmitChanges();
     }
 }
Exemplo n.º 7
0
 public static IEnumerable<Subscription> GetInactiveSubscriptionsByUser(User subscriber)
 {
     return GetInactiveSubscriptionsByUser(subscriber.Path);
 }
Exemplo n.º 8
0
 public static void ActivateSubscription(User subscriber, Node target)
 {
     SetActivation(subscriber, target, true);
 }
Exemplo n.º 9
0
 public static void InactivateSubscription(User subscriber, Node target)
 {
     SetActivation(subscriber, target, false);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Gets markup for an item in the list of people who liked an item
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static string GetLikeListItemMarkup(User user)
        {
            var markupStr = GetMarkupString("/Root/Global/renderers/Wall/LikeListItem.html");
            if (markupStr == null)
                return null;

            markupStr = markupStr.Replace("{{avatar}}", UITools.GetAvatarUrl(user));
            markupStr = markupStr.Replace("{{username}}", user.Name);
            markupStr = markupStr.Replace("{{userlink}}", Actions.ActionUrl(Content.Create(user), "Profile"));

            return markupStr;
        }
Exemplo n.º 11
0
        public static string GetCommentMarkup(string markupStr, DateTime creationDate, User user, string text, int commentId, LikeInfo likeInfo, Node commentNode)
        {
            if (markupStr == null)
                return null;

            markupStr = markupStr.Replace("{{commentid}}", commentId.ToString());
            markupStr = markupStr.Replace("{{avatar}}", UITools.GetAvatarUrl(user));
            markupStr = markupStr.Replace("{{username}}", user.Name);
            markupStr = markupStr.Replace("{{userlink}}", Actions.ActionUrl(Content.Create(user), "Profile"));
            markupStr = markupStr.Replace("{{text}}", text);
            markupStr = markupStr.Replace("{{date}}", creationDate.ToString());
            markupStr = markupStr.Replace("{{friendlydate}}", UITools.GetFriendlyDate(creationDate));
            markupStr = markupStr.Replace("{{likeboxdisplay}}", likeInfo.Count > 0 ? "inline" : "none");
            markupStr = markupStr.Replace("{{likes}}", likeInfo.GetShortMarkup());
            markupStr = markupStr.Replace("{{ilikedisplay}}", !likeInfo.iLike ? "inline" : "none");
            markupStr = markupStr.Replace("{{iunlikedisplay}}", likeInfo.iLike ? "inline" : "none");

            // user interaction allowed
            var haspermission = WallHelper.HasLikePermission(commentNode);
            markupStr = markupStr.Replace("{{interactdisplay}}", haspermission ? "inline" : "none");
            // show 'like' icon for comment likes if user does not have permission -> in this case like icon would not appear since like link is hidden
            markupStr = markupStr.Replace("{{interactclass}}", haspermission ? string.Empty : "sn-commentlike");
            return markupStr;
        }
Exemplo n.º 12
0
        private void SendActivateByAdminEmailInternal(User adminUser, string registeredUserPath)
        {
            if (adminUser == null)
                throw new ArgumentNullException("adminUser");
            
            if (String.IsNullOrEmpty(registeredUserPath)) 
                throw new ArgumentException("registeredUserPath");

            CheckMailSetting();

            var mailMessage = GetActivateByAdminMailMessage(adminUser, registeredUserPath);

            if (mailMessage == null)
                return; 

            mailMessage.Priority = MailPriority.Normal;

            SendEmail(mailMessage);
        }
Exemplo n.º 13
0
        /* ==================================================================================== Public Methods */
        public void CreateNewADUser(User user, string newPath, string passwd)
        {
            IUser originalUser = User.Current;
            Common.ChangeToAdminAccount();

            try
            {
                var parentPath = RepositoryPath.GetParentPath(newPath);

                // get containing synctree
                var syncTree = GetSyncTreeContainingPortalPath(parentPath);
                if (syncTree == null)
                {
                    // not synced object
                    return;
                }
                AdLog.LogPortalObject("Creating new AD user", user.Path);

                var parentADPath = syncTree.GetADPath(parentPath);

                CreateADUser(syncTree, parentADPath, user, passwd);
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
                throw new Exception(ex.Message, ex);
            }
        }
Exemplo n.º 14
0
 public static Subscription GetSubscriptionByUser(User subscriber, Node target)
 {
     return GetSubscriptionByUser(subscriber.Path, target.Path);
 }
Exemplo n.º 15
0
        //========================================================= Static part

        public static void Subscribe(User subscriber, Node target, NotificationFrequency frequency, string language, string sitePath, string siteUrl)
        {
            Subscribe(subscriber, target, frequency, language, sitePath, siteUrl, true);
        }
Exemplo n.º 16
0
        public static IEnumerable<Node> GetViaGroups(User user, WorkspaceGroup groupInfo)
        {
            var principals = user.GetPrincipals();

            return groupInfo.Group.Members.Where(m => principals.Contains(m.Id)).OrderBy(m => m.DisplayName);
        }
Exemplo n.º 17
0
        private MailMessage GetResetMailMessage(string resetEmail, User u, string resetKeyGuid)
        {
            var mailTo = resetEmail;
            var mailSubject = Configuration.ResetPasswordSubjectTemplate;
            var mailDefinition = Configuration.ResetPasswordTemplate;
            var mailFrom = GetMailFromValue();
            // prepare uri
            var siteRepositoryPath = PortalContext.Current.Site.Path;

            var changePwdPageUrl = string.Empty;

			var changePwdPage = Node.Load<SNP.Page>(Configuration.ChangePasswordPagePath);
            if (changePwdPage != null)
                changePwdPageUrl = GetChangePasswordUrl(changePwdPage, siteRepositoryPath);

            var resetLink = String.Format("{3}://{0}?uid={1}&key={2}", 
                changePwdPageUrl, 
                u.Id, 
                resetKeyGuid, 
                HttpContext.Current.Request.Url.GetComponents(UriComponents.Scheme, UriFormat.SafeUnescaped));

            mailDefinition = String.Format(mailDefinition, resetLink);
            
            return new MailMessage(mailFrom, mailTo, mailSubject, mailDefinition);
        }
Exemplo n.º 18
0
        public static User RegisterUser(string fullUserName)
        {
            if (string.IsNullOrEmpty(fullUserName))
                return null;

            var slashIndex = fullUserName.IndexOf('\\');
            var domain = fullUserName.Substring(0, slashIndex);
            var username = fullUserName.Substring(slashIndex + 1);

            var user = User.Load(domain, username);

            if (user != null)
                return user;

            try
            {
                AccessProvider.Current.SetCurrentUser(User.Administrator);

                var dom = Node.Load<Domain>(RepositoryPath.Combine(Repository.ImsFolderPath, domain));

                if (dom == null)
                {
                    //create domain
                    dom = new Domain(Repository.ImsFolder) { Name = domain };
                    dom.Save();
                }

                //create user
                user = new User(dom) { Name = username, Enabled = true, FullName = username };
                user.Save();

                Group.Administrators.AddMember(user);
            }
            finally
            {
                if (user != null)
                    AccessProvider.Current.SetCurrentUser(user);
            }

            return user;
        }
Exemplo n.º 19
0
 public static void Reset()
 {
     _visitor = null;
 }
Exemplo n.º 20
0
        private MailMessage GetActivateByAdminMailMessage(User adminUser, string registeredUserPath)
        {
            if (String.IsNullOrEmpty(registeredUserPath)) 
                throw new ArgumentException("registeredUserPath");

            try
            {
                var mailFrom = GetMailFromValue();
                var mailTo = adminUser.Email;
                var mailSubject = Configuration.ActivateEmailSubject;
                var mailDefinition = Configuration.ActivateEmailTemplate;
                mailDefinition = String.Format(mailDefinition, registeredUserPath);

                return new MailMessage(mailFrom, mailTo, mailSubject, mailDefinition);
                
            } 
            catch(Exception exc) //logged
            {
                Logger.WriteException(exc);
            }
            return null;
        }
Exemplo n.º 21
0
 public static Subscription GetSubscriptionByUser(User subscriber, Node target, bool isActive)
 {
     return GetSubscriptionByUser(subscriber.Path, target.Path, isActive);
 }
Exemplo n.º 22
0
        public static bool SyncVirtualUserFromAD(string adPath, string username, User virtualUser, List<PropertyMapping> propertyMappings, string customADAdminAccountName, string customADAdminAccountPwd, bool novellSupport, string guidProp, bool syncUserName)
        {
            bool success = false;
            try
            {
                using (var serverEntry = ConnectToAD(adPath, customADAdminAccountName, customADAdminAccountPwd, novellSupport, guidProp))
                {
                    var filter = string.Format("({0}={1})", SyncConfiguration.GetUserNameProp(propertyMappings), username);
                    using (var entry = SearchADObject(serverEntry, filter, novellSupport, guidProp))
                    {
                        if (entry != null)
                        {
                            UpdatePortalUserCustomProperties(entry, virtualUser, propertyMappings, syncUserName);

                            var guid = Common.GetADObjectGuid(entry, guidProp);
                            if (guid.HasValue)
                            {
                                virtualUser["SyncGuid"] = ((Guid)guid).ToString();
                                success = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
            return success;
        }
Exemplo n.º 23
0
        public static bool SyncVirtualUserFromAD(string adPath, Guid guid, User virtualUser, List<PropertyMapping> propertyMappings, string customADAdminAccountName, string customADAdminAccountPwd, bool novellSupport, string guidProp, bool syncUserName)
        {
            bool success = false;
            try
            {
                using (var serverEntry = ConnectToAD(adPath, customADAdminAccountName, customADAdminAccountPwd, novellSupport, guidProp))
                {
                    var filter = string.Format("{0}={1}", guidProp, Common.Guid2OctetString(guid));
                    using (var entry = SearchADObject(serverEntry, filter, novellSupport, guidProp))
                    {
                        if (entry != null)
                        {
                            UpdatePortalUserCustomProperties(entry, virtualUser, propertyMappings, syncUserName);

                            virtualUser["SyncGuid"] = guid.ToString();
                            success = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
            return success;
        }
Exemplo n.º 24
0
        /* ==================================================================================== Helper methods */
        public static void SyncInitialUserProperties(User user)
        {
            var adPath = "WinNT://" + user.Domain + "/" + user.Name + ",user";

            try
            {
                using (var entry = ConnectToADSimple(adPath))
                {
                    if (entry != null)
                    {
                        var fn = entry.Properties["FullName"].Value.ToString();

                        user.FullName = string.IsNullOrEmpty(fn) ? user.Name : fn;
                        user.Save();
                    }
                }
            }
            catch(COMException ex)
            {
                SenseNet.Diagnostics.Logger.WriteException(ex);
            }
        }
Exemplo n.º 25
0
        private void CreateADUser(SyncTree syncTree, string parentADPath, User user, string passwd)
        {
            using (DirectoryEntry parentObj = syncTree.ConnectToObject(parentADPath))
            {
                var prefix = Common.GetADObjectPrefix(ADObjectType.User);
                var userName = user.Name.MaximizeLength(_config.ADNameMaxLength);
                using (DirectoryEntry newObj = parentObj.Children.Add(String.Concat(prefix, userName), "user"))
                {
                    newObj.Properties["userAccountControl"].Value = ADAccountOptions.UF_NORMAL_ACCOUNT | ADAccountOptions.UF_DONT_EXPIRE_PASSWD;

                    // user actions

                    // user enabled/disabled: akkor enabled, ha a user maga enabled és globálisan nincs letiltva az enabled állapot konfigban
                    var enabled = ((!_createdUsersDisabled) && (user.Enabled));

                    Common.UpdateADUserCustomProperties(newObj, user, _propertyMappings, enabled, _config.ADsAMAccountNameMaxLength, _config.SyncEnabledState, _config.SyncUserName);

                    newObj.CommitChanges();

                    //if (doNotExpirePassword)
                    //{
                    //    oNewADUser.Properties["userAccountControl"].Value = ADAccountOptions.UF_NORMAL_ACCOUNT | ADAccountOptions.UF_DONT_EXPIRE_PASSWD;
                    //}
                    //else
                    //{
                    //    oNewADUser.Properties["userAccountControl"].Value = ADAccountOptions.UF_NORMAL_ACCOUNT;
                    //}
                    
                    // set password
                    if (passwd != null)
                        Common.SetPassword(newObj, passwd);

                    Common.SetPortalObjectGuid(newObj, user, _config.GuidProp);
                }
            }
        }
Exemplo n.º 26
0
 public Identity(User user)
 {
     this.Email = user.Email;
     this.FullName = user.FullName;
     this.UserName = user.Name;
 }
Exemplo n.º 27
0
        public void UpdateADUser(User user, string newPath, string passwd)
        {
            IUser originalUser = User.Current;
            Common.ChangeToAdminAccount();

            try
            {
                UpdateADObject(user, newPath, passwd, UpdateADUserProperties);
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
                throw new Exception(ex.Message, ex);
            }
        }
Exemplo n.º 28
0
        public static void UnSubscribeAll(User subscriber)
        {
            using (var context = new DataHandler())
            {
                var existing = context.Subscriptions.Where(
                    x => x.UserPath == subscriber.Path);

                if (existing.Count() > 0)
                {
                    context.Subscriptions.DeleteAllOnSubmit(existing);
                    context.SubmitChanges();
                }
            }
        }
Exemplo n.º 29
0
        private void CreateNewPortalUser(DirectoryEntry entry, string parentPath, Guid guid, SyncTree syncTree)
        {
            try
            {
                AdLog.LogADObject(string.Format("New portal user - creating under {0}", parentPath), entry.Path);
                var newUser = new User(Node.LoadNode(parentPath), _config.UserType);

                // user actions
                UpdatePortalUserProperties(entry, newUser, syncTree);

                Common.UpdateLastSync(newUser, guid);
                //newUser.Save(); - update lastsync already saves node

                if (_portalUsers != null)
                {
                    if (!_portalUsers.ContainsKey(guid.ToString()))
                        _portalUsers.Add(guid.ToString(), newUser.Id);
                }
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Gets markup for a comment.
 /// </summary>
 /// <param name="creationDate">Date when the comment was created</param>
 /// <param name="user">User who created the comment.</param>
 /// <param name="text">Text of the comment.</param>
 /// <returns></returns>
 public static string GetCommentMarkup(DateTime creationDate, User user, string text, int commentId, LikeInfo likeInfo, Node commentNode)
 {
     var markupStr = GetCommentMarkupStr();
     return GetCommentMarkup(markupStr, creationDate, user, text, commentId, likeInfo, commentNode);
 }