コード例 #1
0
ファイル: AuthorityBll.cs プロジェクト: gofixiao/SCM
 /// <summary>
 /// 通过用户名密码登录
 /// </summary>
 /// <param name="dal"></param>
 /// <param name="authorityModel"></param>
 /// <returns></returns>
 public static bool Signin(IDal dal,CAuthorityModel authorityModel)
 {
     int i;
     var pwd = MD5.Create().ComputeHash(Encoding.Default.GetBytes(authorityModel.UserCode + authorityModel.UPwd));
     var dt = dal.Select("select * from tUser where UPassword=@UPassword", out i,
         dal.CreateParameter("@UPassword", pwd));
     if (i == 0)
     {
         return false;
     }
     authorityModel.Id = Convert.ToInt16(dt.Rows[0]["Id"]);
     authorityModel.UserName = Convert.ToString(dt.Rows[0]["UserName"]);
     authorityModel.GroupCode = Convert.ToString(dt.Rows[0]["GroupCode"]);
     authorityModel.DeptCode = Convert.ToString(dt.Rows[0]["DeptCode"]);
     return true;
 }
コード例 #2
0
 public CAuthorityModel Post(CAuthorityModel value)
 {
     using (var dal =DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
     {
         bool ok;
         try
         {
             dal.Open();
         }
         catch
         {
             throw new HttpResponseException(new SystemExceptionMessage());
         }
         var httpCookie = HttpContext.Current.Request.Cookies["Token"];
         if (value.Remain && httpCookie != null && string.IsNullOrEmpty(value.UserCode) && string.IsNullOrEmpty(value.UPwd))
         {
             //Token不为空 用户名和密码为空,则使用token登录
             ok=AuthorityBll.Signin(dal, httpCookie.Value, value);
         }
         else
         {
             //使用用户名密码登录
             ok=AuthorityBll.Signin(dal, value);
         }
         if (!ok)
         {
             throw new HttpResponseException(new DataNotFoundMessage());
         }
         HttpContext.Current.Session["SignUser"] = value;
         //生成Token
         var token = Guid.NewGuid().ToString();
         AuthorityBll.UpdateToken(dal,token,value.UserCode);
         HttpContext.Current.Response.Cookies["Token"].Value =token;
         HttpContext.Current.Response.Cookies["Token"].Expires = DateTime.Now.AddDays(30);
         if (value.Remain) return value;
         HttpContext.Current.Response.Cookies["Token"].Expires = DateTime.Now.AddDays(-1);
         AuthorityBll.DropToken(dal, value.UserCode);
         return value;
     }
 }