public async Task <SocialUser> GetOrCreateFacebookUser(string token, string fbUserId) { var user = FindByOriginalId(fbUserId, SocialUserSource.Facebook); if (user == null) { FbUser fbUser = await _fbClient.GetUserInfo(token, fbUserId); user = FindByOriginalId(fbUserId, SocialUserSource.Facebook); if (user == null) { user = new SocialUser { OriginalId = fbUser.id, Name = fbUser.name, Email = fbUser.email, OriginalLink = fbUser.link, Avatar = fbUser.pic, Source = SocialUserSource.Facebook }; await UnitOfWorkManager.RunWithNewTransaction(CurrentUnitOfWork.GetSiteId(), async() => { await InsertAsync(user); }); } } if (user.IsDeleted) { user.IsDeleted = false; user.Type = SocialUserType.Customer; Update(user); } return(user); }
public async Task <UserInfoDto> FindPublicInfoAsync(int socialUserId) { UserInfoDto userInfoDto = new UserInfoDto { Id = socialUserId }; SocialUser user = _domainService.FindAllWithDeleted().FirstOrDefault(t => t.Id == socialUserId); if (user == null) { return(userInfoDto); } if (user.Source == SocialUserSource.Facebook) { FbUser facebookInfo = await _fbClient.GetUserInfo(user.OriginalId); userInfoDto.Source = SocialUserSource.Facebook; userInfoDto.Name = facebookInfo.name; userInfoDto.Email = facebookInfo.email; userInfoDto.Link = facebookInfo.link; userInfoDto.OriginalId = facebookInfo.id; userInfoDto.Avatar = facebookInfo.pic; if (user.Avatar != userInfoDto.Avatar || user.Email != userInfoDto.Email) { user.Avatar = userInfoDto.Avatar; user.Email = userInfoDto.Email; _domainService.Update(user); } } else if (user.Source == SocialUserSource.Twitter) { var account = _domainService.FindAll().Where(t => t.Type == SocialUserType.IntegrationAccount && t.Source == SocialUserSource.Twitter).Select(t => t.SocialAccount).FirstOrDefault(); if (account != null) { IUser twitterUserInfo = _twitterClient.GetUser(account.Token, account.TokenSecret, long.Parse(user.OriginalId)); if (twitterUserInfo != null) { userInfoDto.Source = SocialUserSource.Twitter; userInfoDto.Name = twitterUserInfo.Name; userInfoDto.OriginalId = twitterUserInfo.Id.ToString(); userInfoDto.Avatar = twitterUserInfo.ProfileImageUrl; userInfoDto.Link = TwitterHelper.GetUserUrl(twitterUserInfo.ScreenName); userInfoDto.ScreenName = twitterUserInfo.ScreenName; userInfoDto.Location = twitterUserInfo.Location; userInfoDto.FollowersCount = twitterUserInfo.FollowersCount; userInfoDto.FriendsCount = twitterUserInfo.FriendsCount; userInfoDto.StatusesCount = twitterUserInfo.StatusesCount; userInfoDto.Description = twitterUserInfo.Description; userInfoDto.JoinedDate = twitterUserInfo.CreatedAt; if (twitterUserInfo.Entities.Website != null) { userInfoDto.Website = twitterUserInfo.Entities.Website.Urls.First().DisplayedURL; } if (user.Avatar != userInfoDto.Avatar || user.Email != userInfoDto.Email) { user.Avatar = userInfoDto.Avatar; user.Email = userInfoDto.Email; _domainService.Update(user); } } } } return(userInfoDto); }