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");
        }
Beispiel #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);
     }
 }
Beispiel #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);
     }
 }
Beispiel #4
0
 public List<GroupExtended> GetGroupsExtended(Authentication auth)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         return business.Groups.GetGroupsExtended(auth.UserId);
     }
 }
Beispiel #5
0
 public List<Group> GetGroups(Authentication auth)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         return business.Groups.GetGroups();
     }
 }
Beispiel #6
0
 public Group GetGroup(Authentication auth, int groupId)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         return business.Groups.GetGroup(groupId);
     }
 }
Beispiel #7
0
 public void EnrollInGroup(Authentication auth, int groupId)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         business.Groups.EnrollInGroup(auth.UserId, groupId);
     }
 }
Beispiel #8
0
 public void DeleteMessage(Authentication auth, int messageId)
 {
     using (var business = new SocialServiceBusiness())
     {
         business.Authentication.AuthenticateUser(auth);
         business.Groups.DeleteMessage(auth.UserId, messageId);
     }
 }
Beispiel #9
0
 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;
        }
Beispiel #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);
     }
 }
Beispiel #12
0
 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");
 }