public static void ProccessAuthSet(string username, string SID, int UserSessionIndex, IQ iq) { Auth auth = iq.Query as Auth; iq.SwitchDirection(); string cuser = auth.Username; string cpass = auth.Digest; if (!string.IsNullOrEmpty(cuser) && !string.IsNullOrEmpty(cpass)) { if (!ThreadTools.Users.Online[UserSessionIndex].Authenticated) { int UserIndex; if (!ThreadTools.Users.Online.IsAuthenticated(cuser, out UserIndex)) { BLL.Users api = new BLL.Users(); if (api.LoginMessenger(cuser, SID, cpass)) { iq.Type = IqType.result; ThreadTools.Users.Online[UserSessionIndex].Authenticated = true; ThreadTools.Users.Online[UserSessionIndex].Username = cuser; iq.Query = null; ThreadTools.Users.Online[UserSessionIndex].Send(iq); api.ChangeUserStatus(cuser, true); Presence p = Rosters.GetPresence(cuser); p.To = new agsXMPP.Jid(cuser + "@" + Config.AppSetting.domain); ThreadTools.Users.Online[UserSessionIndex].Send(p); Rosters.SendStatus(cuser); } else { iq.Type = IqType.error; iq.Query = null; iq.AddChild(new agsXMPP.protocol.client.Error(ErrorType.auth, ErrorCondition.NotAuthorized)); ThreadTools.Users.Online[UserSessionIndex].Send(iq); } } else { iq.Type = IqType.error; iq.Query = null; iq.AddChild(new agsXMPP.protocol.client.Error(ErrorType.auth, ErrorCondition.Conflict)); ThreadTools.Users.Online[UserSessionIndex].Send(iq); } } } else { iq.Type = IqType.error; iq.Query = null; iq.AddChild(new agsXMPP.protocol.client.Error(ErrorType.auth, ErrorCondition.NotAcceptable)); ThreadTools.Users.Online[UserSessionIndex].Send(iq); } }
public static void Avatar(string username, IQ iq) { DAL.TbUsers cuser; BLL.Users api = new BLL.Users(); switch (iq.Type) { case IqType.get: if (iq.To != null) { cuser = api.Find(iq.To.User); } else { cuser = api.Find(username); } if (cuser != null) { if (!string.IsNullOrEmpty(cuser.TbVcard.VcardPhoto)) { iq.SwitchDirection(); iq.Type = IqType.result; iq.Query.Namespace = "jabber:iq:avatar"; iq.Query.ChildNodes.Clear(); Element dataEl = new Element("data"); dataEl.Value = ImageTools.ToBase64(cuser.TbVcard.VcardPhoto); iq.Query.AddChild(dataEl); int index; if (ThreadTools.Users.Online.IsAuthenticated(username, out index)) { ThreadTools.Users.Online[index].Send(iq); } } } break; case IqType.set: case IqType.result: if (iq.Query.HasTag("data")) { Element el = iq.Query.SelectSingleElement("data"); cuser = api.Find(username); string pname; bool isSaved; pname = ImageTools.SaveAvatar(el.Value, out isSaved); if (isSaved) { api.ChangeUserPicture(username, pname); Rosters.SendStatus(username); } } break; } }