Exemplo n.º 1
0
        private string GetLoginToken(string json)
        {
            string token = null;

            var resp = LoginResponse.FromJson(json);

            token = resp.Token;

            return(token);
        }
Exemplo n.º 2
0
        public static LoginResponse PostLogin(LoginRequest login)
        {
            //DONE: PostLogin
            var client  = new RestClient(BASEURL);
            var request = new RestRequest("Users/login", Method.POST);

            request.AddJsonBody(login.ToJson());
            var response = client.Execute(request);

            return(LoginResponse.FromJson(response.Content));
        }
Exemplo n.º 3
0
        public static LoginResponse PostLogin(LoginRequest login)
        {
            var client  = new RestClient(BASEURL);
            var request = new RestRequest("Users/login", Method.POST);

            request.AddJsonBody(login.ToJson());
            var response = client.Execute(request);

            // Console.WriteLine("Content" + response.Content);
            // Console.WriteLine("Status Code" + response.StatusCode);//NotFound|Created|BadRequest
            return(LoginResponse.FromJson(response.Content));
        }
Exemplo n.º 4
0
        async Task CheckLoginAttempt()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            bool success = false;

            try
            {
                var client = Utilities.GetClient();


                var loginResponse =
                    await client.PostAsync(client.BaseAddress, new StringContent(Utilities.GetPOSTJson(Username, Password),
                                                                                 Encoding.UTF8,
                                                                                 "application/json"));

                var json = await loginResponse.Content.ReadAsStringAsync();

                var response = LoginResponse.FromJson(json);

                if (!response.Valid)
                {
                    await Application.Current.MainPage.DisplayAlert("Login failed.", "Your login details are incorrect.", "OK");
                }
                else
                {
                    success = true;
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Something went wrong",
                                                                ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }

            if (success)
            {
                success = false;
                await Application.Current.MainPage.DisplayAlert("Successful login!", $"Welcome, {Username}.", "OK");

                Application.Current.MainPage = new FixturesPage();
            }
        }
        public async Task <LoginResponse> Login(string username, string password)
        {
            RequestParameterCollection parameters = new RequestParameterCollection();

            parameters.AddParameter("username", username);
            parameters.AddParameter("password", password);

            string apiResponse = await GetResponse(baseUrl + "login.php" + parameters.ToString());

            userCredentials = LoginResponse.FromJson(apiResponse);

            return(LoginResponse.FromJson(apiResponse));
        }
        public static LoginResponse PostLogin(LoginRequest login)
        {
            //TODO: PostLogin
            var client  = new RestClient(BASEURL);
            var request = new RestRequest("Users/login", Method.POST);

            //request.AddParameter("data", data);
            request.AddJsonBody(login.ToJson());
            var response = client.Execute(request);

            //Console.WriteLine(response.Content);
            //Console.WriteLine(response.StatusCode);//NotFound|Created|BadRequest
            // if (response.StatusCode.ToString().Contains("BadRequest"))
            // {
            //     return new LoginResponse { Token = response.Content };
            // }
            return(LoginResponse.FromJson(response.Content));
        }
        public static LoginResponse PostLogin(LoginRequest login)
        {
            // TODO: ===== PostLogin

            var client  = new RestClient(BASEURL);
            var request = new RestRequest("users/login", Method.POST);

            request.AddJsonBody(login);

            var response = client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                return new LoginResponse {
                           UserName = "******", Token = "Invalid credentials"
                }
            }
            ;

            return(LoginResponse.FromJson(response.Content));
        }