public AdminApp (Authentication auth) { _auth = auth; validateUser (); SetUI (); }
public RequestService (Authentication auth) { App.OnSocketEvent += App_OnSocketEvent; _auth = auth; validateUser (); SetUI (); }
public DriverView (Authentication auth) { App.OnSocketEvent += App_OnSocketEvent; _auth = auth; validateUser (); SetUI (); _currentUserStatus = 1; }
private static async Task<Requester> CreateRequester(Authentication authUser) { return new Requester() { _id = authUser.DetailedUserId._id, PhoneNumber = authUser.DetailedUserId.PhoneNumber, Name = authUser.DetailedUserId.Name, LastName = authUser.DetailedUserId.LastName, GeneralCalification = authUser.DetailedUserId.GeneralCalification }; }
private static async Task<Driver> CreateDriver(Authentication authUser) { Driver driver = null; TaskCompletionSource<Driver> completion = new TaskCompletionSource<Driver>(); System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create( TuGrua.Core.Backend.Constants.UriServer + TuGrua.Core.Backend.Constants.UriApi + TuGrua.Core.Backend.Constants.GetDetailedUser + "?id=" + authUser.DetailedUserId._id); request.Method = "GET"; request.Accept = "application/json"; request.Headers["x-access-token"] = authUser.Token; try { request.BeginGetResponse(ar => { try { using (var response = request.EndGetResponse(ar)) { using (var reader = new StreamReader(response.GetResponseStream())) { var responseObject = JsonConvert.DeserializeObject<Driver>(reader.ReadToEnd()); driver = responseObject; } } } catch (Exception) { } completion.SetResult(driver); }, null); } catch (Exception) { } return (completion.Task).Result; /* = new Driver() { _id = authUser.DetailedUserId._id, PhoneNumber = authUser.DetailedUserId.PhoneNumber, Name = authUser.DetailedUserId.Name, LastName = authUser.DetailedUserId.LastName, GeneralCalification = authUser.DetailedUserId.GeneralCalification }; */ }
private async void AuthenticationProcess(Authentication auth) { if (auth != null) { switch (auth.Role) { case Role.Admin: { var page = new TuGrua.AdminApp(auth); Device.BeginInvokeOnMainThread(() => { ContentPage.Navigation.InsertPageBefore(page, ContentPage); ContentPage.Navigation.PopAsync().ConfigureAwait(false); }); break; } case Role.Driver: { var page = new TuGrua.DriverView(auth); Device.BeginInvokeOnMainThread(() => { ContentPage.Navigation.InsertPageBefore(page, ContentPage); ContentPage.Navigation.PopAsync().ConfigureAwait(false); }); break; } case Role.Requester: { var page = new TuGrua.RequestService(auth); Device.BeginInvokeOnMainThread(() => { ContentPage.Navigation.InsertPageBefore(page, ContentPage); ContentPage.Navigation.PopAsync().ConfigureAwait(false); }); break; } default: break; } } }
public static async Task<Requester> Create(Authentication auth, bool isTestUser = false) { return await CreateRequester(auth); }
public static async Task<Driver> Create(Authentication auth, bool isTestUser = false) { //Console.WriteLine (auth); return await CreateDriver(auth); }
private async void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); var rawJson = new StreamReader(streamResponse).ReadToEnd(); var result = JObject.Parse(rawJson); bool success = result["success"].ToObject<bool>(); if (!success) { // Close the stream object streamResponse.Dispose(); // Release the HttpWebResponse response.Dispose(); AuthenticationProcess(null); Device.BeginInvokeOnMainThread(() => { DisplayAlert("Aviso", (string)result["message"], "OK"); }); } else { var detailedUser = result ["detailedUserId"]; Authentication auth = new Authentication () { Token = result ["token"].ToObject<string> (), UserId = result ["userId"].ToObject<string> (), Role = (Role)(result ["role"].ToObject<int> ()), Email = _emailText.Text, Status = result ["status"].ToObject<int> (), DetailedUserId = result ["detailedUserId"].ToObject<DetailedUser> () }; // Close the stream object streamResponse.Dispose(); // Release the HttpWebResponse response.Dispose(); AuthenticationProcess(auth); } // Close the stream object streamResponse.Dispose(); // Release the HttpWebResponse response.Dispose(); }
public static async Task<Admin> Create(Authentication auth, bool isTestUser = false) { return await CreateAdmin(auth); }