private void ChangeProfile()
 {
     Error = "";
     NewUser.Validate();
     if (!NewUser.IsValid)
     {
         return;
     }
     else if (!string.IsNullOrEmpty(ConfirmPassword) && !MainViewModel.logedInUser.Password.ToLower().Equals(ConfirmPassword.ToLower()))
     {
         Error = "Passwords must match.";
     }
     else if (!NewUser.Username.ToLower().Equals(MainViewModel.logedInUser.Username.ToLower()))
     {
         if (_repo.CheckUsername(NewUser.Username))
         {
             Error = "Username allready exists.";
         }
     }
     else
     {
         _repo.EditUser(MainViewModel.logedInUser, NewUser);
         MainViewModel.logedInUser = _repo.LoadData(NewUser.Username);
         AppViewModel.Instance.OnNav("images");
         AppViewModel.Instance.Images();
         NewUser.Username = "";
         NewUser.Password = "";
         ConfirmPassword  = "";
     }
 }
Пример #2
0
        private async void ExecuteNavigateToSignUpCommand()
        {
            //checking for connectivity
            var network = Connectivity.NetworkAccess;

            if (network != NetworkAccess.Internet)
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Error: No internet access", actionButtonText : "OK", msDuration : 3000, configuration : snackBarConfiguration);

                return;
            }


            if (CompanyName == null || Username == null || Email == null || PhoneNumber == null || Address == null || Password == null || ConfirmPassword == null)
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Error: Fill the required fields", actionButtonText : "OK", msDuration : 3000, configuration : snackBarConfiguration);

                return;
            }

            if (Password.Length < 4)
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Error: Password length must be more than 4 characters", actionButtonText : "OK", msDuration : 3000, configuration : snackBarConfiguration);

                return;
            }

            if (Password.ToLower().Trim() != ConfirmPassword.ToLower().Trim())
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Error: Passwords do not match", actionButtonText : "OK", msDuration : 3000, configuration : snackBarConfiguration);

                return;
            }

            IsNotBusy = false;
            var loadingPageConfiguration = new MaterialLoadingDialogConfiguration()
            {
                BackgroundColor  = Color.FromHex("1DA1F2"),
                MessageTextColor = Color.FromHex("FFFFFF"),
                CornerRadius     = 10,
                TintColor        = Color.FromHex("FFFFFF"),
                ScrimColor       = Color.FromHex("1DA1F2").MultiplyAlpha(0.32)
            };

            var loadingDialog = await MaterialDialog.Instance.LoadingDialogAsync(message : "Processing", configuration : loadingPageConfiguration);

            var validateUser = await remoteService.ValidateUsername(Username.ToLower().Trim());

            if (!validateUser)
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Username already exist", actionButtonText : "OK", msDuration : 2000, configuration : snackBarConfiguration);

                await loadingDialog.DismissAsync();

                IsNotBusy = true;
                return;
            }

            var signUp = new SignUp
            {
                CompanyName = this.CompanyName.ToLower().Trim(),
                Username    = this.Username.ToLower().Trim(),
                Email       = this.Email.ToLower().Trim(),
                PhoneNumber = this.PhoneNumber.ToLower().Trim(),
                Address     = this.Address.ToLower().Trim(),
                Password    = this.Password.ToLower().Trim(),
            };

            var user = await remoteService.SignUpAsync(signUp);



            await loadingDialog.DismissAsync();

            IsNotBusy = true;
            if (user)
            {
                CompanyName     = null;
                Username        = null;
                Email           = null;
                Password        = null;
                Address         = null;
                PhoneNumber     = null;
                ConfirmPassword = null;
                //await App.Current.MainPage.DisplayAlert("SignUp Success", "Congrats your account has been created", "Ok");
                await MaterialDialog.Instance.SnackbarAsync(message : "Account created successfully", actionButtonText : "OK", msDuration : 2000, configuration : snackBarConfiguration);

                await NavigationService.NavigateAsync("LoginPage");
            }
            else
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Sign up failed", actionButtonText : "OK", msDuration : 2000, configuration : snackBarConfiguration);
            }
        }
Пример #3
0
        private async void ExecuteSignUpCommand()
        {
            //checking for connectivity
            var network = Connectivity.NetworkAccess;

            if (network != NetworkAccess.Internet)
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Error: No internet access", actionButtonText : "OK", msDuration : 3000, configuration : App.snackBarConfiguration);

                return;
            }

            //checking for null
            if (Email == null || Username == null || PhoneNumber == null || University == null || Department == null || Password == null || ConfirmPassword == null)
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Error: Fill the required fields", actionButtonText : "OK", msDuration : 3000, configuration : App.snackBarConfiguration);

                return;
            }

            //password length
            if (Password.Length < 6)
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Error: Password length must be at least 6 characters", actionButtonText : "OK", msDuration : 3000, configuration : App.snackBarConfiguration);

                return;
            }

            if (Password.ToLower().Trim() != ConfirmPassword.ToLower().Trim())
            {
                await MaterialDialog.Instance.SnackbarAsync(message : "Error: Passwords do not match", actionButtonText : "OK", msDuration : 3000, configuration : App.snackBarConfiguration);

                return;
            }

            //loading dialog configuration
            var loadingPageConfiguration = new MaterialLoadingDialogConfiguration()
            {
                BackgroundColor  = Color.FromHex("048B28"),
                MessageTextColor = Color.FromHex("FFFFFF"),
                CornerRadius     = 10,
                TintColor        = Color.FromHex("FFFFFF"),
                ScrimColor       = Color.FromHex("1DA1F2").MultiplyAlpha(0.05)
            };

            //opacity of the page
            Opacity = 0.8;

            var loadingDialog = await MaterialDialog.Instance.LoadingDialogAsync(message : "Processing", configuration : loadingPageConfiguration);

            IsNotBusy = false;

            //remote service -  create  user
            var user = await remoteService.SignUp(Email.ToLower().Trim(), Password.ToLower().Trim());


            if (user.Id != null)
            {
                var signUp = new SignUp()
                {
                    Email       = this.Email.ToLower().Trim(),
                    Username    = this.Username.Trim(),
                    PhoneNumber = this.PhoneNumber.Trim(),
                    University  = this.University.Trim(),
                    Department  = this.Department.Trim(),
                    Id          = user.Id,
                    Avatar      = "https://firebasestorage.googleapis.com/v0/b/naijaconnect-3b414.appspot.com/o/default%20profile%20picture.png?alt=media&token=092092f9-886d-4a3c-8271-bbbcecc5678d",
                    Status      = "offline"
                };

                //save user to database
                var completeSignUp = await remoteService.SaveUser(signUp);

                await loadingDialog.DismissAsync();

                if (completeSignUp)
                {
                    Email           = null;
                    Username        = null;
                    PhoneNumber     = null;
                    University      = null;
                    Department      = null;
                    Password        = null;
                    ConfirmPassword = null;

                    IsNotBusy = true;
                    Opacity   = 1;
                    await MaterialDialog.Instance.SnackbarAsync(message : "Account created successfully", actionButtonText : "OK", msDuration : 2000, configuration : App.snackBarConfiguration);

                    await NavigationService.NavigateAsync("SignInPage");
                }
                else
                {
                    await MaterialDialog.Instance.SnackbarAsync(message : "Error occured", actionButtonText : "OK", msDuration : 2000, configuration : App.snackBarConfiguration);
                }
            }

            else
            {
                await loadingDialog.DismissAsync();

                await MaterialDialog.Instance.SnackbarAsync(message : "Error: " + user.ErrorMessage, actionButtonText : "OK", msDuration : 2000, configuration : App.snackBarConfiguration);
            }
        }
Пример #4
0
        private async void SignUp()
        {
            ResourceManager rm = new ResourceManager("LoginAppSample.AppResources.Localization.Resources", typeof(App).GetTypeInfo().Assembly);

            string AlertMessage = String.Empty;

            if (String.IsNullOrEmpty(User.Email))
            {
                AlertMessage = rm.GetString("EMAIL_REQUIRED");
            }
            else if (!IsValid(User.Email))
            {
                AlertMessage = rm.GetString("INVALID_EMAIL_REQUIRED");
            }
            if (String.IsNullOrEmpty(User.Username))
            {
                AlertMessage += rm.GetString("USERNAME_REQUIRED");
            }
            if (String.IsNullOrEmpty(User.Password))
            {
                AlertMessage += rm.GetString("PASSWORD_REQUIRED");
            }
            else if (String.IsNullOrEmpty(ConfirmPassword) || !User.Password.ToLower().Equals(ConfirmPassword.ToLower()))
            {
                AlertMessage += rm.GetString("PASSWORD_CONFIRM_PASSWORD_REQUIRED");
            }
            if (!String.IsNullOrEmpty(AlertMessage))
            {
                await _iPopupsService.DisplayAlert(rm.GetString("APPLICATION_NAME"), AlertMessage, rm.GetString("OK"));

                return;
            }
            var result = await _iUserServices.SignUp(User);

            if (result)
            {
                await _iPopupsService.DisplayAlert(rm.GetString("APPLICATION_NAME"), String.Format(rm.GetString("CONFIRM_SIGN_UP_MESSAGE"), rm.GetString("APPLICATION_NAME")), rm.GetString("OK"));

                await _iNavigationService.NavigateTo("SignIn");
            }
            else
            {
                await _iPopupsService.DisplayAlert(rm.GetString("APPLICATION_NAME"), rm.GetString("ERROR_MESSAGE"), rm.GetString("OK"));
            }
        }