Beispiel #1
0
        public async Task <ActionResult> LoginWithImage(string image)
        {
            try
            {
                byte[]       data        = Convert.FromBase64String(image);
                MemoryStream imageStream = new MemoryStream(data);
                FaceRecognizerHelper.FaceApiKey      = ConfigurationManager.AppSettings["FaceApiKey"];
                FaceRecognizerHelper.FaceApiEndpoint = ConfigurationManager.AppSettings["FaceApiEndpoint"];
                FaceRecognizerHelper faceHelper = FaceRecognizerHelper.InitializeService();
                var username = await faceHelper.DetectUserAsync(imageStream);

                if (username != null)
                {
                    ApplicationUser user = await UserManager.FindByNameAsync(username);

                    await SignInManager.SignInAsync(user, false, false);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "User face is not matching or not able to identify");
                    return(View("Login"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Error in login with face recognition, try other options");
                return(View("Login"));
            }
        }
        public async Task <ActionResult> UploadImage(ImageData[] imageData)
        {
            try
            {
                var imagePaths = SaveImages(imageData);
                FaceRecognizerHelper.FaceApiKey      = ConfigurationManager.AppSettings["FaceApiKey"];
                FaceRecognizerHelper.FaceApiEndpoint = ConfigurationManager.AppSettings["FaceApiEndpoint"];
                FaceRecognizerHelper faceHelper = FaceRecognizerHelper.InitializeService();
                await faceHelper.TainImagesAsync(User.Identity.Name, imagePaths);

                return(Json(true));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(500, "Unable to save image."));
            }
        }