예제 #1
0
        private async void Login_Clicked(object sender, EventArgs e)
        {
            string user = usernameEntry.Text;
            string pass = passwordEntry.Text;

            //Ensure the fields are all filled out.
            if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pass))
            {
                await DisplayAlert("Error", "Please complete all fields.", "Ok");

                return;
            }

            //Ensure taking photo is enabled.
            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await DisplayAlert("Error", "No camera avaialble!", "Ok");

                return;
            }

            //Take photo.
            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front,
                PhotoSize     = Plugin.Media.Abstractions.PhotoSize.Medium,
                Directory     = "User Images",
                Name          = "userImage"
            });

            //If no photo is taken, do nothing more.
            if (file == null)
            {
                return;
            }

            var loginsuccess = await SecureStorageService.IsLoginCorrect(user, pass);

            if (!loginsuccess)
            {
                await DisplayAlert("Failure", "Incorrect login details.", "Ok");

                return;
            }

            //Check with Azure Face API if the face is recognised.
            var faceRecognised = await FacialRecognitionService.IsFaceIdentified(user, file.GetStream());

            if (faceRecognised) //If recognised
            {
                await DisplayAlert("Success", "You have logged in.", "Ok");
            }
            else
            {
                await DisplayAlert("Failure", "Face not recognised.", "Ok");
            }

            file.Dispose();
        }
        private async void Submit_Clicked(object sender, EventArgs e)
        {
            string user = usernameEntry.Text;
            string pass = passwordEntry.Text;

            //Ensure the fields are all filled out.
            if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pass) || !trainingDone.IsChecked)
            {
                await DisplayAlert("Error", "Please complete all fields.", "Ok");

                return;
            }

            //Store into secure storage.
            await SecureStorageService.SaveLogin(user, pass);

            //Inform the user that sign up is done and return to login page.
            await DisplayAlert("Success", "You have been signed up. Returning you to login page...", "Ok");

            await App.Current.MainPage.Navigation.PopAsync();
        }