コード例 #1
0
        public async Task <IActionResult> Authentication(BiometricsParameters parameters)
        {
            var detected = false;

            if (parameters.Face != null)
            {
                await using var ms = new MemoryStream();
                await parameters.Face.CopyToAsync(ms);

                detected = await _biometricValidator.DetectFace(
                    registered : await _fileProxy.GetFace(parameters.Context.UserId),
                    login : ms.ToArray(),
                    userId : parameters.Context.UserId);
            }

            if (parameters.Voice != null)
            {
                await using var ms = new MemoryStream();
                await parameters.Voice.CopyToAsync(ms);

                detected = await _biometricValidator.DetectVoice(
                    registered : await _fileProxy.GetVoice(parameters.Context.UserId),
                    login : ms.ToArray(),
                    userId : parameters.Context.UserId);
            }


            if (detected)
            {
                var token = await _accountProxy.GenerateToken(parameters.Context);

                if (string.IsNullOrWhiteSpace(token))
                {
                    return(RedirectToAction("Login", "Account"));
                }

                var options = new CookieOptions {
                    Expires = DateTime.Now.AddMinutes(60)
                };
                Response.Cookies.Append("Token", token, options);

                switch (parameters.Context.Type)
                {
                case UserType.Staff:
                    return(RedirectToAction("Staff", "Dashboard", new { id = parameters.Context.UserId }));

                case UserType.Manager:
                    return(RedirectToAction("Manager", "Dashboard", new { id = parameters.Context.UserId }));

                default:
                    return(RedirectToAction("Login", "Account"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }