Exemplo n.º 1
0
        public async Task <LoginApiResponseModel> AuthenticateUserAsync(string phonenumber, string password)
        {
            try
            {
                LoginApiRequestModel loginRequestModel = new LoginApiRequestModel()
                {
                    UserName = phonenumber,
                    Password = password
                };
                var content = new StringContent(JsonConvert.SerializeObject(loginRequestModel), Encoding.UTF8, "application/json");
                //Change your base address tail part here and post it.
                var response = await client.PostAsync("umbraco/surface/appmembership/loginuser", content);

                response.EnsureSuccessStatusCode();
                using (var stream = await response.Content.ReadAsStreamAsync())
                    using (var reader = new StreamReader(stream))
                        using (var json = new JsonTextReader(reader))
                        {
                            var jsoncontent = _serializer.Deserialize <LoginApiResponseModel>(json);

                            return(jsoncontent);
                        }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The login.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="loginRequest">The login request.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        public async Task <HttpResponseMessage> Login(string accessToken, LoginApiRequestModel loginRequest)
        {
            // add content
            var content = "{\"UserDetails\":{\"UserId\":\"51d1d2ba-0196-4c60-8970-b8544cfc9d62\",\"FirstName\":\"Laura\",\"LastName\":\"Smith\",\"Email\":\"[email protected]\",\"EmailConfirmed\":true,\"PasswordHash\":\"AOGxSZwbrXTFhgB0xDdcy2Fone44MxCnkHbW+II62S8KrOLU5LarRm5ezeJL7n3Iag==\",\"SecurityStamp\":\"a598082c-1137-43df-9a5c-170a1f402370\",\"PhoneNumber\":null,\"PhoneNumberConfirmed\":false,\"TwoFactorEnabled\":false,\"LockoutEndDateUtc\":\"2017-04-27T12:11:05.51\",\"LockoutEnabled\":true,\"AccessFailedCount\":0,\"Roles\":[],\"Claims\":[],\"Logins\":[],\"Id\":\"92d171c8-b360-4862-beaa-c615fb76ef72\",\"UserName\":\"[email protected]\"},\"VerificationToken\":null}";

            return(await this.GetFakeResponse(content));
        }
Exemplo n.º 3
0
        // Аунтефикация
        public async Task <LoginApiResponseModel> AuthenticateUserAsync(string login, string password)
        {
            try
            {
                LoginApiRequestModel loginRequestModel = new LoginApiRequestModel()
                {
                    Login    = login,
                    Password = password
                };
                using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, client.BaseAddress + _loginPath);
                request.Headers.Add("login", loginRequestModel.Login);
                request.Headers.Add("password", loginRequestModel.Password);
                var response = await client.SendAsync(request);

                response.EnsureSuccessStatusCode();
                using (var stream = await response.Content.ReadAsStreamAsync())
                    using (var reader = new StreamReader(stream))
                        using (var json = new JsonTextReader(reader))
                        {
                            var jsoncontent = _serialazer.Deserialize <LoginApiResponseModel>(json);
                            return(jsoncontent);
                        }

                /*
                 * var responce = await client.GetAsync(_registerPath);
                 * responce.EnsureSuccessStatusCode();
                 * using (var stream = await responce.Content.ReadAsStreamAsync())
                 * using (var reader = new StreamReader(stream))
                 * using (var json = new JsonTextReader(reader))
                 * {
                 *  var jsoncontent = _serialazer.Deserialize<LoginApiResponceModel>(json);
                 *  return jsoncontent;
                 * }
                 */
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        /// <summary>The login.</summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="loginRequest">The login request.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        public async Task <HttpResponseMessage> Login(string accessToken, LoginApiRequestModel loginRequest)
        {
            var authApi = RestService.For <IAuthenticationApiWrapper>(
                new HttpClient(new AuthenticatedHttpClientHandler(accessToken))
            {
                BaseAddress = new Uri(
                    SharedConfig.ApiEndpoint)
            });

            var response = new HttpResponseMessage();

            try
            {
                response = await authApi.Login(accessToken, loginRequest);
            }
            catch (ApiException ex)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError));
            }

            return(response);
        }