Ejemplo n.º 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);
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public void UpdateDeviceInfo(Guid accountId, UserDeviceUpdateIM im, string ip, string deviceNumber)
        {
            var deviceList = new UserDeviceDAC().GetUserDeviceByAccountId(accountId);

            if (!deviceList.Any())
            {
                new ApplicationException();
            }

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

            new UserDeviceDAC().Update(new UserDevice()
            {
                UserAccountId = accountId, Address = im.Address, IP = ip, LastActiveTime = DateTime.UtcNow, Name = im.Name, DeviceNumber = im.DeviceNumber
            });
        }
Ejemplo n.º 5
0
        public LoginOM ValidateAuthenticator(ValidateAuthCodeIM im, string deviceNumber)
        {
            var user = CheckUser(im.CountryId, im.Cellphone, im.Password);

            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);

            return(IssueAccessToken(user));
        }