Beispiel #1
0
 public ActionResult Index()
 {
     Session.Clear();
     ClearAuthCookie();
     ClearOldCookie();
     UtilFacebook.ClearFacebookCookies(Response, GeneralConstants.FACEBOOK_API_KEY);
     return(Redirect("/"));
 }
Beispiel #2
0
        // this gets friend's details
        public ActionResult t()
        {
            var owner          = db.GetUserById(sessionid.Value, subdomainid.Value);
            var connectSession = UtilFacebook.GetConnectSession();

            if (connectSession.IsConnected())
            {
                var api     = new Api(connectSession);
                var friends = api.Friends.Get(long.Parse(owner.FBID));
                foreach (var friend in friends)
                {
                    var details = api.Users.GetInfo(friend);
                }
            }

            return(new EmptyResult());
        }
        public ActionResult Import(string type, string token)
        {
            var owner    = db.GetUserById(sessionid.Value, subdomainid.Value);
            var viewdata = new ImportContactsViewData(baseviewmodel)
            {
                hostName    = accountHostname,
                fbuid       = owner.FBID,
                subdomainid = subdomainid.Value,
                appid       = sessionid.Value
            };

            // facebook
            var connectSession = UtilFacebook.GetConnectSession();

            if (connectSession.IsConnected())
            {
                var          api    = new Api(connectSession);
                IList <long> fdlist = api.Friends.GetAppUsers();
                string       s      = string.Empty;
                for (int i = 0; i < fdlist.Count; i++)
                {
                    s += fdlist[i].ToString();
                    if (i != fdlist.Count - 1)
                    {
                        s += ",";
                    }
                }
                viewdata.invitedFbuidList = s;
            }

            // if callback from authsub authorisation
            if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(token))
            {
                var importType = type.ToEnum <ContactImportType>();
                switch (importType)
                {
                case ContactImportType.GOOGLE:
                    var requestFactory = new GAuthSubRequestFactory("cp", "tradelr");
                    requestFactory.Token = token;

                    var query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
                    //query.OAuthRequestorId = string.Concat(sessionid.Value, '@', subdomainid.Value);

                    var service = new ContactsService(requestFactory.ApplicationName);
                    service.RequestFactory = requestFactory;
                    try
                    {
                        var feed     = service.Query(query);
                        var contacts = new List <ContactBasic>();
                        foreach (ContactEntry entry in feed.Entries)
                        {
                            string email;
                            // primary email can be null
                            if (entry.PrimaryEmail == null)
                            {
                                if (entry.Emails == null || entry.Emails.Count == 0)
                                {
                                    continue;     // skip entry, cannot find email
                                }
                                email = entry.Emails[0].Address;
                            }
                            else
                            {
                                email = entry.PrimaryEmail.Address;
                            }

                            var contact = new ContactBasic()
                            {
                                address     = entry.BillingInformation,
                                companyName = email,
                                email       = email
                            };

                            if (entry.Name != null)
                            {
                                if (!string.IsNullOrEmpty(entry.Name.GivenName))
                                {
                                    contact.firstName = entry.Name.GivenName;
                                }

                                if (!string.IsNullOrEmpty(entry.Name.FamilyName))
                                {
                                    contact.lastName = entry.Name.FamilyName;
                                }
                            }

                            if (entry.PrimaryPhonenumber == null)
                            {
                                if (entry.Phonenumbers != null && entry.Phonenumbers.Count != 0)
                                {
                                    contact.phone = entry.Phonenumbers[0].Value;
                                }
                            }
                            else
                            {
                                contact.phone = entry.PrimaryPhonenumber.Value;
                            }

                            // now we need to format it nicely for display purposes

                            contacts.Add(contact);
                        }
                        viewdata.contacts = contacts.OrderBy(x => x.email);
                    }
                    catch (Exception ex)
                    {
                        Syslog.Write(ex);
                    }

                    break;

                default:
                    break;
                }
            }

            return(View(viewdata));
        }