Example #1
0
        public LoginOM ValidateAuthenticatorBySMSCode(ValidateLoginBySMSCodeIM im, string deviceNumber)
        {
            var user                = CheckUser(im.CountryId, im.Cellphone);
            var prevVerifier        = new LoginCellphoneVerifier();
            var hadOpenedGoogleAuth = ValidationFlagComponent.CheckSecurityOpened(user.ValidationFlag, ValidationFlag.GooogleAuthenticator);

            var deviceList = new UserDeviceDAC().GetUserDeviceByAccountId(user.Id);

            if (!deviceList.Any())
            {
                new ApplicationException();
            }
            if (deviceList.All(item => item.DeviceNumber != deviceNumber))
            {
                new ApplicationException();
            }

            SecurityVerify.Verify(new GoogleVerifier(), SystemPlatform.FiiiPay, user.Id.ToString(), user.AuthSecretKey, im.GoogleCode);

            SecurityVerify.Verify <LoginBySMSVerify>(new CustomVerifier("LoginBySMS"), SystemPlatform.FiiiPay, user.Id.ToString(), (model) =>
            {
                return(model.CellphoneVerified);
            });

            var loginOm = IssueAccessToken(user);

            return(loginOm);
        }
        public GetOpenedSecuritiesOM GetUserOpenedSecurities(UserAccount user)
        {
            var country = new CountryDAC().GetById(user.CountryId);
            GetOpenedSecuritiesOM entity = new GetOpenedSecuritiesOM();

            entity.IsOpenedAuthencator = ValidationFlagComponent.CheckSecurityOpened(user.ValidationFlag, ValidationFlag.GooogleAuthenticator);
            entity.CellPhone           = new UserAccountComponent().GetMaskedCellphone(country.PhoneCode, user.Cellphone);
            return(entity);
        }
        public GetStatusOfSecurityOM GetUserStatusOfSecurity(UserAccount user)
        {
            GetStatusOfSecurityOM entity = new GetStatusOfSecurityOM();

            entity.GoogleAuthenticator = new SecurityStatus
            {
                HasBinded = !string.IsNullOrEmpty(user.AuthSecretKey),
                HasOpened = ValidationFlagComponent.CheckSecurityOpened(user.ValidationFlag, ValidationFlag.GooogleAuthenticator)
            };
            return(entity);
        }
Example #4
0
        public LoginOM LoginBySMSCode(int countryId, string cellphone, string code, string deviceNumber)
        {
            var verifier = new LoginCellphoneVerifier();

            SecurityVerify.Verify(verifier, SystemPlatform.FiiiPay, $"{countryId}:{cellphone}", code);

            var user = CheckUser(countryId, cellphone);
            var isNeedGoogleVerify =
                ValidationFlagComponent.CheckSecurityOpened(user.ValidationFlag, ValidationFlag.GooogleAuthenticator);

            var deviceList = new UserDeviceDAC().GetUserDeviceByAccountId(user.Id);

            var isNewDevice = deviceList.All(item => item.DeviceNumber != deviceNumber);

            if (!deviceList.Any())
            {
                if (!string.IsNullOrEmpty(user.Pin) && !user.IsBindingDevice)
                {
                    new UserDeviceDAC().Insert(new UserDevice()
                    {
                        DeviceNumber = deviceNumber, Name = " ", UserAccountId = user.Id, LastActiveTime = DateTime.UtcNow
                    });

                    new UserAccountDAC().UpdateIsBindingDevice(user.Id);
                    isNewDevice = false;
                }
            }

            if (isNeedGoogleVerify || (isNewDevice && !string.IsNullOrEmpty(user.Pin)))
            {
                string loginTypeName = isNewDevice ? "NewDeviceLogin" : "LoginBySMS";
                var    model         = new LoginBySMSVerify
                {
                    CellphoneVerified = true
                };
                SecurityVerify.SetModel(new CustomVerifier(loginTypeName), SystemPlatform.FiiiPay, user.Id.ToString(), model);
                return(new LoginOM()
                {
                    IsNeedGoogleVerify = isNeedGoogleVerify, IsNewDevice = isNewDevice, UserInfo = GetUserVerifyItems(user)
                });
            }

            return(IssueAccessToken(user));
        }
Example #5
0
        public LoginOM Login(LoginIM im, string deviceNumber, string ip)
        {
            var user = CheckUser(im.CountryId, im.Cellphone, im.Password);
            var isNeedGoogleVerify =
                ValidationFlagComponent.CheckSecurityOpened(user.ValidationFlag, ValidationFlag.GooogleAuthenticator);

            var deviceList = new UserDeviceDAC().GetUserDeviceByAccountId(user.Id);

            var isNewDevice = deviceList.All(item => item.DeviceNumber != deviceNumber);

            if (!deviceList.Any())
            {
                if (!string.IsNullOrEmpty(user.Pin) && !user.IsBindingDevice)
                {
                    new UserDeviceDAC().Insert(new UserDevice()
                    {
                        DeviceNumber = deviceNumber, Name = " ", UserAccountId = user.Id, LastActiveTime = DateTime.UtcNow
                    });

                    new UserAccountDAC().UpdateIsBindingDevice(user.Id);
                    isNewDevice = false;
                }
            }
            if ((isNewDevice && !string.IsNullOrEmpty(user.Pin)) || isNeedGoogleVerify)
            {
                return(new LoginOM()
                {
                    IsNeedGoogleVerify = isNeedGoogleVerify, IsNewDevice = isNewDevice, UserInfo = GetUserVerifyItems(user)
                });
            }

            Task.Factory.StartNew(() =>
            {
                var model = new UserLoginLog
                {
                    UserAccountId = user.Id,
                    IP            = ip,
                    Timestamp     = DateTime.UtcNow,
                };
                new UserLoginLogDAC().Insert(model);
            });

            return(IssueAccessToken(user));
        }
Example #6
0
        public LoginOM NewDeviceLoginBySMSCode(NewDeviceLoginBySMSCodeIM im, string deviceNumber)
        {
            var user           = CheckUser(im.CountryId, im.Cellphone);
            var prevVerifier   = new LoginCellphoneVerifier();
            var customVerifier = new CustomVerifier("NewDeviceLogin");

            var hadOpenedGoogleAuth = ValidationFlagComponent.CheckSecurityOpened(user.ValidationFlag, ValidationFlag.GooogleAuthenticator);

            SecurityVerify.Verify <LoginBySMSVerify>(customVerifier, SystemPlatform.FiiiPay, user.Id.ToString(), (model) =>
            {
                bool result = model.CellphoneVerified;
                if (user.L1VerifyStatus == VerifyStatus.Certified)
                {
                    var identityNo = new UserProfileComponent().PreVerifyLv1(user).IdentityDocNo;
                    result         = result && new IDNumberVerifier().Verify(SystemPlatform.FiiiPay, user.Id.ToString(), identityNo, im.IdentityDocNo);
                    if (!result)
                    {
                        var errorCountKey = customVerifier.GetErrorCountKey(SystemPlatform.FiiiPay, user.Id.ToString());
                        var errorCount    = SecurityVerify.CheckErrorCount(customVerifier, errorCountKey);
                        new IDNumberVerifier().VerifyFaild(Constant.VIRIFY_FAILD_TIMES_LIMIT - errorCount - 1);
                    }
                }
                if (!string.IsNullOrEmpty(user.Pin))
                {
                    result = result && new PinVerifier().Verify(SystemPlatform.FiiiPay, user.Id.ToString(), user.Pin, AES128.Decrypt(im.Pin, AES128.DefaultKey));
                    if (!result)
                    {
                        var errorCountKey = customVerifier.GetErrorCountKey(SystemPlatform.FiiiPay, user.Id.ToString());
                        var errorCount    = SecurityVerify.CheckErrorCount(customVerifier, errorCountKey);
                        new PinVerifier().VerifyFaild(Constant.VIRIFY_FAILD_TIMES_LIMIT - errorCount - 1);
                    }
                }
                if (SecurityVerify.CheckSecurityOpened(user.ValidationFlag, ValidationFlag.GooogleAuthenticator))
                {
                    var googleVerifier = new GoogleVerifier();
                    if (string.IsNullOrEmpty(im.GoogleCode))
                    {
                        result = false;
                    }
                    result = result && SecurityVerify.CheckCodeValid(googleVerifier, SystemPlatform.FiiiPay, user.Id.ToString(), im.GoogleCode);
                    result = result && googleVerifier.Verify(user.AuthSecretKey, im.GoogleCode);
                    if (!result)
                    {
                        var errorCountKey = customVerifier.GetErrorCountKey(SystemPlatform.FiiiPay, user.Id.ToString());
                        var errorCount    = SecurityVerify.CheckErrorCount(customVerifier, errorCountKey);
                        googleVerifier.VerifyFaild(Constant.VIRIFY_FAILD_TIMES_LIMIT - errorCount - 1);
                    }
                }

                return(result);
            });

            new UserDeviceDAC().Insert(new UserDevice()
            {
                DeviceNumber = deviceNumber, Name = " ", UserAccountId = user.Id, LastActiveTime = DateTime.UtcNow
            });

            var loginOm = IssueAccessToken(user);

            return(loginOm);
        }