Esempio n. 1
0
        public ServiceResult <LoginOM> NewDeviceLoginBySMSCode(NewDeviceLoginBySMSCodeIM im)
        {
            ServiceResult <LoginOM> result = new ServiceResult <LoginOM>();
            string deviceNumber            = this.GetDeviceNumber();

            if (string.IsNullOrEmpty(deviceNumber))
            {
                result.Code = ReasonCode.MISSING_REQUIRED_FIELDS;
                return(result);
            }

            result.Data = new UserAccountComponent().NewDeviceLoginBySMSCode(im, deviceNumber);
            return(result);
        }
Esempio n. 2
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);
        }