public ActionResult FacebookLogin(string email, string socialPlatform, string imgUrl, int type)
 {
     if (_accountService.IsSocialAccountRegister(email, socialPlatform))
     {
         var cookie = Helpers.SetCookie(_accountService.GetUser(email).AccountName, false);
         Response.Cookies.Add(cookie);
         return(Json(new { response = "第三方登入", status = 1 }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         if (type == 0)
         {
             var info = new SocialInfo
             {
                 SocialPlatform = socialPlatform,
                 Email          = email,
                 ImgUrl         = imgUrl
             };
             return(Json(new { response = JsonConvert.SerializeObject(info), status = 1 }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { response = "尚未註冊", status = 0 }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Exemplo n.º 2
0
        public static async void ParseSocial(string json, SocialInfo socialInfo)
        {
            SocialRootObject socialRootObject;

            if (socialInfo.GetType() == typeof(FacebookInfo))
            {
                socialRootObject = JObject.Parse(json).ToObject <FacebookRootObject>();
            }
            else if (socialInfo.GetType() == typeof(MicrosoftInfo))
            {
                socialRootObject = JObject.Parse(json).ToObject <MicrosoftRootObject>();
            }
            else// if (socialInfo.GetType() == typeof(GoogleInfo))
            {
                socialRootObject = JObject.Parse(json).ToObject <GoogleRootObject>();
            }

            var o = socialRootObject;

            if (o != null)
            {
                SocialRootObject = o;
                await _navPage.PopModalAsync();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Отображает результаты пожествования
 /// </summary>
 protected override void DisplayResult(SocialInfo info)
 {
     message.text = $"СЕГОДНЯ ФОНД <color=#00fff4>«{info.AdditionalText}»</color> " +
                    $"ПОЛУЧИЛ {info.CharityAmount.DisplayMoney()} " +
                    $"С СООБЩЕНИЕМ: <color=#00fff4>«{info.MainText}»</color>";
     hype.text = $"+{info.HypeIncome}";
 }
Exemplo n.º 4
0
        protected override void BeforePageClose()
        {
            base.BeforePageClose();

            workPoints.text = "0";
            _social         = null;
        }
Exemplo n.º 5
0
        public void ShowPage(SocialInfo social)
        {
            _social = social;
            analyzer.Analyze(_social);

            Open();
            DisplayResult(social);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Отображает результат твита
        /// </summary>
        protected override void DisplayResult(SocialInfo info)
        {
            nickname.text = PlayerManager.Data.Info.NickName;
            message.text  = info.MainText;

            likes.text = info.Likes.ToString();
            hype.text  = $"+{info.HypeIncome}";
        }
Exemplo n.º 7
0
        /// <summary>
        /// Отображает результат фотографии в инсте
        /// </summary>
        protected override void DisplayResult(SocialInfo info)
        {
            picture.sprite = pics[info.ModeIndex];
            comment.text   = info.MainText;

            likes.text = info.Likes.ToString();
            hype.text  = $"+{info.HypeIncome}";
        }
Exemplo n.º 8
0
        /// <summary>
        /// Отображает результаты трансляции в соц. сети
        /// </summary>
        protected override void DisplayResult(SocialInfo info)
        {
            comment.text = info.MainText;
            // todo: check info.ModeIndex

            likes.text = info.Likes.ToString();
            hype.text  = $"+{info.HypeIncome}";
        }
Exemplo n.º 9
0
        /// <summary>
        /// Отображает результаты тик-тока
        /// </summary>
        protected override void DisplayResult(SocialInfo info)
        {
            animator.SetInteger(Type, info.ModeIndex);
            comment.text = info.MainText;

            likes.text = info.Likes.ToString();
            hype.text  = $"+{info.HypeIncome}";
        }
Exemplo n.º 10
0
        /// <summary>
        /// Отображает результаты игрового стрима
        /// </summary>
        protected override void DisplayResult(SocialInfo info)
        {
            string nickName = PlayerManager.Data.Info.NickName;

            streamName.text = $"\"{info.MainText}\" by {nickName}";

            likes.text = info.Likes.ToString();
            hype.text  = $"+{info.HypeIncome}";
        }
Exemplo n.º 11
0
 private void SetClicked <T>(Button button, SocialInfo socialInfo)
 {
     if (Device.OS == TargetPlatform.WinPhone)
     {
         button.Clicked += (sender, e) => DependencyService.Get <ILogin>().Show(socialInfo);
     }
     else
     {
         button.Clicked += (sender, e) => Navigation.PushModalAsync(new LoginOathPage(socialInfo));
     }
 }
        public async Task <IActionResult> Update(int id, [FromBody] SocialInfo socialInfo)
        {
            if (id == default || socialInfo == null)
            {
                return(BadRequest());
            }

            await _tagService.AddOrUpdateAsync(id, socialInfo);

            return(NoContent());
        }
        public async Task <IActionResult> Add(IFormFileCollection files, [FromForm] SocialInfo socialInfo)
        {
            if (files?.Count > 0)
            {
                var imagePaths = new List <string>();

                foreach (var file in files)
                {
                    if (file.Length == 0)
                    {
                        continue;
                    }

                    var imagePath = $"{Path.GetTempFileName()}.{file.FileName}";

                    using (var fileStream = new FileStream(imagePath, FileMode.Append))
                    {
                        await file.CopyToAsync(fileStream);
                    }

                    var faces = await _imageService.DetectFaceAsync(imagePath);

                    var biggestFace = faces.OrderByDescending(x => x.Width * x.Height).FirstOrDefault();

                    if (biggestFace == null)
                    {
                        continue;
                    }

                    imagePaths.Add(biggestFace.Path);
                }

                if (imagePaths.Count > 0)
                {
                    var id = await _idService.GetAsync();

                    await _imageService.AddAsync(id, imagePaths);

                    if (socialInfo != null)
                    {
                        await _tagService.AddOrUpdateAsync(id, socialInfo);
                    }

                    return(Ok(id));
                }
            }

            return(BadRequest());
        }
        public async Task AddOrUpdateAsync(int id, SocialInfo socialInfo)
        {
            await Task.CompletedTask;

            var files = Directory.GetFiles(DataFolder, "*.image");

            if (files.Any() && socialInfo != null)
            {
                socialInfo.Id = id;

                var infoPath = Path.Combine(DataFolder, $"{id.ToString()}.json");

                var infoJson = JsonConvert.SerializeObject(socialInfo);

                File.WriteAllText(infoPath, infoJson);
            }
        }
Exemplo n.º 15
0
        public async Task <ActionResult> GoogleLogin2(string token, int type)
        {
            var result = await _memberservice.GetGoogleInfo(token);

            if (result.IsSuccessful)
            {
                var googleTokenInfo = JsonConvert.DeserializeObject <GoogleApiTokenInfo>(result.MessageInfo);

                if (_memberservice.IsSocialAccountRegister(googleTokenInfo.Email, "Google")) //檢查此帳戶是否存在並註冊
                {
                    MemberViewModel member = _api.GetMember(x => x.MemberRegEmail == googleTokenInfo.Email && x.IsThirdParty == "Google");

                    Session["Permission"] = member.Permission; //存session
                    Session["Member"]     = member;            //存session

                    return(Json(new { response = "第三方登入", status = 1 }));
                }
                else
                {
                    if (type == 0) //若不是,去判斷是進行註冊還是登入
                    {
                        var SocialInfo = new SocialInfo
                        {
                            Email          = googleTokenInfo.Email,
                            SocialPlatform = "Google",
                            ImgUrl         = googleTokenInfo.Picture,
                        };

                        return(Json(new { response = JsonConvert.SerializeObject(SocialInfo), status = 1 }));
                    }
                    else
                    {
                        return(Json(new { response = "尚未註冊", status = 0 }));
                    }
                }
            }
            else
            {
                return(Json(new { response = "發生錯誤", status = 0 }));
            }
        }
Exemplo n.º 16
0
        public async Task <ActionResult> GoogleLogin(string token, int type)
        {
            var result = await _accountService.GetGoogleInfo(token);

            if (result.IsSuccessful)
            {
                var googleTokenInfo = JsonConvert.DeserializeObject <GoogleApiTokenInfo>(result.MessageInfo);

                if (_accountService.IsSocialAccountRegister(googleTokenInfo.Email, "Google")) //檢查此帳戶是否存在並註冊
                {
                    var cookie = Helpers.SetCookie(_accountService.GetUser(googleTokenInfo.Email).AccountName, false);
                    Response.Cookies.Add(cookie);
                    return(Json(new { response = "第三方登入", status = 1 }));
                }
                else
                {
                    if (type == 0) //若不是,去判斷是進行註冊還是登入
                    {
                        var SocialInfo = new SocialInfo
                        {
                            Email          = googleTokenInfo.Email,
                            SocialPlatform = "Google",
                            ImgUrl         = googleTokenInfo.Picture,
                        };

                        return(Json(new { response = JsonConvert.SerializeObject(SocialInfo), status = 1 }));
                    }
                    else
                    {
                        return(Json(new { response = "尚未註冊", status = 0 }));
                    }
                }
            }
            else
            {
                return(Json(new { response = "發生錯誤", status = 0 }));
            }
        }
Exemplo n.º 17
0
 public LoginOathPage(SocialInfo socialInfo)
 {
     SocialInfo = socialInfo;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Отображает результаты соц. действия
 /// </summary>
 protected abstract void DisplayResult(SocialInfo socialInfo);
Exemplo n.º 19
0
 /// <summary>
 /// Сохраняет результат социального действия
 /// </summary>
 private static void SaveResult(SocialInfo social)
 {
     GameManager.Instance.GameStats.SocialsCooldown = SOCIAL_COOLDOWN;
     PlayerManager.Instance.SpendMoney(social.CharityAmount);
     PlayerManager.Instance.AddHype(social.HypeIncome);
 }
Exemplo n.º 20
0
 public Task AddOrUpdateAsync(int id, SocialInfo socialInfo)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
 protected override void AfterPageClose()
 {
     SaveResult(_social);
     _social = null;
 }
Exemplo n.º 22
0
        public void Show(SocialInfo socialInfo)
        {
            // IEnumerable<Account> accounts = AccountStore.Create().FindAccountsForService("Facebook");

            var auth = new OAuth2Authenticator(
                clientId: socialInfo.clientId,         // your OAuth2 client id
                scope: socialInfo.scope,               // the scopes for the particular API you're accessing, delimited by "+" symbols
                authorizeUrl: socialInfo.authorizeUrl, // the auth URL for the service
                redirectUrl: socialInfo.redirectUrl);  // the redirect URL for the service

            auth.ClearCookiesBeforeLogin = false;
            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed += async(sender, eventArgs) =>
            {
                if (!eventArgs.IsAuthenticated)
                {
                    Debug.WriteLine("Not Authenticated");
                    return;
                }
                else
                {
                    // Now that we're logged in, make a OAuth2 request to get the user's info.
                    var request = new OAuth2Request("GET", new Uri(socialInfo.userInfoAPI), null, eventArgs.Account);
                    try
                    {
                        Response response = await request.GetResponseAsync();

                        var json = (await response.GetResponseTextAsync());

                        //Debug.WriteLine("Name: " + obj["name"]);



                        if (eventArgs.IsAuthenticated)
                        {
                            // Use eventArgs.Account to do wonderful things
                            //dynamic foo = JsonObject.Parse(json);
                            LoginGear.App.ParseSocial(json, socialInfo);
                            LoginGear.App.SuccessfulLoginAction.Invoke();
                        }
                        else
                        {
                            // The user cancelled
                        }
                    }

                    catch (OperationCanceledException)
                    {
                        Debug.WriteLine("Canceled");
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Error: " + ex.Message);
                    }
                }
            };

            Uri uri = auth.GetUI();

            App.RootFrame.Navigate(uri);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Запускает работу по социальному действию
 /// </summary>
 private void StartSocial(SocialInfo info)
 {
     workingPage.StartWork(info);
     Close();
 }
Exemplo n.º 24
0
 /// <summary>
 /// Начинает выполнение работы
 /// </summary>
 public override void StartWork(params object[] args)
 {
     _social = (SocialInfo)args[0];
     Open();
 }
Exemplo n.º 25
0
        public async Task TagBatchAsync()
        {
            var idService = new IdService();

            var imageService = new ImageService();

            var tagService = new TagService();

            var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images");

            var groupedFiles =
                Directory
                .GetFiles(dir, "*.*", SearchOption.AllDirectories)
                .GroupBy(x => Path.GetFileName(Path.GetDirectoryName(x)));

            foreach (var files in groupedFiles)
            {
                var dirName = files.Key;

                var id = await idService.GetAsync();

                var imagePaths = new List <string>();

                foreach (var imagePath in files)
                {
                    var fileName = Path.GetFileName(imagePath);

                    if (_ignoredFiles.Contains(fileName))
                    {
                        continue;
                    }

                    var faces = await imageService.DetectFaceAsync(imagePath);

                    var biggestFace = faces.OrderByDescending(x => x.Width * x.Height).FirstOrDefault();

                    if (biggestFace == null)
                    {
                        continue;
                    }

                    imagePaths.Add(biggestFace.Path);
                }

                if (imagePaths.Count == 0)
                {
                    continue;
                }

                var socialInfo = new SocialInfo
                {
                    Name = dirName
                };

                await imageService.AddAsync(id, imagePaths, train : false);

                await tagService.AddOrUpdateAsync(id, socialInfo);
            }

            await imageService.TrainAsync();
        }
Exemplo n.º 26
0
        private async Task <UserDto> RegisterExternalInternal(string provider, string userName, string userId, string externalAccessToken, string fullname = "")
        {
            var user = new ApplicationUser()
            {
                IsActive = true
            };

            if (provider == LoginType.Facebook.ToString())
            {
                #region get fb info

                var client  = new RestClient(new Uri("https://graph.facebook.com"));
                var request = new RestRequest("me", Method.GET);
                request.AddQueryParameter("access_token", externalAccessToken);
                request.AddQueryParameter("fields", "id,email,first_name,birthday,last_name");
                SocialInfo profile = client.Execute <SocialInfo>(request).Data;
                if (profile != null)
                {
                    user.Email    = profile.Email;
                    user.Name     = profile.FullName;
                    user.UserName = profile.Email;
                    user.Avatar   = $"https://graph.facebook.com/{userId}/picture?width=300&height=300";
                }

                #endregion
            }
            else if (provider == LoginType.Google.ToString())
            {
                #region get google info

                var client  = new RestClient(new Uri("https://www.googleapis.com/oauth2/v1/"));
                var request = new RestRequest("userinfo", Method.GET);
                request.AddQueryParameter("access_token", externalAccessToken);
                request.AddQueryParameter("fields", "id,email,name");
                SocialInfo profile = client.Execute <SocialInfo>(request).Data;
                if (profile != null)
                {
                    if (!string.IsNullOrEmpty(profile.Email))
                    {
                        user.Email = profile.Email;
                    }
                    user.Name = profile.Name;

                    // get avatar
                    client  = new RestClient("https://www.googleapis.com/plus/v1/people/");
                    request = new RestRequest(userId, Method.GET);
                    request.AddQueryParameter("fields", "image");
                    request.AddQueryParameter("key", ConfigurationManager.AppSettings["GoogleApiKey"]);
                    var avatarInfo = client.Execute <AvatarInfo>(request).Data;
                    if (avatarInfo != null)
                    {
                        user.Avatar = avatarInfo.Image?.Url;
                    }
                    //if (!string.IsNullOrEmpty(profile.Gender))
                    //    user.Gender = ("male".Equals(profile.Gender) ? GenderTypes.Male : GenderTypes.Female);
                    //if (!string.IsNullOrEmpty(profile.Birthday))
                    //{
                    //    user.BirthDay = DateTime.ParseExact(profile.Birthday, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                    //}
                }

                #endregion
            }
            //else if (provider == LoginType.LinkedIn.ToString())
            //{
            //    #region get linked info

            //    var client = new RestClient(new Uri("https://api.linkedin.com/v1/"));
            //    var request = new RestRequest("people/~:(id,first-Name,last-Name,email-address)", Method.GET);
            //    request.AddQueryParameter("format", "json");
            //    request.AddQueryParameter("oauth2_access_token", externalAccessToken);
            //    LinkedInInfo profile = client.Execute<LinkedInInfo>(request).Data;
            //    if (profile != null)
            //    {
            //        if (!string.IsNullOrEmpty(profile.EmailAddress))
            //            user.Email = profile.EmailAddress;
            //        //user.FullName = profile.FullName;
            //        //if (!string.IsNullOrEmpty(profile.Gender))
            //        //    user.Gender = ("male".Equals(profile.Gender) ? GenderTypes.Male : GenderTypes.Female);
            //        //if (!string.IsNullOrEmpty(profile.Birthday))
            //        //{
            //        //    user.BirthDay = DateTime.ParseExact(profile.Birthday, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            //        //}
            //    }

            //    #endregion
            //}
            //else if (provider == LoginType.Instagram.ToString())
            //{
            //    #region get instagram info

            //    var client = new RestClient(new Uri("https://api.instagram.com/v1/"));
            //    var request = new RestRequest("users/self", Method.GET);
            //    request.AddQueryParameter("access_token", externalAccessToken);
            //    InstagramInfo profile = client.Execute<InstagramInfo>(request).Data;
            //    if (profile != null)
            //    {
            //        //user.FullName = profile.Data.FullName;
            //        user.Email = $"{provider}{profile.Data.UserName}@iad.com";
            //    }

            //    #endregion
            //}
            //else if (provider == LoginType.Twitter.ToString())
            //{
            //    // generate email
            //    //user.FullName = fullname;
            //    user.Email = $"{userName}@iad.com";
            //}
            //create new user
            var userDto = Mapper.Map <UserDto>(user);
            userDto.Logins = new List <LoginsDto>()
            {
                new LoginsDto()
                {
                    LoginProvider = provider,
                    ProviderKey   = userId
                }
            };
            await _userService.InsertAsync(userDto);

            return(userDto);
        }