locked
it is not taking a values RRS feed

  • Question

  • User331411 posted

    loginpage.cs using CenturaTechnologies.Models; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

    using Xamarin.Forms; using Xamarin.Forms.Xaml;

    namespace CenturaTechnologies.Views { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class LoginPage : ContentPage { LoginResponseModel loginResponseModel = new LoginResponseModel(); public LoginPage() { InitializeComponent(); // load(); }

        private async void Button_Clicked(object sender, EventArgs e)
        {
            try
            {
                var result = await ApiClass.GetAsyncMethod(ApiClass.login + "?UserName=" + username.Text + "?Password=" + password.Text);
                loginResponseModel = JsonConvert.DeserializeObject<LoginResponseModel>(result);
                if (string.Equals(loginResponseModel.UserName, username) && string.Equals(loginResponseModel.Password, password))
                {
                    await DisplayAlert("Login", "Login Successful", "OK");
                    await Navigation.PushAsync(new LeaveForm());
                }
            }
            catch (Exception ex)
            {
            }
    
        }
    }
    

    }

    apiclass.cs using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks;

    namespace CenturaTechnologies.Models { public class ApiClass { public static string login = "login"; public static string Url = "http://192.168.0.161:82/api/CenApi/"; public static string PingUrl = "http://google.com"; public static int PingPort = 80; private static HttpClient client;

        static ApiClass()
        {
            client = new HttpClient();
            client.BaseAddress = new Uri(Url);
        }
        public static async Task<string> GetAsyncMethod(string url)
        {
            try
            {
                var result = await client.GetAsync(url);
                if (result.IsSuccessStatusCode)
                {
                    string res = await result.Content.ReadAsStringAsync();
                    return res;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
    
            }
            return null;
        }
    }
    

    }

    loginresponsemodel.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

    namespace CenturaTechnologies.Models { class LoginResponseModel { public string Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public DateTime DateOfBirth { get; set; } public string Gender { get; set; } public string MaritalStatus { get; set; } public string Address { get; set; } public string PhoneNumber { get; set; } public string Email { get; set; } public DateTime DateOfJoining { get; set; } public string EmployeeNumber { get; set; } public string TypeName { get; set; } public int Salary { get; set; } public string Domain { get; set; } public string UserName { get; set; } public string Password { get; set; }

    }
    

    }

    Wednesday, June 28, 2017 6:34 AM

All replies

  • User318788 posted

    @Anupa,

    It is not taking a values !!!!! WHAT ONE SHOULD INTERPRET FROM THIS? Okey pasting your entire code here does not help either.

    You're code has several flaws in you app (API) (other from what is not working I do not know)

    First, You should NOT use GetAsync and send the credentials in clear text, respect some privacy and provide some security to users. Better use PostAsync, do not send credentials, send a hash/encrypted values.

    Second, What in the world makes you compare the username and password returned from database/storage and prompt the user that his/her login is successful. Rather send a Hash and compare hash on server side and return boolean from API/service

    Third, Why your LoginResponseModel carries the burden of responsibility of EmployeeDetail, this rather should be post login service call.

    What I think of Centura Technologies as Bengaluru's one of the fine company, don't mess it's reputation.

    Sorry for being little harsh on you, however, when you ask something be specific, and before asking online in forum, ask your mentor/team lead or discuss with colleague, follow the best practices, read some blogs and improve your coding. I don't know your overall experience level on the development front, however I must say you're going good, only you need to improve yourself. Best of luck.

    Wednesday, June 28, 2017 7:11 AM