public Authentication Login(LoginCredentials credentials) { var result = new Authentication(); var facebookCredentials = credentials as FacebookLoginCredentials; if (facebookCredentials != null) { var facebookSession = new Facebook.FacebookClient(facebookCredentials.AccessToken); dynamic me = facebookSession.Get("me"); var facebookUser = new FacebookUser { FacebookUserId = long.Parse(me["id"]), UserName = me["username"] }; result.UserId = _data.CheckOrInsertFacebookUser(facebookUser); var session = StartSession(result.UserId); result.Ticket = session.Key; result.ValidTill = session.Value; return result; } throw new NotImplementedException("Only facebook users are supported now"); }
public List<Message> GetRelevantMessages(Authentication auth, int skip, int take) { using (var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); return business.Groups.GetRelevantMessages(auth.UserId, skip, take); } }
public List<Message> GetMessages(Authentication auth, int groupId) { using (var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); return business.Groups.GetMessages(auth.UserId, groupId); } }
public List<GroupExtended> GetGroupsExtended(Authentication auth) { using (var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); return business.Groups.GetGroupsExtended(auth.UserId); } }
public List<Group> GetGroups(Authentication auth) { using (var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); return business.Groups.GetGroups(); } }
public Group GetGroup(Authentication auth, int groupId) { using (var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); return business.Groups.GetGroup(groupId); } }
public void EnrollInGroup(Authentication auth, int groupId) { using (var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); business.Groups.EnrollInGroup(auth.UserId, groupId); } }
public void DeleteMessage(Authentication auth, int messageId) { using (var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); business.Groups.DeleteMessage(auth.UserId, messageId); } }
public int AddGroup(Authentication auth, Group group) { using (var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); return business.Groups.AddGroup(group); } }
public Sessions GetSession(Authentication header) { if (header == null) return null; var result = _data.Sessions.SingleOrDefault(s => s.userId == header.UserId && s.ticket == header.Ticket); if (result != null) if (result.validTill.ToShortDateString() != header.ValidTill.ToShortDateString()) result = null; return result; }
public void PostMessage(Authentication auth, Message message, int? parentId) { using(var business = new SocialServiceBusiness()) { business.Authentication.AuthenticateUser(auth); business.Groups.PostMessage(message, parentId); } }
public Sessions GetSession(Authentication header) { throw new NotImplementedException(); }
public void AuthenticateUser(Authentication auth) { var session = _data.GetSession(auth); if (session == null) throw new AccessViolationException("Header is not valid"); }