Exemple #1
0
        /// <summary>
        /// 找回通行证密码
        /// </summary>
        /// <param name="retrievePassword"></param>
        /// <returns></returns>
        /// <exception cref="BIStudio.Framework.DefinedException"></exception>
        public void PassportRetrievePassword(SYSPassportRetrievePasswordDTO dto)
        {
            if (string.IsNullOrEmpty(dto.LoginName))
            {
                throw CFException.Create(SYSPassportChangePasswordResult.LoginNameDoesNotExist);
            }

            try
            {
                var passport = _passportRepository.Get(item => item.LoginName == dto.LoginName);
                //检查用户信息
                if (!passport.ID.HasValue)
                {
                    throw CFException.Create(SYSPassportChangePasswordResult.LoginNameDoesNotExist);
                }
                //检查新密码
                if (string.IsNullOrEmpty(dto.Password) || !ALValidator.IsLengthStr(dto.Password, 6, 16))
                {
                    throw CFException.Create(SYSPassportChangePasswordResult.PasswordTooWeak);
                }
                if (string.IsNullOrEmpty(dto.ConfirmedPassword) || dto.Password != dto.ConfirmedPassword)
                {
                    throw CFException.Create(SYSPassportChangePasswordResult.RePasswordIncorrect);
                }

                //更改密码
                passport.Password = passport.ComputePassword(dto.LoginName, dto.Password);
                _passportRepository.Modify(passport);
                return;
            }
            catch (Exception ex)
            {
                throw CFException.Create(SYSPassportChangePasswordResult.Fail, ex.Message, ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// 注册通行证
        /// </summary>
        /// <param name="passport"></param>
        /// <returns></returns>
        /// <exception cref="BIStudio.Framework.DefinedException"></exception>
        public SYSPassport PassportRegist(SYSPassportRegistDTO passport)
        {
            if (string.IsNullOrEmpty(passport.LoginName) || !ALValidator.IsLengthStr(passport.LoginName, 4, 50) || !ALValidator.IsNormalChar(passport.LoginName))
            {
                throw CFException.Create(SYSPassportRegistResult.LoginNameInvalid);
            }
            if (string.IsNullOrEmpty(passport.Password) || !ALValidator.IsLengthStr(passport.Password, 6, 16))
            {
                throw CFException.Create(SYSPassportRegistResult.PasswordTooWeak);
            }
            if (string.IsNullOrEmpty(passport.RePassword) || passport.Password != passport.RePassword)
            {
                throw CFException.Create(SYSPassportRegistResult.RePasswordIncorrect);
            }
            if (string.IsNullOrEmpty(passport.Email) || !ALValidator.IsEmail(passport.Email))
            {
                throw CFException.Create(SYSPassportRegistResult.EmailInvalid);
            }

            try
            {
                if (_passportRepository.Get(item => item.LoginName == passport.LoginName).ID != null)
                {
                    throw CFException.Create(SYSPassportRegistResult.LoginNameAlreadyExists);
                }

                if (_passportRepository.Get(item => item.Email == passport.Email).ID != null)
                {
                    throw CFException.Create(SYSPassportRegistResult.EmailAlreadyExists);
                }

                var now    = DateTime.Now;
                var entity = new SYSPassport
                {
                    LoginName      = passport.LoginName,
                    Email          = passport.Email,
                    Remarks        = passport.Remarks,
                    LastLoginTime  = now,
                    LastLoginError = 0,
                    IsValid        = true,
                    IsLocked       = false,
                    Inputer        = CFContext.User.UserName,
                    InputerID      = CFContext.User.ID,
                    InputTime      = now
                };
                entity.Password = entity.ComputePassword(passport.LoginName, passport.Password);
                _passportRepository.Add(entity);
                return(entity);
            }
            catch (Exception ex)
            {
                throw CFException.Create(SYSPassportRegistResult.Fail, ex.Message, ex);
            }
        }
        /// <summary>
        /// 获得用户可用操作
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="time"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public IList <SYSOperation> GetOperations(long accountId, DateTime?time, string ip)
        {
            time = time ?? DateTime.Now;
            ip   = ip ?? CFContext.User.IP;
            //字符串比较,需要补零
            ip = ALValidator.IsIP(ip) ? string.Join(".", ip.Split('.').Select(d => d.PadLeft(3, '0'))) : "127.000.000.001";

            var query = from o in _operationRepository.Entities
                        join so in _strategyOperationRepository.Entities on o.ID equals so.OperationID
                        join s in _strategyRepository.Entities on so.StrategyID equals s.ID
                        join sg in _strategyGroupRepository.Entities on s.ID equals sg.StrategyID
                        join g in _groupRepository.Entities on sg.GroupID equals g.ID
                        join gu in _groupAccountRepository.Entities on g.ID equals gu.GroupID
                        where
                        gu.UserId == accountId &&
                        (s.StartTime == null || s.StartTime <= time) &&
                        (s.EndTime == null || s.EndTime >= time) &&
                        (s.StartIP == null || string.Compare(s.StartIP, ip) <= 0) &&
                        (s.EndIP == null || string.Compare(s.EndIP, ip) >= 0)
                        select o;

            return(query.ToList());
        }