Exemplo n.º 1
0
        public void RegisterUser(JsonObject ps)
        {
            Profile p = new Profile();

            ProfileManager pm = new ProfileManager();

            FacebookService fb = new FacebookService();
            Facebook.JsonObject o = fb.DownloadData<Facebook.JsonObject>("/me", ps["accessToken"].ToString());

            if (pm.LoadUser(o["email"].ToString()) != null)
                throw new Exception("Profile already exists");

            p.CreationDate = DateTime.Now;
            p.Email = o["email"].ToString();
            p.IsLockedOut = false;

            if (o.ContainsKey("username"))
                p.UserName = o["username"].ToString();
            else
                p.UserName = ps["userID"].ToString();

            pm.RegisterUser(p);

            SocialConnection sc = new SocialConnection();
            sc.OauthToken = ps["accessToken"].ToString();
            sc.ReferenceID = ps["userID"].ToString();
            sc.ServiceID = SocialServiceType.Facebook;
            sc.UserID = p.UserID;

            SocialServiceManager scm = new SocialServiceManager();
            scm.AddConnection(sc);

            pm.ReleaseAuthenticationTicket(p);
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            SocialConnection sc = new SocialConnection();
            SocialAccessToken accessToken = null;

            switch (context.Request.QueryString[0])
            {
                case "foursquare":
                    FoursquareService fsqs = new FoursquareService();
                    accessToken = fsqs.GetAccessToken(context.Request.QueryString["code"]);
                    Igloo.SharpSquare.Entities.User fsqUser = fsqs.GetProfile(accessToken.Token);

                    sc.OauthToken = accessToken.Token;
                    sc.ReferenceID = fsqUser.id;
                    sc.ServiceID = SocialServiceType.Foursquare;
                    sc.UserID = 1;

                    break;
                case "twitter":
                    SocialServices.TwitterService tws = new SocialServices.TwitterService();
                    accessToken = tws.GetAccessToken(context.Request.QueryString["oauth_token"], context.Request.QueryString["oauth_verifier"]);
                    TwitterUser twitterUser = tws.GetProfile(accessToken.Token, accessToken.TokenSecret);

                    sc.OauthToken = accessToken.Token;
                    sc.OauthVerifier = accessToken.TokenSecret;
                    sc.ServiceID = SocialServiceType.Twitter;
                    sc.UserID = 1;
                    sc.ReferenceID = twitterUser.Id.ToString();

                    break;
            }

            SocialServiceManager scm = new SocialServiceManager();
            scm.AddConnection(sc);

            context.Response.Redirect("/services?added=" + context.Request.QueryString[0]);
        }
Exemplo n.º 3
0
 public void AddConnection(SocialConnection sc)
 {
     Session.Save(sc);
 }