Commits

Dobrosław Żybort committed 28d67aa

Implement private paste option

Comments (0)

Files changed (4)

 	rows, err := ctx.Database.Query(`
 		select paste_id, title, author, data, datetime 
 		from pastes 
+		where protection == 0 
 		order by paste_id desc limit ? offset ?`, nr, offset)
 	if err != nil {
 		panic(err)
 
 func insertPaste(paste *Paste, ctx *Context) (lastId int64, err error) {
 	result, err := ctx.Database.Exec(`
-		insert into pastes(Title, Author, Datetime, Data) 
-		values (?, ?, ?, ?)`,
-		paste.Title, paste.Author, paste.Datetime, paste.Data)
+		insert into pastes(Title, Author, Datetime, Data, Protection) 
+		values (?, ?, ?, ?, ?)`,
+		paste.Title,
+		paste.Author,
+		paste.Datetime,
+		paste.Data,
+		paste.Protection)
 
 	if err != nil {
 		return 0, err
 	} else {
 		paste.Author = ctx.User.Name
 	}
+	paste.Protection = pasteData.Protection
 
 	lastId, err := insertPaste(paste, ctx)
 
 	Datetime        time.Time `json:"Datetime"`
 	Title           string    `json:"Title"`
 	Author          string    `json:"Author"`
-	Protection      int       `json:"Protection"`
+	Protection      int8      `json:"Protection"`
 	Syntax          string    `json:"Syntax"`
 	URL             string    `json:"URL"`
 	Lifespan        int       `json:"Lifespan"`
 }
 
 type PasteForm struct {
-	Title  string `schema:"title"`
-	Data   string `schema:"code"`
-	Author string `schema:"username"`
+	Title      string `schema:"title"`
+	Data       string `schema:"code"`
+	Author     string `schema:"username"`
+	Protection int8   `schema:"private"`
 }
 
 //=============================================================================
 
 func NewPaste() *Paste {
 	return &Paste{
-		Datetime: time.Now().UTC(),
-		Title:    "Untitled",
-		Author:   "Anonymous",
-		Syntax:   "plaintext",
+		Datetime:   time.Now().UTC(),
+		Title:      "Untitled",
+		Author:     "Anonymous",
+		Syntax:     "plaintext",
+		Protection: 0,
 	}
 }

templates/index.html

 			<input type="text" name="username">
 		{{ end }}
 		</p>
+		<label><input type="checkbox" name="private" value="1">Private</label> 
 		<p><button>Submit</button></p>
 	</form>
 	
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.