Esempio n. 1
0
        public override Vcard GetVCard(Jid jid)
        {
            ASCContext.SetCurrentTenant(jid.Server);

            jid = new Jid(jid.Bare.ToLowerInvariant());
            var ui = ASCContext.UserManager.GetUserByUserName(jid.User);

            if (ui != null)
            {
                var vcard = (Vcard)cache.Get(jid.ToString());
                if (vcard != null)
                {
                    return(vcard);
                }

                vcard             = new Vcard();
                vcard.Name        = new Name(ui.LastName, ui.FirstName, null);
                vcard.Fullname    = UserFormatter.GetUserName(ui);
                vcard.Nickname    = ui.UserName;
                vcard.Description = ui.Notes;
                if (ui.BirthDate != null)
                {
                    vcard.Birthday = ui.BirthDate.Value;
                }
                vcard.JabberId = jid;
                if (ui.Sex.HasValue)
                {
                    vcard.Gender = ui.Sex.Value ? Gender.MALE : Gender.FEMALE;
                }

                var index = ui.Contacts.FindIndex(c => string.Compare(c, "phone", true) == 0) + 1;
                if (0 < index && index < ui.Contacts.Count)
                {
                    vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.NUMBER, ui.Contacts[index]));
                }
                vcard.AddEmailAddress(new Email(EmailType.INTERNET, ui.Email, true));

                var tenant      = ASCContext.GetCurrentTenant();
                var departments = string.Join(", ", CoreContext.UserManager.GetUserGroups(ui.ID).Select(d => HttpUtility.HtmlEncode(d.Name)).ToArray());
                if (tenant != null)
                {
                    vcard.Organization = new Organization(tenant.Name, departments);
                }
                vcard.Title = ui.Title;

                var image = PreparePhoto(ASCContext.UserManager.GetUserPhoto(ui.ID, Guid.Empty));
                if (image != null)
                {
                    vcard.Photo = new Photo(image, ImageFormat.Png);
                    image.Dispose();
                }

                cache.Insert(jid.ToString(), vcard, CACHE_TIMEOUT);
                return(vcard);
            }
            else
            {
                return(base.GetVCard(jid));
            }
        }
Esempio n. 2
0
        public override void SetVCard(Jid jid, Vcard vcard)
        {
            ASCContext.SetCurrentTenant(jid.Server);
            var tenant = ASCContext.GetCurrentTenant();

            if (tenant == null || ASCContext.UserManager.IsUserNameExists(jid.User))
            {
                throw new JabberException(ErrorCode.Forbidden);
            }
            base.SetVCard(jid, vcard);
        }