Esempio n. 1
0
        private async void _Fund_Clicked(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(_Amount.Text) || !String.IsNullOrEmpty(_Amount.Text))
            {
                Dictionary <int, String[]> Data = new Dictionary <int, string[]>
                {
                    { 0, new String[] { "user_id", Utilities.ID.ToString() } },
                    { 1, new String[] { "amount", _Amount.Text } }
                };

                try
                {
                    String ResponseJson = await TransactionController.FundAccount(Utilities.PostDataEncoder(Data));

                    var DecodedJson = JObject.Parse(ResponseJson);

                    if (Convert.ToBoolean(DecodedJson["status"]))
                    {
                        //return to previous page after user closes the alert dialog
                        await Utilities.CreateAlertDialog("Alert", DecodedJson["message"].ToString(), "Ok", delegate
                        {
                            Navigation.PopAsync();
                        });
                    }
                    else
                    {
                        await DisplayAlert("Alert", DecodedJson["message"].ToString(), "Ok");
                    }
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Alert", ex.Message, "Ok");
                }
            }
        }
        private async void _SignUp_Clicked(object sender, EventArgs e)
        {
            Dictionary <int, String[]> KeyValues = new Dictionary <int, string[]>();
            bool IsCompleted = false;

            try
            {
                KeyValues.Add(0, new String[] { "full_name", _FullName.Text });
                KeyValues.Add(1, new String[] { "gender", (_Gender.SelectedItem.Equals("Male")) ? "m" : "f" });
                KeyValues.Add(2, new String[] { "phone", GD.Phone });
                KeyValues.Add(3, new String[] { "address", _HomeAddress.Text });
                KeyValues.Add(4, new String[] { "dob", _DOB.Date.ToString("yyyy-MM-dd") });
                KeyValues.Add(5, new String[] { "password", GD.Password });
                KeyValues.Add(6, new String[] { "username", _Username.Text });
                if (!String.IsNullOrEmpty(GD.Email))
                {
                    KeyValues.Add(7, new String[] { "email", GD.Email });
                }
                KeyValues.Add(8, new String[] { "blood_group", _BloodGroup.SelectedItem.ToString() });
                KeyValues.Add(9, new String[] { "is_medic", "0" });

                IsCompleted = true;
            }
            catch
            {
                await DisplayAlert("Alert", "Please Fill All Fields", "Okay");
            }

            if (IsCompleted)
            {
                FormUrlEncodedContent Data = Utilities.PostDataEncoder(KeyValues);
                try
                {
                    //get the result of the signup 0 = status, 1 = message
                    var Result = await SignUpController.SignUp(Data);

                    if (Convert.ToBoolean(Result[0]))
                    {
                        await Utilities.CreateAlertDialog("Alert", Result[1].ToString(), "Ok", delegate
                        {
                            Navigation.PushAsync(new LoginPage());
                            Navigation.RemovePage(this);
                        });
                    }
                    else
                    {
                        await DisplayAlert("Alert", Result[1].ToString(), "Okay");
                    }
                }
                catch (System.Net.WebException WebEx)
                {
                    await DisplayAlert("Alert", "Unable to connect to the server, Please check the internet connection. ", "Okay");
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Alert", "UPDP Error, Please Contact Admin " + ex.Message, "Okay");
                }
            }
        }
Esempio n. 3
0
        private async Task HandleLoginAction()
        {
            bool isUserEmpty     = string.IsNullOrEmpty(nUser.Text);
            bool isPasswordEmpty = string.IsNullOrEmpty(nPassword.Text);

            if (isUserEmpty || isPasswordEmpty)
            {
                if (isUserEmpty)
                {
                    nUser.Focus();
                }
                nUser.PlaceholderColor = Color.Red;
                if (isPasswordEmpty)
                {
                    nPassword.Focus();
                }
                nPassword.PlaceholderColor = Color.Red;
                await DisplayAlert("Alert", "Pleae fill the RED fields", "Ok");
            }
            else
            {
                ///no internet access
                ///local sign in
                if (!CrossConnectivity.Current.IsConnected)
                {
                    String Hashed = "";
                    using (var sha = SHA512.Create())
                    {
                        using (var md5 = MD5.Create())
                        {
                            Hashed = Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(nPassword.Text))))));
                        }
                    }

                    ///verification
                    var UserInfo = await LoginHandler.LoginInfo(nUser.Text, Hashed);

                    if (UserInfo.Count > 0)
                    {
                        if (UserInfo[0].MedicID != 0)
                        {
                            Utilities.MedicID = UserInfo[0].MedicID;
                        }

                        await Navigation.PushAsync(new HomePage(UserInfo[0].UserID, (UserInfo[0].MedicID != 0)));

                        Navigation.RemovePage(this);
                    }
                    else
                    {
                        await DisplayAlert("Alert", "Please create an account when you are connected before you can use this application offline.", "Ok");
                    }
                }
                else
                {
                    Dictionary <int, String[]> KeyValues = new Dictionary <int, string[]>();
                    KeyValues.Add(0, new String[] { "password", nPassword.Text });
                    KeyValues.Add(1, new String[] { "user", nUser.Text });
                    FormUrlEncodedContent Data = Utilities.PostDataEncoder(KeyValues);

                    String ResponseJson = "";
                    try
                    {
                        ResponseJson = await Model.LoginModel.Login(Data);

                        var DecodedJson = JObject.Parse(ResponseJson.ToString());

                        if (Convert.ToBoolean(DecodedJson["status"]))
                        {
                            ///request needed permission of not granted
                            bool StoragePermissionGranted = await Utilities.CheckPermission(Permission.Storage, Utilities.ApplicationName + " would need access to device storage.");

                            Utilities.IsLoggedIn = true;
                            Utilities.IsMedic    = Convert.ToBoolean(DecodedJson["info"]["is_medic"]);
                            Utilities.ID         = (int)DecodedJson["info"]["id"];

                            if (Utilities.IsMedic)
                            {
                                Utilities.MedicID = (int)DecodedJson["info"]["medic_id"];
                            }



                            ///save info to local db

                            using (var sha = SHA512.Create())
                            {
                                using (var md5 = MD5.Create())
                                {
                                    String Hashed = Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(nPassword.Text))))));

                                    var UserInfo = await LoginHandler.LoginInfo(nUser.Text, Hashed);

                                    if (UserInfo.Count == 0)
                                    {
                                        await LoginHandler.InsertNewLoginInfo(nUser.Text, Hashed, (int)DecodedJson["info"]["id"], (Utilities.IsMedic)?(int)DecodedJson["info"]["medic_id"] : 0, DecodedJson["info"]["name"].ToString());

                                        var UserDetails = await SettingsController.GetSettings();

                                        await UserDetailsHandler.SaveUserDetails(new UserDetailsModel { Address = UserDetails["address"], DOB = UserDetails["dob"], Email = UserDetails["email"], FullName = UserDetails["name"], PhoneNo = UserDetails["phone"], UserID = Utilities.ID });
                                    }
                                }
                            }



                            await Navigation.PushAsync(new HomePage((int)DecodedJson["info"]["id"], Utilities.IsMedic));

                            //await ChatHandler.GetLastUniqueConversation();

                            Navigation.RemovePage(this);
                        }
                        else
                        {
                            await DisplayAlert("Alert", DecodedJson["message"].ToString(), "Okay");
                        }
                    }
                    catch (System.Net.WebException WebEx)
                    {
                        await DisplayAlert("Alert", WebEx.Message + "\n" + Utilities.BaseAddress + "\n" + ResponseJson, "Okay");
                    }
                    catch (Exception ex)
                    {
                        await DisplayAlert("Alert", ex.StackTrace + "\n" + Utilities.BaseAddress + "\n" + ResponseJson, "Okay");
                    }
                }
            }
        }
Esempio n. 4
0
        private async void _Submit_Clicked(object sender, EventArgs e)
        {
            try
            {
                String PhoneNo = _CountryCode.SelectedItem + _PhoneNo.Text;

                if (!String.IsNullOrEmpty(PhoneNo) && !String.IsNullOrEmpty(_ConfirmPassword.Text))
                {
                    String Email = (String.IsNullOrEmpty(_Email.Text)) ? "n/a" : _Email.Text;
                    //inform user if email/phone no is used
                    bool IsEmailAvail = false;

                    if (Email != "n/a")
                    {
                        IsEmailAvail = await SignUpController.CheckUniqueFields(Utilities.PostDataEncoder(new Dictionary <int, string[]>
                        {
                            { 0, new String[] { "email", _Email.Text } }
                        }), "e-mail");
                    }

                    bool IsPhoneAvail = await SignUpController.CheckUniqueFields(Utilities.PostDataEncoder(new Dictionary <int, string[]>
                    {
                        { 0, new String[] { "phone", PhoneNo } }
                    }), "phone-no");


                    if (IsEmailAvail)
                    {
                        if (IsPhoneAvail)
                        {
                            //confirm password
                            if (_ConfirmPassword.Text.Equals(_Password.Text))
                            {
                                await Navigation.PushAsync(new OTPPage(new GeneralDetails(Email, PhoneNo, _ConfirmPassword.Text, UserType, ShortCountryCode)));
                            }
                            else
                            {
                                await DisplayAlert("Alert", "Passwords don't match", "Okay");
                            }
                        }
                        else
                        {
                            await DisplayAlert("Alert", "Phone number is already registered ", "Okay");
                        }
                    }
                    else
                    {
                        await DisplayAlert("Alert", "Email address is already registered ", "Okay");
                    }
                }
                else
                {
                    //force validation
                    if (String.IsNullOrEmpty(_PhoneNo.Text))
                    {
                        _PhoneNo.PlaceholderColor = Color.Red;
                    }
                    else
                    {
                        _PhoneNo.PlaceholderColor = Color.Black;
                    }

                    if (String.IsNullOrEmpty(_Password.Text))
                    {
                        _Password.PlaceholderColor = Color.Red;
                    }
                    else
                    {
                        _Password.PlaceholderColor = Color.Black;
                    }

                    if (String.IsNullOrEmpty(_ConfirmPassword.Text))
                    {
                        _ConfirmPassword.PlaceholderColor = Color.Red;
                    }
                    else
                    {
                        _ConfirmPassword.PlaceholderColor = Color.Black;
                    }

                    await DisplayAlert("Alert", "Pleae fill the RED Fields", "Okay");
                }
            }
            catch (System.Net.WebException WebEx)
            {
                await DisplayAlert("Alert", Utilities.NoInternet, "Okay");
            }
            catch (Exception ex)
            {
                await DisplayAlert("Alert", ex.Message, "Okay");
            }
        }