Пример #1
0
        public async Task <string> RegisterAsync(PatientCreationBundle patientCreationBundle)
        {
            try
            {
                await _client.GetAsync(new Uri(_baseAddress) + "Auth/");

                _token = new CancellationTokenSource();
                //Serialize the patientCreationBundle and send it to the API.
                StringContent registerContent = new StringContent(JObject.FromObject(patientCreationBundle).ToString(), Encoding.UTF8, "application/json");
                _response = await _client.PostAsync(new Uri(_baseAddress + "User/Create/"), registerContent, _token.Token);

                _data = await _response.Content.ReadAsStringAsync();

                return(_data);
            }
            catch (Exception)
            {
                _token.Cancel();
                return(null);
            }
        }
Пример #2
0
        public async Task <string> OnRegisterButtonPressedAsync()
        {
            if (!String.IsNullOrEmpty(_email.Text) && !String.IsNullOrEmpty(_password.Text) && !String.IsNullOrEmpty(_firstName.Text) && !String.IsNullOrEmpty(_lastName.Text) && !String.IsNullOrEmpty(_phoneNumber.Text))
            {
                Regex emailRegex    = new Regex(@"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$");
                Regex passwordRegex = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&]{8,}$");
                Regex phoneRegex    = new Regex(@"^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$");

                if (!emailRegex.IsMatch(_email.Text.Trim()))
                {
                    _password.Text = String.Empty;
                    return("Must match the form of [email protected]");
                }

                if (!passwordRegex.IsMatch(_password.Text.Trim()))
                {
                    _password.Text = String.Empty;
                    return("Must be at least 8 characters long, 1 uppercase letter, 1 lowercase letter, 1 special character, and 1 number");
                }

                if (_phoneNumber.Text.Length != 10)
                {
                    if (!phoneRegex.IsMatch(_phoneNumber.Text.Trim()))
                    {
                        _password.Text = String.Empty;
                        return("Invalid Phone Number");
                    }
                    _password.Text = String.Empty;
                    return("Phone Number must be 10 digits long");
                }

                Patient patient = new Patient()
                {
                    Email       = _email.Text.Trim(),
                    FirstName   = _firstName.Text.Trim(),
                    LastName    = _lastName.Text.Trim(),
                    PhoneNumber = _phoneNumber.Text.Trim(),
                };

                if (!String.IsNullOrEmpty(_middleName.Text))
                {
                    patient.MiddleName = _middleName.Text.Trim();
                }

                PatientCreationBundle patientCreationBundle = new PatientCreationBundle()
                {
                    Password = _password.Text.Trim(),
                    Patient  = patient
                };

                if (!String.IsNullOrEmpty(_doctorToken.Text))
                {
                    patientCreationBundle.DoctorToken = _doctorToken.Text.Trim();
                }

                string status = await _restService.RegisterAsync(patientCreationBundle);

                if (status is null)
                {
                    return("No Connection");
                }
                else if (status != "Invalid User" && !(status is null))
                {
                    return("Registered!");
                }
                else
                {
                    _password.Text = String.Empty;
                    return("User Already Exists or Invalid Doctor Token");
                }
            }
            else
            {
                _password.Text = String.Empty;
                return("Form Is Not Filled");
            }
        }