示例#1
0
        private LoginResult <SysClientUser> SignIn(string username, string password, bool isrememberme)
        {
            string loginIp = CommonUtils.GetIP();


            SysUserLoginHistory userLoginHistory = new SysUserLoginHistory();

            userLoginHistory.Ip = loginIp;
            //userLoginHistory.Country = ipInfo.Country;
            //userLoginHistory.Province = ipInfo.Province;
            //userLoginHistory.City = ipInfo.City;
            userLoginHistory.LoginType = Enumeration.LoginType.Computer;
            var identity = new AspNetIdentiyAuthorizeRelay <SysClientUser>(CurrentDb);

            var result = identity.Login(username, password, isrememberme, userLoginHistory);


            if (result.User != null)
            {
                ILog log = LogManager.GetLogger(CommonSetting.LoggerLoginWeb);
                log.Info(FormatUtils.LoginInWeb(result.User.Id, result.User.UserName));
            }

            return(result);
        }
示例#2
0
        public LoginResult <TUser> SignIn(string username, string password, string loginIp, Enumeration.LoginType loginType)
        {
            DateTime timeNow = DateTime.Now;

            IpInfo ipInfo = new IpInfo();
            SysUserLoginHistory loginHis = new SysUserLoginHistory();

            loginHis.LoginTime = timeNow;
            loginHis.Ip        = ipInfo.Ip;
            loginHis.Country   = ipInfo.Country;
            loginHis.Province  = ipInfo.Province;
            loginHis.City      = ipInfo.City;
            loginHis.LoginType = loginType;



            var identity = new AspNetIdentiyAuthorizeRelay <TUser>();

            var result = identity.Login(username, password, timeNow, loginIp);

            switch (result.ResultTip)
            {
            case Enumeration.LoginResultTip.UserNotExist:
                loginHis.Description = "登录失败";
                loginHis.Result      = Enumeration.LoginResult.Failure;
                break;

            case Enumeration.LoginResultTip.UserAccessFailedMaxCount:
                loginHis.Description = "登录失败,连续输入错误密码3次,锁定帐号30分钟";
                loginHis.Result      = Enumeration.LoginResult.Failure;
                break;

            case Enumeration.LoginResultTip.UserPasswordIncorrect:
                loginHis.Description = "登录失败,密码错误";
                loginHis.Result      = Enumeration.LoginResult.Failure;
                loginHis.UserId      = result.User.Id;
                break;

            case Enumeration.LoginResultTip.UserDisabled:
                loginHis.Description = "登录失败,帐号被禁用";
                loginHis.Result      = Enumeration.LoginResult.Failure;
                loginHis.UserId      = result.User.Id;
                break;

            case Enumeration.LoginResultTip.UserDeleted:
                loginHis.Description = "登录失败,帐号已删除";
                loginHis.Result      = Enumeration.LoginResult.Failure;
                loginHis.UserId      = result.User.Id;
                break;

            case Enumeration.LoginResultTip.VerifyPass:
                loginHis.Description = "登录成功";
                loginHis.Result      = Enumeration.LoginResult.Success;
                loginHis.UserId      = result.User.Id;

                break;
            }

            CurrentDb.SysUserLoginHistory.Add(loginHis);
            CurrentDb.SaveChanges();


            return(result);
        }