예제 #1
0
        private void AddOperateHistory(string pOperater, Enumeration.OperateType pOperateType, string pReferenceId, string pContent)
        {
            SysOperateHistory operateHistory = new SysOperateHistory();

            operateHistory.Id          = GuidUtil.New();
            operateHistory.UserId      = pOperater;
            operateHistory.ReferenceId = pReferenceId;
            operateHistory.Ip          = "";
            operateHistory.Type        = pOperateType;
            operateHistory.Content     = pContent;
            operateHistory.CreateTime  = DateTime.Now;
            operateHistory.Creator     = pOperater;
            _db.SysOperateHistory.Add(operateHistory);
            _db.SaveChanges();
        }
예제 #2
0
        public LoginResult <TUser> Login(string userName, string password, bool isPersistent, SysUserLoginHistory userLoginHistory)
        {
            SysUserLoginHistory loginHis = new SysUserLoginHistory();

            userName = userName.Trim();
            var user = _userManager.FindByName <TUser, int>(userName);

            if (user == null)
            {
                return(new LoginResult <TUser>(Enumeration.LoginResult.Failure, Enumeration.LoginResultTip.UserNotExist));
            }

            var lastUserInfo = user;

            loginHis.UserId    = user.Id;
            loginHis.LoginTime = DateTime.Now;
            loginHis.LoginType = userLoginHistory.LoginType;
            loginHis.Ip        = userLoginHistory.Ip;
            loginHis.Country   = userLoginHistory.Country;
            loginHis.Province  = userLoginHistory.Province;
            loginHis.City      = userLoginHistory.City;

            user = _userManager.Find <TUser, int>(userName, password);



            if (user == null)
            {
                loginHis.Description = "Login failed, password error";
                loginHis.Result      = Enumeration.LoginResult.Failure;
                _db.SysUserLoginHistory.Add(loginHis);
                _db.SaveChanges();

                return(new LoginResult <TUser>(Enumeration.LoginResult.Failure, Enumeration.LoginResultTip.UserPasswordIncorrect, lastUserInfo));
            }

            if (user.IsDisable)
            {
                loginHis.Description = "Login failed, the account is disabled ";
                loginHis.Result      = Enumeration.LoginResult.Failure;
                _db.SysUserLoginHistory.Add(loginHis);
                _db.SaveChanges();

                return(new LoginResult <TUser>(Enumeration.LoginResult.Failure, Enumeration.LoginResultTip.UserDisabled, lastUserInfo));
            }

            if (user.IsDelete)
            {
                loginHis.Description = "Login failed, the account has been deleted ";
                loginHis.Result      = Enumeration.LoginResult.Failure;
                _db.SysUserLoginHistory.Add(loginHis);
                _db.SaveChanges();
                return(new LoginResult <TUser>(Enumeration.LoginResult.Failure, Enumeration.LoginResultTip.UserDeleted, lastUserInfo));
            }


            loginHis.Description = "Login success ";
            loginHis.Result      = Enumeration.LoginResult.Success;
            _db.SysUserLoginHistory.Add(loginHis);

            user.LastLoginTime = loginHis.LoginTime;
            user.LastLoginIp   = loginHis.Ip;

            _db.SaveChanges();

            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
            var identity = _userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = isPersistent
            }, identity);



            return(new LoginResult <TUser>(Enumeration.LoginResult.Success, Enumeration.LoginResultTip.VerifyPass, lastUserInfo));
        }
예제 #3
0
        private void AddOperateHistory(int operater, Enumeration.OperateType operateType, int referenceId, string content)
        {
            SysOperateHistory operateHistory = new SysOperateHistory();

            operateHistory.UserId      = operater;
            operateHistory.ReferenceId = referenceId;
            operateHistory.Ip          = "";
            operateHistory.Type        = operateType;
            operateHistory.Content     = content;
            operateHistory.CreateTime  = DateTime.Now;
            operateHistory.Creator     = operater;
            _db.SysOperateHistory.Add(operateHistory);
            _db.SaveChanges();
        }
예제 #4
0
        private void AddOperateHistory(Enumeration.OperateType operateType, int referenceId, string content)
        {
            int userId = HttpContext.Current.GetOwinContext().Request.User.Identity.GetUserId <int>();
            SysOperateHistory operateHistory = new SysOperateHistory();

            operateHistory.UserId      = userId;
            operateHistory.ReferenceId = referenceId;
            operateHistory.Ip          = "";
            operateHistory.Type        = operateType;
            operateHistory.Content     = content;
            operateHistory.CreateTime  = DateTime.Now;
            operateHistory.Creator     = userId;
            _db.SysOperateHistory.Add(operateHistory);
            _db.SaveChanges();
        }