예제 #1
0
        private async Task Register()
        {
            ValidateAll();
            if (ErrorStateManager.HasError)
            {
                return;
            }

            IsBusy = true;
            UserRegisterRequest user = new UserRegisterRequest();

            try
            {
                user.UserName  = Username;
                user.Email     = Email;
                user.Password  = Password;
                user.FirstName = FirstName;
                user.LastName  = LastName;

                var result = await _usersApi.Register <UserRegisterRequest>(user);

                if (result != null)
                {
                    await Application.Current.MainPage.DisplayAlert("Success", "Registered sucessufully", "OK");

                    ApiService.Username = result.UserName;
                    ApiService.Password = Password;

                    var loggedIn = await _usersApi.AuthUser();

                    if (loggedIn)
                    {
                        Application.Current.MainPage = new MainPage();
                    }
                    else
                    {
                        await App.Current.MainPage.DisplayAlert("Info", "We coudln't log you in. Please try later.", "OK");
                    }
                }
            }
            catch (Exception ex)
            {
                IsBusy = false;
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
        }
        async Task Login()
        {
            IsBusy = true;
            try
            {
                ApiService.Username = Username;
                ApiService.Password = Password;

                var maybeLogin = await _usersApi.AuthUser();

                if (maybeLogin == true)
                {
                    Application.Current.MainPage = new MainPage();
                }
            }
            catch (Exception ex)
            {
                IsBusy = false;
                await Application.Current.MainPage.DisplayAlert("Error", "Invalid credentials.", "OK");
            }
        }
예제 #3
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            SetLoading(true);
            try
            {
                ApiService.Username = txtUsername.Text;
                ApiService.Password = txtPassword.Text;

                var maybeLogin = await _service.AuthUser();

                if (maybeLogin == true)
                {
                    if (ApiService.Role.Equals("Customer"))
                    {
                        SetLoading(false);
                        MessageBox.Show("Customers are not allowed to use dashboard.", "Authentication", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        SetLoading(false);
                        MessageBox.Show("You successufully logged in.", "Authentication", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        _nextFormPrincipal.Clear();
                        _nextFormPrincipal.Add(ApiService.Role);
                        FormMain form1 = new FormMain(_nextFormPrincipal);

                        this.Close();
                        form1.Show();
                    }
                }
            }
            catch (Exception ex)
            {
                SetLoading(false);
                MessageBox.Show("Invalid credentials.", "Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //MessageBox.Show(ex.Message, "Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }