예제 #1
0
        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");
        }
예제 #2
0
 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);
     }
 }
예제 #3
0
 public List<Message> GetMessages(Authentication auth, int groupId)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         return business.Groups.GetMessages(auth.UserId, groupId);
     }
 }
예제 #4
0
 public List<GroupExtended> GetGroupsExtended(Authentication auth)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         return business.Groups.GetGroupsExtended(auth.UserId);
     }
 }
예제 #5
0
 public List<Group> GetGroups(Authentication auth)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         return business.Groups.GetGroups();
     }
 }
예제 #6
0
 public Group GetGroup(Authentication auth, int groupId)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         return business.Groups.GetGroup(groupId);
     }
 }
예제 #7
0
 public void EnrollInGroup(Authentication auth, int groupId)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         business.Groups.EnrollInGroup(auth.UserId, groupId);
     }
 }
예제 #8
0
 public void DeleteMessage(Authentication auth, int messageId)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         business.Groups.DeleteMessage(auth.UserId, messageId);
     }
 }
예제 #9
0
 public int AddGroup(Authentication auth, Group group)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         return business.Groups.AddGroup(group);
     }
 }
예제 #10
0
        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;
        }
예제 #11
0
 public void PostMessage(Authentication auth, Message message, int? parentId)
 {
     using(var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         business.Groups.PostMessage(message, parentId);
     }
 }
예제 #12
0
 public Sessions GetSession(Authentication header)
 {
     throw new NotImplementedException();
 }
예제 #13
0
 public void AuthenticateUser(Authentication auth)
 {
     var session = _data.GetSession(auth);
     if (session == null)
         throw new AccessViolationException("Header is not valid");
 }