Beispiel #1
0
    public void GetProfileOfUser()
    {
        GetProfile.GetUserProfile(
            (response) => {
            ProfileResponse profileResponse = (ProfileResponse)response;

            State.UserProfile = profileResponse.profile;

            StartCoroutine(showPopUpT("successfully signed in", "success"));

            StartCoroutine(GotoMainMenu());
        },
            (statusCode, error) => {
            GoToLogin();

            if (statusCode == StatusCodes.CODE_VALIDATION_ERROR)
            {
                ValidationError validationError = (ValidationError)error;
                StartCoroutine(showPopUpT(validationError.errors.First().Value[0], "error"));
            }
            else
            {
                GenericError genericError = (GenericError)error;
                StartCoroutine(showPopUpT(genericError.message, "error"));
            }
        }
            );
    }
Beispiel #2
0
        public async Task <UserProfileMold> Get(GetProfile request)
        {
            var user = await RavenSession.LoadAsync <User>(request.UserId);

            var mapped = Mapper.Map <UserProfileMold>(user);

            return(mapped);
        }
Beispiel #3
0
        public async Task <IActionResult> CreateGoogle([FromBody] string idToken)
        {
            try
            {
                //Usa biblioteca para acessar o google e pegar o perfil
                GetProfile getProfile = new GetProfile();

                //Classe com os campos de retorno do google
                ObjetoGoogle profile = await getProfile.Acessar(idToken);

                if (profile != null)
                {
                    UsuarioModel model = new UsuarioModel
                    {
                        Email = profile.email,
                        Nome  = profile.name,
                        Senha = Guid.NewGuid().ToString()
                    };

                    var usuarioResult = await Create(model);

                    //Faz o casting da resposta do metodo
                    var aux = usuarioResult as CreatedAtActionResult;

                    if (aux != null)
                    {
                        var tokenClient   = new TokenClient("http://identityservertcc.azurewebsites.net/connect/token", "jarbasApp", "secret");
                        var tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync(model.Email, model.Senha, "jarbasApi offline_access");

                        if (!tokenResponse.IsError)
                        {
                            var usuario = aux.Value as Usuario;
                            var token   = tokenResponse.Json;
                            return(CreatedAtAction("Create", new { usuario, token }));
                        }
                        else
                        {
                            ModelState.AddModelError("Token", "O usuário foi criado, porém houve um erro no login, tente novamente");
                            return(BadRequest(ModelState.Values.SelectMany(e => e.Errors)));
                        }
                    }
                    else
                    {
                        return(usuarioResult);
                    }
                }
                else
                {
                    ModelState.AddModelError("Google", "Erro ao obter informações do Google, tente novamente");
                    return(BadRequest(ModelState.Values.SelectMany(e => e.Errors)));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Beispiel #4
0
    protected void ButtonAsynGet_Click(object sender, EventArgs e)
    {
        GetProfile getProfileDel = () =>
        {
            return(ApplicationContext.Current.Profile);
        };
        IAsyncResult asynResult = getProfileDel.BeginInvoke(null, null);
        Profile      profile    = getProfileDel.EndInvoke(asynResult);

        this.TextBoxFirstName.Text = profile.FirstName;
        this.TextBoxLastName.Text  = profile.LastName;
        this.TextBoxAge.Text       = profile.Age.ToString();
    }
Beispiel #5
0
        private void buttonAsyncGet_Click(object sender, EventArgs e)
        {
            GetProfile getProfileDel = () =>
            {
                return(ApplicationContext.Current.Profile);
            };
            IAsyncResult asynResult = getProfileDel.BeginInvoke(null, null);
            Profile      profile    = getProfileDel.EndInvoke(asynResult);

            this.textBoxFirstName.Text  = profile.FirstName;
            this.textBoxLastName.Text   = profile.LastName;
            this.numericUpDownAge.Value = profile.Age;
        }
        public async Task Profile_is_looked_up_by_twitch_username()
        {
            // arrange
            var username = "******";
            var request  = new GetProfile(username);

            MockCollection.Setup(m => m.GetAsync(It.IsAny <string>(), null))
            .ReturnsAsync(new FakeGetResult(new TwitcherProfile()));

            // act
            await _handler.Handle(request, CancellationToken.None);

            // assert
            MockCollection.Verify(m => m.GetAsync(username, It.IsAny <GetOptions>()), Times.Once);
        }
Beispiel #7
0
        private async Task LoadProfileAsync(GetProfile query, HttpQueryDispatcher.Next next)
        {
            if (!serverConnection.IsAvailable)
            {
                profile = await localStorage.LoadAsync();

                if (profile != null)
                {
                    return;
                }
            }

            profile = (ProfileModel) await next(query);

            await localStorage.SaveAsync(profile);
        }
Beispiel #8
0
        private async Task LoadProfileAsync(GetProfile query, HttpQueryDispatcher.Next next)
        {
            if (!network.IsOnline)
            {
                profile = await localStorage.LoadAsync();

                if (profile != null)
                {
                    return;
                }
            }

            profile = (ProfileModel) await next(query);

            await localStorage.SaveAsync(profile);
        }
Beispiel #9
0
        public async Task Profile_is_looked_up_by_twitch_username()
        {
            // arrange
            var username = "******";
            var request  = new GetProfile(username);

            _mockBucket.Setup(m => m.GetAsync <TwitcherProfile>(It.IsAny <string>()))
            .ReturnsAsync(new FakeOperationResult <TwitcherProfile> {
                Value = new TwitcherProfile()
            });

            // act
            await _handler.Handle(request, CancellationToken.None);

            // assert
            _mockBucket.Verify(m => m.GetAsync <TwitcherProfile>(username), Times.Once);
        }
Beispiel #10
0
    public void GetProfileOfUser()
    {
        StaticImage.SetActive(false);
        AnimaterImage.SetActive(true);
        GetProfile.GetUserProfile(
            (response) => {
            StaticImage.SetActive(true);
            AnimaterImage.SetActive(false);

            ProfileResponse profileResponse = (ProfileResponse)response;

            State.UserProfile = profileResponse.profile;
        },
            (statusCode, error) => {
            StaticImage.SetActive(true);
            AnimaterImage.SetActive(false);
        }
            );
    }
Beispiel #11
0
        public async Task ValidateAsync(ExtensionGrantValidationContext context)
        {
            var userToken = context.Request.Raw.Get("id_token");

            if (string.IsNullOrEmpty(userToken))
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Token não pode ser nulo");
                return;
            }

            //Usa biblioteca para acessar o google e pegar o perfil
            GetProfile getProfile = new GetProfile();

            //Classe com os campos de retorno do google
            ObjetoGoogle profile = await getProfile.Acessar(userToken);

            if (profile != null)
            {
                var usuario = await identityContext.Usuario.FirstOrDefaultAsync(u => u.Email.Equals(profile.email));

                if (usuario != null)
                {
                    context.Result = new GrantValidationResult(usuario.Id, "google");
                    return;
                }
                else
                {
                    context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Usuário não cadastrado");
                    return;
                }
            }
            else
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Erro ao obter informações do Google, tente novamente");
                return;
            }
        }
Beispiel #12
0
        public object Get(GetProfile request)
        {
            try
            {
                var token = AuthService.CheckPermitions(Request.Headers["Authorization"], Db);
                if (token == null)
                    return Unauthorized("Please, authorize");


                var code = Db.GetByIdOrDefault<OAuthCode>(token.Code);
                if (code == null)
                    return NotFound("");

                var user = Db.GetById<User>(code.UserLogin);
                if (user == null)
                    return NotFound("");

                return new HttpResult(Mapper.Map<UserDto>(user), $"{MimeTypes.Json}; charset=utf-8");
            }
            catch
            {
                return new HttpError(HttpStatusCode.InternalServerError, "Internal Server Error");
            }
        }
Beispiel #13
0
 public async Task <ProfileModel> GetProfileAsync(GetProfile getProfile)
 {
     return(await _mediator.Send(getProfile));
 }
Beispiel #14
0
 private async Task LoadProfileAsync(GetProfile query, HttpQueryDispatcher.Next next)
 {
     profile = (ProfileModel) await next(query);
 }
Beispiel #15
0
        public async Task <ProfileModel> Get(GetProfile request)
        {
            request.User = _currentUserProvider.GetUser();

            return(await _mediator.Send(request));
        }
 public IProfileModel Any(GetProfile request)
 {
     return(workflow.Get(request.ID));
 }