diff --git a/Klient/Klient/Klient.Android/MainActivity.cs b/Klient/Klient/Klient.Android/MainActivity.cs index 18b0cb6..1df438a 100644 --- a/Klient/Klient/Klient.Android/MainActivity.cs +++ b/Klient/Klient/Klient.Android/MainActivity.cs @@ -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(Resource.Id.Login).Text; + SecureString Password = new NetworkCredential("", FindViewById(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 + { + { "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(Resource.Id.Name).Text; + var Surname = FindViewById(Resource.Id.Surname).Text; + var Email = FindViewById(Resource.Id.Email).Text; + var Login = FindViewById(Resource.Id.NewLogin).Text; + SecureString Password = new NetworkCredential("", FindViewById(Resource.Id.NewPassword).Text).SecurePassword; + SecureString Password2 = new NetworkCredential("", FindViewById(Resource.Id.RepeatPassword).Text).SecurePassword; + if(new NetworkCredential("", Password).Password != new NetworkCredential("", Password2).Password) + { + SetContentView(Resource.Layout.ekranRejestracji); + } + + var values = new Dictionary + { + { "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")] diff --git a/Klient/Klient/Klient.Android/Poszukiwacz.csproj b/Klient/Klient/Klient.Android/Poszukiwacz.csproj index 51e91df..6b57764 100644 --- a/Klient/Klient/Klient.Android/Poszukiwacz.csproj +++ b/Klient/Klient/Klient.Android/Poszukiwacz.csproj @@ -51,6 +51,7 @@ +