Beispiel #1
0
        public StatusData Login(string username, string pwd, bool remember = true)
        {
            StatusData myStatusData = new StatusData();          //返回状态
            //
            AuthCodeClass myAuthCodeClass = new AuthCodeClass(); //授权码类
            //
            User_UserName myUserInfo = new User_UserName();

            using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities())//数据库操作
            {
                //
                myUserInfo = myOperating.User_UserName.FirstOrDefault(p => p.MobilePhone == username);
                if (myUserInfo != null)
                {
                    if (!String.IsNullOrWhiteSpace(pwd))
                    {
                        pwd = Md5Class.CreateMd5(pwd);//
                    }
                    if (myUserInfo.PassWord != pwd)
                    {
                        myStatusData.operateStatus = 2;//密码错误
                    }
                    else if (myUserInfo.Status != 200)
                    {
                        myStatusData.operateStatus = myUserInfo.Status;//201锁定,联系客服
                    }
                    else
                    {
                        string myAuthCodeStr = myAuthCodeClass.CreateAuthCode(myUserInfo.MobilePhone, myUserInfo.RoleId, remember);
                        myStatusData.operateStatus   = 200;//登录成功
                        myStatusData.userAuthCode    = myAuthCodeStr;
                        myUserInfo.RecentlyLoginDate = DateTime.Now;
                        myOperating.SaveChanges();
                    }
                }
            }
            return(myStatusData);
        }