-1

내 로그인 뷰 모델입니다 여기 내가 뷰 모델에서 다른 페이지로 사용자를 탐색 할 수 있습니다 내가 어떻게 사용자가 잘못된 사용자 이름 또는 암호를 여기</p> <p>을 entred 때 토큰 및 사용자 액세스가 성공적으로 오류 messege 또는 로그인 난 후에 내가 대시 보드 페이지로 사용자를 탐색 할 수있는 방법

using RoyalSales.Views; 
using System.Windows.Input; 
using Xamarin.Forms; 
using RoyalSalesAPI.Services; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Android.App; 
using Android.Content.Res; 
using RoyalSales.Helpers; 

namespace RoyalSales.ViewModels 
{ 
    class LoginViewModel 
    { 
     private APIServices _APIServices = new APIServices(); 

     public string Username { get; set; } 
     public string Password { get; set; } 
     public String Message { get; set; } 
     public ICommand Logincommand => new Command(async() => 
{ 
var accesssToken = await _APIServices.LoginAsync(Username, Password); 
if (!string.IsNullOrEmpty(accesssToken)) 
{ 
Message = "login succeed"; 

Settings.Username = Username; 

Settings.Password = Password; 

Settings.AccessToken = accesssToken; 
// here i want navigate user to dashboard page 
} 
else 
{ 
Message = "wrong username or password"; 
// here i want show message dialoge to tell user theres an wrong username or 
password 

                  } 
                 }); 
     public ICommand LogOutcommand 
     { 
      get 
      { 
       return new Command(() => 
       { 


         Settings.AccessToken = null; 

       }); 
      } 
     } 



     public LoginViewModel() 
     { 
      if (!string.IsNullOrEmpty(Settings.Username)) 
      { 
       Username = Settings.Username; 
       Password = Settings.Password; 
      } 
     } 
    } 
} 

여기
using Javax.Security.Auth; 
using RoyalSales.Views; 
using Android.Provider; 
using RoyalSalesAPI.Services; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

using Xamarin.Forms; 
using Xamarin.Forms.Xaml; 
using RoyalSales.ViewModels; 
using RoyalSales.Helpers; 
using Settings = RoyalSales.Helpers.Settings; 

namespace RoyalSales 
{ 
    [XamlCompilation(XamlCompilationOptions.Compile)] 
    public partial class Login : ContentPage 
    { 
     public APIServices aPIServices = new APIServices(); 
     private string accessToken = Settings.AccessToken.ToString(); 
     public Login() 
     { 
      InitializeComponent(); 
      NavigationPage.SetHasNavigationBar(this, false); 


     } 

     private async void Button_Clicked(object sender, EventArgs e) 
     { 



     } 
    } 
} 

내 loginpage.xaml

내 loginpage.cs입니다
<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage 
    x:Class="RoyalSales.Login" 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:viewModels="clr-namespace:RoyalSales.ViewModels;assembly=RoyalSales" 
    Title="login page" 
    BackgroundColor="#F38906"> 
    <ContentPage.BindingContext> 
     <viewModels:LoginViewModel /> 
    </ContentPage.BindingContext> 
    <ContentPage.Content> 
     <StackLayout 
      Padding="20" 
      Orientation="Vertical" 
      Spacing="30"> 
      <BoxView HeightRequest="20" /> 
      <Image 
       HorizontalOptions="Center" 
       Source="almotaheda.png" 
       WidthRequest="175" /> 
      <Label 
       FontSize="Large" 
       HorizontalOptions="Center" 
       Text="slogn" 
       TextColor="White" /> 
      <Frame BackgroundColor="#FBD7AC" HasShadow="False"> 
       <StackLayout Orientation="Vertical" Spacing="10"> 
        <Entry 
         x:Name="UserNameEntry" 
         HeightRequest="40" 
         HorizontalTextAlignment="Center" 
         Placeholder="username" 
         PlaceholderColor="#F38906" 
         Text="{Binding Username}" 
         TextColor="Black" /> 
        <Entry 
         x:Name="PasswordEntry" 
         HeightRequest="40" 
         HorizontalTextAlignment="Center" 
         IsPassword="True" 
         Placeholder="Password" 
         PlaceholderColor="#F38906" 
         Text="{Binding Password}" 
         TextColor="Black" /> 

       </StackLayout> 
      </Frame> 
      <Label 
       FontSize="20" 
       Text="{Binding Message}" 
       TextColor="#FFFFFF" /> 
      <Button 
       BackgroundColor="White" 
       Command="{Binding Logincommand}" 
       FontAttributes="Bold" 
       FontSize="20" 
       HorizontalOptions="FillAndExpand" 
       Text="login" 
       TextColor="#F38906" 
       Clicked="Button_Clicked"/> 
      <BoxView HeightRequest="20" /> 

     </StackLayout> 

    </ContentPage.Content> 
</ContentPage> 

plese 도움 successfuly 로그인 또는 오류 메시지가 잘못된 사용자 이름 또는 암호가

+0

일반적으로 이렇게하려면 로그인 페이지로 사용자를 보내면 다음과 같은 검색어 매개 변수를 첨부하십시오 :'login? returnurl = someUrl'. 그런 다음 사용자를 로그인하면 쿼리 매개 변수의 URL로 사용자를 보냅니다. 그러나 질문에서 웹 애플 리케이션이나 뭐 이런 일을하고 싶은지 확실하지 않다. 웹 앱에서 그 일을 할 수 있습니다. – CodingYoshi

답변

0

당신은 예를 들어 AccessToken

을 설정 한 후 PushAsync 또는 PushModalAsync를 사용할 수있는 경우 경우 내 대시 보드 페이지로 사용자를 탐색 :

012 : 당신이 사용할 수있는 뷰 모델에서 경고를 표시하기 위해

await App.Current.MainPage.Navigation.PushAsync(new dashboardPage(), true); 
+0

답장을 보내 주셔서 감사합니다. 가장 좋은 답변으로 표시 할 것입니다. 사용자 이름이나 비밀번호를 잘못 알릴 수있는 방법을 알려 주실 수 있습니까? –

+0

답변을 수정하겠습니다. – GeralexGR

관련 문제