Example #1
0
 /// <summary>
 /// 用户注销
 /// </summary>
 /// <returns></returns>
 public ActionResult Logoff()
 {
     //记录用户登录日志
     oEventBLL.WriteEvent("用户:" + CurrentSession.UserID + "注销");
     CurrentSession = new SessionData();
     CurrentCookie = new CookieData();
     return RedirectToAction("Index", "Home");
 }
Example #2
0
        /// <summary>
        /// 验证用户登陆,并记录Session
        /// </summary>
        /// <param name="strUserName">输入的登陆名</param>
        /// <param name="strPassCode">输入的登陆密码明文</param>
        /// <returns>0:用户名密码为空;1:用户名不存在;2:用户密码错误;3:非内部用户;4:成功登陆</returns>
        public byte checkUser(string strUserName, string strPassCode, bool rememberLoginName = false, bool rememberUser = false)
        {
            byte nResult = 4;
            //如果接收的用户名和密码为空,返回0
            if (String.IsNullOrEmpty(strUserName) || String.IsNullOrEmpty(strPassCode))
            {
                nResult = 0;
            }
            else
            {
                //创建一个User实例
                MemberUser user = new MemberUser();
                //验证用户名
                try
                {
                    user = (from u in dbEntity.MemberUsers.Include("Role")
                            where u.Deleted == false && u.Ustatus == (byte)ModelEnum.UserStatus.VALID
                                  && u.LoginName == strUserName
                            select u).Single();
                }
                catch (Exception)
                {
                    user = null;
                    nResult = 1;
                }
                if (user != null)
                {
                    string _passcode = CommonHelper.EncryptDES(strPassCode, user.SaltKey);//加密密码密文
                    if (user.Passcode != _passcode)//验证密码密文
                    {
                        nResult = 2;
                    }
                    else if (!oGeneralBLL.IsInternal(user))
                    {
                        nResult = 3;
                    }
                    else
                    {
                        //登陆成功,记录session
                        if (user.Role.Code == "Supervisor")
                            CurrentSession = new SessionData(user.Gid, true, true, user.Culture.Culture, oGeneralBLL.GetDefaultCurrency(user.OrgID),user.OrgID);
                        else
                            CurrentSession = new SessionData(user.Gid, false, true, user.Culture.Culture, oGeneralBLL.GetDefaultCurrency(user.OrgID),user.OrgID);

                        //记录cookie
                        CookieData oCookieData = new CookieData();
                        DateTimeOffset tdLastLoginTime = DateTimeOffset.Parse(DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        user.LastLoginTime = tdLastLoginTime;//记录用户登陆时间
                        dbEntity.SaveChanges();
                        oCookieData.LastLoginTime = CommonHelper.EncryptDES(tdLastLoginTime.ToString(), user.SaltKey);//加密保存最后登陆时间
                        oCookieData.UserID = user.Gid;
                        byte isRemember = 0;
                        if (rememberUser == true)
                            isRemember = 2;
                        else if (rememberLoginName == true)
                            isRemember = 1;
                        oCookieData.Remember = isRemember;
                        CurrentCookie = oCookieData;
                        //记录用户登录日志
                        oEventBLL.WriteEvent("用户:" + user.LoginName + "登陆");
                    }
                }
            }
            return nResult;
        }
Example #3
0
        /// <summary>
        /// 初始登陆页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            CookieData oCookieData = CurrentCookie;//获取cookie
            if (oCookieData == null)//cookie为空则直接返回登陆页面
                return View();
            if (oCookieData.Remember == 2)//cookie.Remember=2 则直接自动登陆并记录session
            {
                MemberUser user = (from u in dbEntity.MemberUsers.Include("Role")
                                   where u.Deleted == false && u.Ustatus == (byte)ModelEnum.UserStatus.VALID
                                         && u.Gid == CurrentCookie.UserID
                                   select u).FirstOrDefault();
                if (user == null)
                    return View();

                //判断用户上次登陆时间是否一致
                string strLastLoginTime = CommonHelper.EncryptDES(user.LastLoginTime.ToString(), user.SaltKey);
                if (strLastLoginTime != oCookieData.LastLoginTime)
                    return View();
                DateTimeOffset tdLastLoginTime = DateTimeOffset.Parse(DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                user.LastLoginTime = tdLastLoginTime;//记录用户登陆时间
                dbEntity.SaveChanges();
                oCookieData.LastLoginTime = CommonHelper.EncryptDES(tdLastLoginTime.ToString(), user.SaltKey);//加密保存最后登陆时间
                if (user.Role.Code == "Supervisor")
                    CurrentSession = new SessionData(user.Gid, true, true, user.Culture.Culture, oGeneralBLL.GetDefaultCurrency(user.OrgID), user.OrgID);
                else
                    CurrentSession = new SessionData(user.Gid, false, true, user.Culture.Culture, oGeneralBLL.GetDefaultCurrency(user.OrgID), user.OrgID);
                CurrentCookie = oCookieData;
                //记录用户登录日志
                oEventBLL.WriteEvent("用户:" + user.LoginName + "登陆");
                return RedirectToAction("HomePage");
            }
            else if (oCookieData.Remember == 1)//若session.Remember=1 则返回登陆页面并显示cookie中上次登陆的用户名
            {
                MemberUser user = oGeneralBLL.getUser((Guid)oCookieData.UserID);
                if (user != null)
                    ViewBag.userLoginName = user.LoginName;
            }
            return View();
        }