Esempio n. 1
0
 public bool Set(string username, Vcard vcard)
 {
     using (SqlDataContext dc = new SqlDataContext())
     {
         try
         {
             var user = dc.DatabaseUserItems.Single(x => string.Compare(username, x.Username, true) == 0);
             user.Nickname  = vcard.Nickname;
             user.Signature = vcard.Description;
         }
         catch (System.Exception ex)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 2
0
 public string GetUserpassword(string username)
 {
     if (string.IsNullOrEmpty(username))
     {
         return(null);
     }
     try
     {
         using (SqlDataContext dc = new SqlDataContext())
         {
             return(dc.DatabaseUserItems.Where(x => string.Compare(username, x.Username, true) == 0 ||
                                               string.Compare(username, x.Mail, true) == 0)
                    .Select(x => x.Password).Single());
         }
     }
     catch { return(null); }
 }
Esempio n. 3
0
        public bool Set(string username, Vcard vcard)
        {
            using (SqlDataContext dc=new SqlDataContext())
            {
                try
                {
                    var user = dc.DatabaseUserItems.Single(x => string.Compare(username, x.Username, true) == 0);
                    user.Nickname = vcard.Nickname;
                    user.Signature = vcard.Description;

                }
                catch (System.Exception ex)
                {
                    return false;
                }
            }
            return true;
        }
Esempio n. 4
0
        public Vcard Get(string username)
        {
            Vcard vcard = null;
            using (SqlDataContext dc=new SqlDataContext())
            {
                try
                {
                    var user = dc.DatabaseUserItems.Single(x => string.Compare(username, x.Username, true) == 0);
                    var data=HeaderManager.Load(username);
                    vcard = new Vcard();
                    vcard.Nickname = user.Nickname;
                    vcard.Description = user.Signature;
                    vcard.Jid = JIDEscaping.Escape(user.Username) + "@gjtalk.com";
                    vcard.AddEmail(new Email(user.Mail));
                    if (data != null)
                        vcard.Photo = new Photo(data, ImageFormat.Png);
                }
                catch (System.Exception ex)
                {

                }
            }
            return vcard;
        }
Esempio n. 5
0
 public long GetUserId(string username)
 {
     long id = -1;
     if (!string.IsNullOrEmpty(username))
     {
         username = username.ToLower();
         if (!idmap.TryGetValue(username, out id))
         {
             try
             {
                 using (SqlDataContext dc = new SqlDataContext())
                 {
                     var user = dc.DatabaseUserItems.Where(x => string.Compare(x.Username, username, true) == 0 || string.Compare(x.Mail,
                         username, true) == 0).Select(x => new { x.Id, x.Mail, x.Username }).Single();
                     idmap.Add(user.Username.ToLower(), user.Id);
                     if (!string.IsNullOrEmpty(user.Mail))
                         idmap.Add(user.Mail.ToLower(), user.Id);
                 }
             }
             catch { }
         }
     }
     return id;
 }
Esempio n. 6
0
 public User GetUser(string username)
 {
     if (string.IsNullOrEmpty(username))
         return null;
     try
     {
         using (SqlDataContext dc = new SqlDataContext())
         {
             var user = dc.DatabaseUserItems.Single(x => string.Compare(x.Username, username, true) == 0
         || string.Compare(x.Mail, username) == 0);
             return new User()
             {
                 UserId = user.Id,
                 Username = user.Username,
                 Nickname = user.Nickname,
                 HeaderPic = user.HeaderImage,
                 Signature = user.Signature,
                 Status = UserOnlineStatus.Hidden,
                 Mail = user.Mail
             };
         }
     }
     catch { return null; }
 }
Esempio n. 7
0
        void ProcessSearchIq(XmppBase.Iq iq)
        {
            iq.SwitchDirection();
            Matrix.Xmpp.Search.Search search = iq.Query as Matrix.Xmpp.Search.Search;
            if (search.XData == null)
                search.XData = new XData.Data();
            if (iq.Type == IqType.get)
            {
                search.Instructions = "The following fields are available.";
                search.First = search.Last = search.Nick = search.Email = "";
                search.XData.Type = XData.FormType.form;
                search.XData.Title = "Advanced User Search";
                search.XData.Instructions = "The following fields are available.";
                search.XData.AddField(new XData.Field("FORM_TYPE", "jabber:iq:search") { Type = XData.FieldType.Hidden });
                var searchFiled = new XData.Field("search", "Search", XData.FieldType.Text_Single);
                var usernameField = new XData.Field("Username", "Username", XData.FieldType.Boolean);
                var nameField = new XData.Field("Name", "Name", XData.FieldType.Boolean);
                var emailField = new XData.Field("Email", "Email", XData.FieldType.Boolean);
                searchFiled.Add(new XData.Value(true));
                usernameField.Add(new XData.Value(true));
                nameField.Add(new XData.Value(true));
                emailField.Add(new XData.Value(true));
                search.XData.AddField(searchFiled);
                search.XData.AddField(usernameField);
                search.XData.AddField(nameField);
                search.XData.AddField(emailField);

            }
            else if (iq.Type == IqType.set && search.XData.Type == XData.FormType.submit)
            {
                var searchField = search.XData.GetField("search");
                var usernameField = search.XData.GetField("Username");
                var nameField = search.XData.GetField("Name");
                var emailField = search.XData.GetField("Email");
                if (searchField != null)
                {
                    bool bUsername = usernameField != null && usernameField.GetValueBool();
                    bool bName = nameField != null && nameField.GetValueBool();
                    bool bEmail = emailField != null && emailField.GetValueBool();
                    string keyword = searchField.Value;
                    if (!string.IsNullOrEmpty(keyword))
                    {
                        using (SqlDataContext dc = new SqlDataContext())
                        {
                            var query = dc.DatabaseUserItems.Where(x =>
                                (bUsername && string.Compare(x.Username, keyword, true) == 0) ||
                                (bName && string.Compare(x.Nickname, keyword, true) == 0) ||
                                (bEmail && string.Compare(x.Mail, keyword, true) == 0)
                                );
                            search.XData = new XData.Data();
                            search.XData.Type = XData.FormType.result;

                            search.XData.AddField(new XData.Field()
                            {
                                Var = "FORM_TYPE",
                                Type = XData.FieldType.Hidden
                            });
                            XData.Reported reported = new XData.Reported();
                            reported.Add(new XData.Field("jid", "JID", XData.FieldType.Jid_Single));
                            reported.Add(new XData.Field("Username", "Username", XData.FieldType.Text_Single));
                            reported.Add(new XData.Field("Name", "Name", XData.FieldType.Text_Single));
                            reported.Add(new XData.Field("Email", "Email", XData.FieldType.Text_Single));
                            reported.Add(new XData.Field("Signature", "Signature", XData.FieldType.Text_Single));
                            search.XData.Add(reported);
                            foreach (var user in query)
                            {
                                var item = new XData.Item();
                                item.Add(new XData.Field("Name", user.Nickname));
                                item.Add(new XData.Field("Email", user.Mail));
                                item.Add(new XData.Field("Username", user.Username));
                                item.Add(new XData.Field("jid", user.Username + "@gjtalk.com"));
                                item.Add(new XData.Field("Signature", user.Signature));
                                search.XData.AddItem(item);
                            }
                        }
                    }
                }
            }
            iq.Type = IqType.result;
            Session.Send(iq);
        }
Esempio n. 8
0
 public string GetUserpassword(string username)
 {
     if (string.IsNullOrEmpty(username))
         return null;
     try
     {
         using (SqlDataContext dc = new SqlDataContext())
         {
             return dc.DatabaseUserItems.Where(x => string.Compare(username, x.Username, true) == 0
                 || string.Compare(username, x.Mail, true) == 0)
                 .Select(x => x.Password).Single();
         }
     }
     catch { return null; }
 }