コード例 #1
0
        public ActionResult ViewFile()
        {
            if (string.IsNullOrEmpty(Request.QueryString["FileID"]) ||
                string.IsNullOrEmpty(Request.QueryString["Token"]) ||
                string.IsNullOrEmpty(Request.QueryString["UserEmail"]))
            {
                return(RedirectToAction("ErrorView", new ELTError()
                {
                    Type = ELTErrorType.Input_format_is_not_correct,
                    Description = ELTErrorType.Input_format_is_not_correct.ToString(),
                    ReferenceID = ErrorConstant.ERROR_REF10000
                }));
            }

            //Check if Cookie is Expired.
            TokenBL      tBL   = new TokenBL();
            FileSystemBL fBL   = new FileSystemBL();
            ELTToken     token = tBL.GetToken(Request.QueryString["Token"]);

            //If so return a view that the file is no longer availabe and you need to get the file from the sender.
            if (token.Expired)
            {
                return(RedirectToAction("ErrorView", new ELTError()
                {
                    Type = ELTErrorType.Token_has_been_expired,
                    Description = ELTErrorType.Token_has_been_expired.ToString(),
                    ReferenceID = ErrorConstant.ERROR_REF10002
                }));
            }


            if (Request.Cookies["TempUser"] != null)
            {
                if (Request.Cookies["TempUser"]["ReadFileAllowedToken"] == Request.QueryString["Token"])
                {
                    return(ReturnELTFile(Convert.ToInt32(Request.QueryString["FileID"])));
                }
            }

            if (!User.Identity.IsAuthenticated)
            {
                Session["NewUserFromFileAccess"] = Request.Url.Query;
                //NameValueCollection qscoll=    HttpUtility.ParseQueryString(Request.Url.Query);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                int FileID = fBL.GetFileIDforParentID(User.Identity.Name, Convert.ToInt32(Request.QueryString["FileID"]));
                if (FileID == 0)
                {
                    return(RedirectToAction("ErrorView", new ELTError()
                    {
                        Type = ELTErrorType.File_does_not_exist,
                        Description = ELTErrorType.File_does_not_exist.ToString(),
                        ReferenceID = ErrorConstant.ERROR_REF10001
                    }));
                }
                return(ReturnELTFile(FileID));
            }
        }
コード例 #2
0
        public ELTToken GetToken(string Token)
        {
            SqlConnection conn = new SqlConnection(GetConnectionString(AppConstants.DB_CONN_PROD));
            SqlCommand    cmd  = new SqlCommand()
            {
                Connection = conn, CommandType = CommandType.StoredProcedure, CommandText = "[COMM].[AccessCommunicationToken]"
            };
            List <ELTFileSystemItem> list = new List <ELTFileSystemItem>();

            ELTToken token = new ELTToken();

            try
            {
                string Command = "Get";

                DateTime TimeStart      = DateTime.Now;
                DateTime CreatedDate    = DateTime.Now;
                DateTime TimeEnd        = DateTime.Now;
                bool     Expired        = false;
                int      TokenType      = 0;
                string   RecipientEmail = string.Empty;
                int      Period         = 0;
                cmd.Parameters.Add(new SqlParameter("@Command", Command));
                cmd.Parameters.Add(new SqlParameter("@Period", Period));
                cmd.Parameters.Add(new SqlParameter("@Token", Token));
                cmd.Parameters.Add(new SqlParameter("@TokenType", TokenType));
                cmd.Parameters.Add(new SqlParameter("@TimeStart", TimeStart));
                cmd.Parameters.Add(new SqlParameter("@TimeEnd", TimeEnd));
                cmd.Parameters.Add(new SqlParameter("@Expired", Expired));
                cmd.Parameters.Add(new SqlParameter("@RecipientEmail", RecipientEmail));
                cmd.Parameters.Add(new SqlParameter("@CreatedDate", CreatedDate));

                cmd.Parameters["@Token"].Direction = ParameterDirection.InputOutput;
                cmd.Parameters["@Token"].Size      = 1000;

                cmd.Parameters["@TokenType"].Direction = ParameterDirection.InputOutput;
                cmd.Parameters["@TokenType"].Size      = 100;

                cmd.Parameters["@TimeStart"].Direction = ParameterDirection.InputOutput;
                cmd.Parameters["@TimeStart"].Size      = 100;

                cmd.Parameters["@TimeEnd"].Direction = ParameterDirection.InputOutput;
                cmd.Parameters["@TimeEnd"].Size      = 100;

                cmd.Parameters["@Expired"].Direction = ParameterDirection.InputOutput;
                cmd.Parameters["@Expired"].Size      = 100;

                cmd.Parameters["@Expired"].Direction = ParameterDirection.InputOutput;
                cmd.Parameters["@Expired"].Size      = 100;

                cmd.Parameters["@RecipientEmail"].Direction = ParameterDirection.InputOutput;
                cmd.Parameters["@RecipientEmail"].Size      = 100;

                cmd.Parameters["@CreatedDate"].Direction = ParameterDirection.InputOutput;
                cmd.Parameters["@CreatedDate"].Size      = 100;
                conn.Open();
                cmd.ExecuteNonQuery();

                token.Token          = Convert.ToString(cmd.Parameters["@Token"].Value);
                token.RecipientEmail = Convert.ToString(cmd.Parameters["@RecipientEmail"].Value);
                token.TokenType      = (TokenType)Convert.ToInt32(cmd.Parameters["@TokenType"].Value);
                token.Expired        = Convert.ToBoolean(cmd.Parameters["@Expired"].Value);
                token.TimeStart      = cmd.Parameters["@TimeStart"].Value.GetType()
                                       == typeof(System.DBNull) ? new DateTime(): Convert.ToDateTime(cmd.Parameters["@TimeStart"].Value);
                token.TimeEnd = cmd.Parameters["@TimeEnd"].Value.GetType()
                                == typeof(System.DBNull) ? new DateTime() : Convert.ToDateTime(cmd.Parameters["@TimeEnd"].Value);
                token.CreatedDate = Convert.ToDateTime(cmd.Parameters["@CreatedDate"].Value);
                token.Period      = Convert.ToInt32(cmd.Parameters["@Period"].Value);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }


            return(token);
        }