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