예제 #1
0
        public async Task <AuthResponse> OTPOptionsAsync(string userid)
        {
            try
            {
                var response = new AuthResponse {
                    Status = new APIResponseStatus {
                        IsSuccessful = true, Message = new APIResponseMessage()
                    }
                };
                var settings = await _service.GetSettingsAsync() ?? new SecurityResp
                {
                    authSettups = new List <Security>()
                };
                if (settings.authSettups.Count() > 0)
                {
                    var multiplefFA = settings.authSettups.Where(a => a.Module == (int)Modules.CREDIT).ToList();
                    var user        = await _userManager.FindByIdAsync(userid);

                    if (multiplefFA.Count() > 0)
                    {
                        if (_detectionService.Device.Type.ToString().ToLower() == Device.Desktop.ToString().ToLower())
                        {
                            if (multiplefFA.FirstOrDefault(a => a.Media == (int)Media.EMAIL).ActiveOnWebApp)
                            {
                                await _identityService.SendOTPToEmailAsync(user);

                                response.Status.Message.FriendlyMessage = "OTP Verification Code sent to your email";
                                return(response);
                            }
                            if (multiplefFA.FirstOrDefault(a => a.Media == (int)Media.SMS) != null && multiplefFA.FirstOrDefault(a => a.Media == (int)Media.SMS).ActiveOnWebApp)
                            {
                                response.Status.Message.FriendlyMessage = "OTP Verification Code sent to your number";
                                return(response);
                            }
                        }
                        if (_detectionService.Device.Type.ToString().ToLower() == Device.Mobile.ToString().ToLower())
                        {
                            if (multiplefFA.FirstOrDefault(a => a.Media == (int)Media.EMAIL).ActiveOnMobileApp)
                            {
                                response.Status.Message.FriendlyMessage = "OTP Verification Code sent to your email";
                                return(response);
                            }
                            if (multiplefFA.FirstOrDefault(a => a.Media == (int)Media.SMS).ActiveOnMobileApp)
                            {
                                response.Status.Message.FriendlyMessage = "OTP Verification Code sent to your number";
                                return(response);
                            }
                        }
                    }
                }

                response.Status.IsSuccessful = false;
                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }