コード例 #1
0
ファイル: IUserManager.cs プロジェクト: pathrough/Flh
        public IUserService Login(string mobileOrEmail, string password, string ip)
        {
            ExceptionHelper.ThrowIfNullOrWhiteSpace(mobileOrEmail, "mobileOrEmail", "账号不能为空");
            ExceptionHelper.ThrowIfNullOrWhiteSpace(password, "password", "密码不能为空");
            var source = _UserRepository.Entities;

            if (StringRule.VerifyMobile(mobileOrEmail))
            {
                source = source.Where(u => u.mobile == mobileOrEmail.Trim());
            }
            else if (StringRule.VerifyEmail(mobileOrEmail))
            {
                source = source.Where(u => u.email == mobileOrEmail.Trim());
            }
            else
            {
                ExceptionHelper.ThrowIfTrue(true, "mobileOrEmail", "请输入手机或者邮箱进行登陆");
            }

            var user = source.FirstOrDefault();

            if (user == null)
            {
                throw new FlhException(ErrorCode.NotExists, "账号不存在");
            }
            if (!user.enabled)
            {
                throw new FlhException(ErrorCode.Locked, "账号已被锁定");
            }
            if (!new Security.MD5().Verify(password.Trim(), user.pwd))
            {
                throw new FlhException(ErrorCode.ErrorUserNoOrPwd, "账号或密码错误");
            }

            ip = (ip ?? String.Empty).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? String.Empty;

            user.last_login_date = DateTime.Now;
            _UserRepository.SaveChanges();

            var history = new Data.LoginHistory
            {
                ip         = ip,
                login_date = DateTime.Now,
                uid        = user.uid
            };

            _LoginHistoryRepository.Add(history);
            _LoginHistoryRepository.SaveChanges();

            return(GetUser(user));
        }
コード例 #2
0
ファイル: IUserManager.cs プロジェクト: yeshusuper/Flh
        public IUserService Login(string mobileOrEmail, string password, string ip)
        {
            ExceptionHelper.ThrowIfNullOrWhiteSpace(mobileOrEmail, "mobileOrEmail", "账号不能为空");
            ExceptionHelper.ThrowIfNullOrWhiteSpace(password, "password", "密码不能为空");
            var source = _UserRepository.Entities;
            if (StringRule.VerifyMobile(mobileOrEmail))
                source = source.Where(u => u.mobile == mobileOrEmail.Trim());
            else if (StringRule.VerifyEmail(mobileOrEmail))
                source = source.Where(u => u.email == mobileOrEmail.Trim());
            else
                ExceptionHelper.ThrowIfTrue(true, "mobileOrEmail", "请输入手机或者邮箱进行登陆");

            var user = source.FirstOrDefault();
            if (user == null)
                throw new FlhException(ErrorCode.NotExists, "账号不存在");
            if (!user.enabled)
                throw new FlhException(ErrorCode.Locked, "账号已被锁定");
            if (!new Security.MD5().Verify(password.Trim(), user.pwd))
                throw new FlhException(ErrorCode.ErrorUserNoOrPwd, "账号或密码错误");

            ip = (ip ?? String.Empty).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? String.Empty;

            user.last_login_date = DateTime.Now;
            _UserRepository.SaveChanges();

            var history = new Data.LoginHistory
            {
                ip = ip,
                login_date = DateTime.Now,
                uid = user.uid
            };
            _LoginHistoryRepository.Add(history);
            _LoginHistoryRepository.SaveChanges();

            return GetUser(user);
        }