Example #1
0
        public RedirectResult Auth(string code, string error)
        {
            UserInfo          userInfo = CurrentClient.GetUserInfo(Request.QueryString);
            IdentityInfoModel info     = DataService.AuthorizeUser(userInfo, User.UserId);

            if (!User.Identity.IsAuthenticated)
            {
                SocialIdentity.SetAuthTicket(info, Response);
            }
            return(GetRedirectToSourceUrl());
        }
Example #2
0
 public ActionResult Settings(UserProfileModel model)
 {
     model.Identity.Id        = (Guid)User.UserId;
     model.AvailableProviders = AuthorizationRoot.Clients.ToList();
     DataService.UpdateUserProfile(model.Identity);
     if (Session["TempAvatar"] != null)
     {
         DataService.UpdateUserAvatar((Guid)User.UserId, Session["TempAvatar"] as byte[]);
         Session.Remove("TempAvatar");
     }
     SocialIdentity.SetAuthTicket(model.Identity, Response);
     return(View(model));
 }
Example #3
0
 public IEnumerable<Post> GetAllPosts(SocialIdentity identity, int count)
 {
     return this.client.GetAllStatus(identity.Token, count).Select(
         s => new Post
         {
             From = new UserDetails
             {
                 Id = s.From.UserId.ToString(),
                 Name = s.From.Name,
                 ProfilePictureUrl = s.From.PictureUrl,
                 ProfileUrl = s.From.ProfileUrl
             },
             Body = s.Message,
             Date = TypeConverter.ConvertDate(s.Time),
             ProviderName = this.Name
         }).ToList();
 }
Example #4
0
        public IEnumerable<Post> GetAllPosts(SocialIdentity identity, int count)
        {
            var accessToken = new AccessToken { Token = identity.Token, TokenSecret = identity.Secret };

            return this.client.GetAllStatus(accessToken, count).Select(
                s => new Post
                {
                    Date = TypeConverter.ConvertDate(s.CreatedAt),
                    From = new UserDetails
                    {
                        Id = s.User.Id.ToString(),
                        Name = s.User.Name,
                        ProfilePictureUrl = s.User.ProfileImageUrl,
                        ProfileUrl = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", UrlResources.WebSiteUrl, s.User.ScreenName)
                    },
                    Body = s.Text,
                    ProviderName = this.Name
                }).ToList();
        }
Example #5
0
        public string CreateUser(SocialIdentity identity)
        {
            using (var context = new SocialDataContext(this.connectionString))
            {
                var socialUserId = Guid.NewGuid();

                var networkUser = new NetworkUser
                {
                    NetworkUserId = identity.Id,
                    Provider = identity.ProviderName,
                    SocialUserId = socialUserId,
                    Token = identity.Token,
                    Secret = identity.Secret,
                    Expires = identity.Expires,
                    Name = identity.Name
                };
                context.NetworkUsers.InsertOnSubmit(networkUser);

                context.SubmitChanges();

                return networkUser.Name;
            }
        }
Example #6
0
        public void AssociateIdentity(string userId, SocialIdentity identity)
        {
            using (var context = new SocialDataContext(this.connectionString))
            {
                /// Associate the network user to the social user
                var networkUser = context.NetworkUsers.FirstOrDefault(u => u.NetworkUserId == identity.Id &&
                                                                      u.Provider == identity.ProviderName);
                if (networkUser == null)
                {
                    networkUser = new NetworkUser
                    {
                        NetworkUserId = identity.Id,
                        Provider = identity.ProviderName,
                        SocialUserId = new Guid(userId),
                        Token = identity.Token,
                        Secret = identity.Secret,
                        Expires = identity.Expires,
                        Name = identity.Name
                    };
                    context.NetworkUsers.InsertOnSubmit(networkUser);
                }
                else
                {
                    var oldUserID = networkUser.SocialUserId;
                    networkUser.SocialUserId = new Guid(userId);
                }

                /// remove old network user associations within the same provider
                var oldNetworkUsers = context.NetworkUsers.Where(u => u.Provider == identity.ProviderName &&
                                                                      u.NetworkUserId != identity.Id &&
                                                                      u.SocialUserId.ToString() == userId).ToList();
                context.NetworkUsers.DeleteAllOnSubmit(oldNetworkUsers);

                context.SubmitChanges();
            }
        }
Example #7
0
 public PhotoUpload UploadPhoto(SocialIdentity identity, byte[] image, string name, string contentType, string caption)
 {
     return this.client.UploadPhoto(identity.Token, image, name, contentType, caption);
 }
Example #8
0
 public void UpdateStatus(SocialIdentity identity, string status)
 {
     this.client.SetStatus(identity.Token, status);
 }
Example #9
0
        public UserDetails GetUserDetails(SocialIdentity identity)
        {
            var user = this.client.GetUser(identity.Token);

            return new UserDetails
            {
                Id = user.UserId.ToString(),
                Name = user.Name,
                ProfilePictureUrl = user.PictureUrl,
                ProfileUrl = user.ProfileUrl,
                Identity = identity
            };
        }
Example #10
0
 public SocialPrincipal(SocialIdentity identity, IDataService dataService)
 {
     _identity = identity;
     _dataService = dataService;
 }
Example #11
0
 public void UpdateStatus(SocialIdentity identity, string status)
 {
     var accessToken = new AccessToken { Token = identity.Token, TokenSecret = identity.Secret };
     this.client.UpdateStatus(accessToken, OAuthHelper.UrlEncode(status));
 }
Example #12
0
        public UserDetails GetUserDetails(SocialIdentity identity)
        {
            var accessToken = new AccessToken { Token = identity.Token, TokenSecret = identity.Secret };

            var user = this.client.GetUser(accessToken, int.Parse(identity.Id));

            return new UserDetails
            {
                Id = user.Id.ToString(),
                Name = user.Name,
                ProfilePictureUrl = user.ProfileImageUrl,
                ProfileUrl = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", UrlResources.WebSiteUrl, user.ScreenName),
                Identity = identity
            };
        }
Example #13
0
        public string FindIdentity(SocialIdentity identity)
        {
            using (var context = new SocialDataContext(this.connectionString))
            {
                var user = context.NetworkUsers.FirstOrDefault(u => u.NetworkUserId == identity.Id && u.Provider == identity.ProviderName);
                if (user != null)
                {
                    user.Token = identity.Token;
                    user.Secret = identity.Secret;
                    user.Expires = identity.Expires;
                    user.Name = identity.Name;
                    context.SubmitChanges();

                    //return user.SocialUserId.ToString();
                    return user.Name;
                }
                else
                {
                    return null;
                }
            }
        }