Ejemplo n.º 1
0
        private async void ExecuteNewUserCommand(object obj)
        {
            this.DemandeurIdentite.Id = Guid.NewGuid().ToString();
            var loader = await MaterialDialog.Instance.LoadingDialogAsync("Veuillez patienter svp ...");

            try
            {
                if (PwdConfirm.Trim() != Pwd.Trim())
                {
                    throw new Exception("Mot de passe saisi ne correspond pas");
                }
                if (IsError)
                {
                    throw new Exception("Verifiez vos données");
                }
                this.DemandeurIdentite.Password = Pwd.HashPassword();
                await RestService.For <IBackendService>(Configurations.ServerConfig.Host).Inscription(JsonConvert.SerializeObject(this.DemandeurIdentite));

                await loader.DismissAsync();

                await MaterialDialog.Instance.AlertAsync($"Un e-mail de verification a été envoyé à {this.DemandeurIdentite.Email}");
            }
            catch (Exception e)
            {
                await loader.DismissAsync();

                await MaterialDialog.Instance.SnackbarAsync("Error: " + e.Message, 3000, Configurations.MaterialConfig.MaterialSnackbarConfiguration);
            }
        }
        private async void ExecuteLoginCommand(object obj)
        {
            var loader = await MaterialDialog.Instance.LoadingDialogAsync("Contact du serveur ... ", Configurations.MaterialConfig.MaterialLoadingDialogConfiguration);

            try
            {
                var currentUser = await RestService.For <Services.IBackendService>(Configurations.ServerConfig.Host).Connexion(JsonConvert.SerializeObject(new
                {
                    email      = Email,
                    motDePasse = Pwd.HashPassword()
                }));

                SecureStorageHelper.AuthKey = currentUser.Id;
                LiteDbHelper.SaveDataUser(currentUser);
                await loader.DismissAsync();

                if (string.IsNullOrEmpty(currentUser.Nom) ||
                    string.IsNullOrEmpty(currentUser.Postnom) ||
                    string.IsNullOrEmpty(currentUser.Prenom) ||
                    string.IsNullOrEmpty(currentUser.Username))
                {
                    await Navigation.PushAsync(new Views.FirstUpdatePage());
                }
                else
                {
                    await Navigation.PushAsync(new Views.HomePage());
                }
            }
            catch (Exception e)
            {
                await loader.DismissAsync();

                if (e is Refit.ApiException)
                {
                    await MaterialDialog.Instance.SnackbarAsync($"{((Refit.ApiException)e).Content}", 3000, Configurations.MaterialConfig.MaterialSnackbarConfiguration);
                }
                else
                {
                    await MaterialDialog.Instance.SnackbarAsync($"Erreur: {e.Message}", 3000, Configurations.MaterialConfig.MaterialSnackbarConfiguration);
                }
            }
        }