POS-16 Stworzenie metody umożliwiającej logowanie oraz rejestrację.

This commit is contained in:
Wojciech Przybyła 2020-12-06 23:28:59 +01:00
parent 6c1186a014
commit 1bf0b2894b
2 changed files with 56 additions and 1 deletions

View File

@ -7,12 +7,19 @@ using Android.Views;
using Android.Widget;
using Android.OS;
using Xamarin.Essentials;
using System.Net.Http;
using System.Collections.Generic;
using System.Security;
using System.Net;
using System.Linq;
namespace Klient.Droid
{
[Activity(Label = "Klient", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
private static readonly HttpClient client = new HttpClient();
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
@ -24,7 +31,29 @@ namespace Klient.Droid
[Java.Interop.Export("In")]
async public void SignIn(View v)
{
var Login = FindViewById<EditText>(Resource.Id.Login).Text;
SecureString Password = new NetworkCredential("", FindViewById<EditText>(Resource.Id.Password).Text).SecurePassword;
if(Login.Length < 3 || Login.Length > 12)
{
SetContentView(Resource.Layout.ekranLogowania);
}
if(string.IsNullOrWhiteSpace(new NetworkCredential("", Password).Password))
{
SetContentView(Resource.Layout.ekranLogowania);
}
var values = new Dictionary<string, string>
{
{ "login", Login },
{ "password", new NetworkCredential("", Password).Password }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("https://localhost:44371/api/User/SignIn", content);
var responseString = await response.Content.ReadAsStringAsync();
}
[Java.Interop.Export("Reset")]
@ -36,7 +65,32 @@ namespace Klient.Droid
[Java.Interop.Export("SignUp")]
async public void SignUp()
{
var Name = FindViewById<EditText>(Resource.Id.Name).Text;
var Surname = FindViewById<EditText>(Resource.Id.Surname).Text;
var Email = FindViewById<EditText>(Resource.Id.Email).Text;
var Login = FindViewById<EditText>(Resource.Id.NewLogin).Text;
SecureString Password = new NetworkCredential("", FindViewById<EditText>(Resource.Id.NewPassword).Text).SecurePassword;
SecureString Password2 = new NetworkCredential("", FindViewById<EditText>(Resource.Id.RepeatPassword).Text).SecurePassword;
if(new NetworkCredential("", Password).Password != new NetworkCredential("", Password2).Password)
{
SetContentView(Resource.Layout.ekranRejestracji);
}
var values = new Dictionary<string, string>
{
{ "email", Email },
{ "name", Name },
{ "surname", Surname },
{ "login", Login },
{ "password", new NetworkCredential("", Password).Password }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("https://localhost:44371/api/User/Register", content);
var responseString = await response.Content.ReadAsStringAsync();
}
[Java.Interop.Export("HelpLoginScreen")]

View File

@ -51,6 +51,7 @@
<Reference Include="Mono.Android.Export" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>