我对这一切都很陌生。我正在尝试为我当地的橄榄球俱乐部创建一个桌子服务应用程序。我已将我的应用程序连接到Azure sql数据库,但当我尝试登录时,用户可以注册,但没有发生任何情况。这是我为用户提供的类:
using System;
namespace LeighRUFCapp.Model
{
public class Users
{
// [PrimaryKey, AutoIncrement]
public string ID { get; set; }
// [MaxLength(256)]
public string Email { get; set; }
public string Password { get; set; }
}
}bellow是我的登录页面的xaml;
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LeighRUFCapp.LoginPages.LoginPage" xmlns:yummy="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView">
<ContentPage.Content>
<StackLayout BackgroundColor="#313131">
<Image Source="logo.png" HorizontalOptions="CenterAndExpand" Margin="40" VerticalOptions="Center"></Image>
<StackLayout Orientation="Vertical" Margin="20" AnchorY="0.5" VerticalOptions="StartAndExpand">
<Entry Placeholder="Email" TextColor="White" PlaceholderColor="LightGray" Keyboard="Email" x:Name="EmailAddressEntry"></Entry>
<Entry Placeholder="Password" TextColor="White" PlaceholderColor="LightGray" IsPassword="True" x:Name="UserPasswordEntry"></Entry>
<yummy:PancakeView BackgroundColor="#EFCC45" CornerRadius="20,20,20,20" HorizontalOptions="FillAndExpand" HeightRequest="50" Margin="25,0,25,0">
<yummy:PancakeView.Shadow>
<yummy:DropShadow Color="#232323" Offset="10,10"/>
</yummy:PancakeView.Shadow>
<Button x:Name="LoginButton" Clicked="LoginButton_Clicked" Text="Login" FontSize="Large" HorizontalOptions="FillAndExpand" BorderColor="#000000" BackgroundColor="#EFCC45" FontFamily="helvetica" TextColor="#000000"></Button>
</yummy:PancakeView>
<yummy:PancakeView BackgroundColor="#EFCC45" CornerRadius="20,20,20,20" HorizontalOptions="FillAndExpand" HeightRequest="50" Margin="25,0,25,0">
<yummy:PancakeView.Shadow>
<yummy:DropShadow Color="#232323" Offset="10,10"/>
</yummy:PancakeView.Shadow>
<Button x:Name="RegisterBtn" Clicked="RegisterBtn_Clicked" Text="Register" HorizontalOptions="FillAndExpand" BorderColor="#000000" BackgroundColor="#EFCC45" FontFamily="helvetica" FontSize="Large" TextColor="#000000"></Button>
</yummy:PancakeView>
</StackLayout>
<StackLayout>
<Button x:Name="Adminbtn" Clicked="Adminbtn_Clicked" Text="Admin" TextColor="#EFCC45" FontFamily="helvetica" FontSize="Subtitle" BackgroundColor="#313131"/>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>和我的登录页面的c#;
using System;
using System.Collections.Generic;
using System.Linq;
using LeighRUFCapp.Homestuff;
using LeighRUFCapp.Model;
using Xamarin.Forms;
namespace LeighRUFCapp.LoginPages
{
public partial class LoginPage : ContentPage
{
public LoginPage()
{
SetValue(NavigationPage.HasNavigationBarProperty, false);
InitializeComponent();
}
private async void LoginButton_Clicked(System.Object sender, System.EventArgs e)
{
bool isEmailEmpty = string.IsNullOrEmpty(EmailAddressEntry.Text);
bool isPasswordEmpty = string.IsNullOrEmpty(UserPasswordEntry.Text);
if (isEmailEmpty || isPasswordEmpty)
{
await DisplayAlert("Error", "Your Email or Password is incorrect", "OK");
}
else
{
var user = await App.MobileService.GetTable<Users>().Where(u => u.Email == EmailAddressEntry.Text).ToListAsync();
if (user != null)
{
//if (Users.Password == UserPasswordEntry.Text)
//{
await Navigation.PushAsync(new HomePage());
/* }
else
{
//password is not being found in the table usersfor some reason
await DisplayAlert("Error", "Incorrect email or password", "OK");
}
}
else
{
await DisplayAlert("Error", "There was an error logging you in", "OK");
}*/
}
}
}
void RegisterBtn_Clicked(System.Object sender, System.EventArgs e)
{
App.Current.MainPage = new NavigationPage(new RegisterPage());
}
void Adminbtn_Clicked(System.Object sender, System.EventArgs e)
{
App.Current.MainPage = new NavigationPage(new AdminLogin());
}
}
}发布于 2020-12-12 02:59:38
我的建议是:
这更安全,也是移动应用程序的常见模式。您通常会使用JSON作为响应类型来设计rest API。这将意味着在启动Xamarin应用程序之前,在Visual Studio中启动该服务(假设是Android -如果不是,则最终需要Mac)。或者,您可以创建该服务的单独实例。一旦经过调试,VS就可以非常容易地部署到Azure云中。
你能远程访问数据库吗?可以,但您必须关闭一些安全功能,或者通过HTTPS或类似的方式使用访问。这不是一个很好的模式,因为您最终会在应用程序中使用连接字符串。并不是说移动应用程序很容易进行反向工程来获取信息,但建议您遵循最佳实践。
https://stackoverflow.com/questions/65256769
复制相似问题