Exemplo n.º 1
0
        public async Task <ActionResult> AuthorizeYa(AuthorizeForm authorizeForm)
        {
            var success = await yandexService.CheckCredentialsAsync(authorizeForm.Login, authorizeForm.Pass)
                          .ConfigureAwait(true);

            Response.SetCookies(Constants.YaLoginCookie, authorizeForm.Login ?? string.Empty);

            if (!success)
            {
                return(PartialView("AuthorizeResult", new AuthorizeResult {
                    Success = false
                }));
            }

            var authInfo = authorizationSettings.GetCachedMuserAuthorization(UserId);

            if (authInfo == null)
            {
                authInfo = new MuserAuthorization
                {
                    YaLogin    = authorizeForm.Login,
                    YaPassword = authorizeForm.Pass
                };
            }
            else
            {
                authInfo.YaLogin    = authorizeForm.Login;
                authInfo.YaPassword = authorizeForm.Pass;
            }

            authorizationSettings.SetMuserAuthorization(authInfo, UserId);

            return(await GetYaPlaylists().ConfigureAwait(true));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> YandexAuthorize(YandexAuthorizeForm authorizeForm, Guid sessionId)
        {
            if (captcha.IsForbid(UserId, "Yandex"))
            {
                return(View("YandexAuthorize", new YandexAuthorizeForm {
                    Login = authorizeForm.Login, Forbid = true
                }));
            }

            var success = await yandexService.CheckCredentialsAsync(authorizeForm.Login, authorizeForm.Pass)
                          .ConfigureAwait(true);

            Response.SetCookies(Constants.YaLoginCookie, authorizeForm.Login ?? string.Empty);

            if (!success)
            {
                captcha.IncrementForbid(UserId, "Yandex");
                return(View("YandexAuthorize",
                            new YandexAuthorizeForm {
                    Login = authorizeForm.Login, AuthFailed = true
                }));
            }

            var authInfo = authorizationSettings.GetCachedMuserAuthorization(UserId);

            if (authInfo == null)
            {
                authInfo = new MuserAuthorization
                {
                    YaLogin    = authorizeForm.Login,
                    YaPassword = authorizeForm.Pass
                };
            }
            else
            {
                authInfo.YaLogin    = authorizeForm.Login;
                authInfo.YaPassword = authorizeForm.Pass;
            }

            authorizationSettings.SetMuserAuthorization(authInfo, UserId);

            return(await GetYaPlaylists(sessionId).ConfigureAwait(true));
        }