Пример #1
0
        /// <summary>
        /// 取得用者相關資料
        /// </summary>
        /// <param name="userID">使用者帳號</param>
        /// <returns></returns>
        public static LoginUserInfoDataEntity GetUser(string userID)
        {
            LoginUserInfoDataEntity user = new LoginUserInfoDataEntity()
            {
                loginuserID       = string.Empty,
                loginuserName     = string.Empty,
                loginuserPassword = string.Empty,
                deptID            = string.Empty,
                deptName          = string.Empty
            };

            var strSQL = @"
                            SELECT
	                            u.loginuserID 
	                            ,u.loginuserPassword 
	                            ,u.loginuserName 
	                            ,u.deptID 
	                            ,d.deptName  
                            FROM LBOM_LOGIN_USER U
                            JOIN LBOM_dept D
	                            ON U.DEPTID = d.DEPTID
                            WHERE u.loginuserID = @loginuserID
                    ";

            using (var conn = new SqlConnection(ConnectionString))
                using (var cmd = new SqlCommand(strSQL, conn))
                {
                    cmd.Parameters.Add(new SqlParameter("@loginuserID", userID));
                    conn.Open();

                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            dr.Read();
                            //Mapper.CreateMap<IDataReader, LoginUserInfoDataEntity>();
                            //user = Mapper.Map<IDataReader, IList<LoginUserInfoDataEntity>>(dr).ToList().First();
                            user.deptID            = dr["deptID"].ToString();
                            user.loginuserID       = dr["loginuserID"].ToString();
                            user.loginuserName     = dr["loginuserName"].ToString();
                            user.loginuserPassword = dr["loginuserPassword"].ToString();
                            user.deptName          = dr["deptName"].ToString();
                        }
                    }
                }
            return(user);
        }
Пример #2
0
        /// <summary>
        /// 登入處理
        /// </summary>
        /// <param name="user"></param>
        /// <param name="isPersisten"></param>
        protected void LoginProcess(LoginUserInfoDataEntity user, bool isPersisten = false)
        {
            //建立票證
            var ticket = new FormsAuthenticationTicket(
                version: 1,
                name: user.loginuserID,
                issueDate: DateTime.Now,
                expiration: DateTime.Now.AddMinutes(30),
                isPersistent: isPersisten,
                userData: "",
                cookiePath: FormsAuthentication.FormsCookiePath
                );

            var encTicket       = FormsAuthentication.Encrypt(ticket);
            var encryptedTicket = FormsAuthentication.Encrypt(ticket);
            var cookie          = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            Session["userInfo"] = user;//將使用者資料物件存入SESSION

            Response.Cookies.Add(cookie);
        }