Ejemplo n.º 1
0
        private async void Login()
        {
            // This is where you would probably check the login and only if valid do the navigation...
            if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password))
            {
                await App.Current.MainPage.DisplayAlert("Thông báo", "Tên đăng nhập và mật khẩu không được bỏ trống!", "ok");
            }
            else
            {
                var account = new { username = Username, password = Password };
                DataLogin = await usersServices.CheckLoginAsync(account);

                if (DataLogin is null)
                {
                    await App.Current.MainPage.DisplayAlert("Thông báo", "Tên đăng nhập hoặc mật khẩu không chính xác!", "ok");
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Thông báo", "Đăng nhập thành công", "ok");

                    Application.Current.Properties["firstName"] = DataLogin.data.firstName;
                    Application.Current.Properties["lastName"]  = DataLogin.data.lastName;
                    Application.Current.Properties["userId"]    = DataLogin.data.id;
                    await SecureStorage.SetAsync("oauthtoken", DataLogin.data.accessToken);

                    await SecureStorage.SetAsync("isLogged", "1");

                    Application.Current.MainPage = new AppShell();
                    await _navigationService.NavigateTo("///main/overview");
                }
            }
        }