2017-09-13 15:40:49 +00:00
package main
import (
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
"crypto/sha256"
"encoding/hex"
2017-09-13 15:40:49 +00:00
"html"
"io"
"log"
"net"
"net/http"
"os"
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
"path/filepath"
2017-09-13 15:40:49 +00:00
"regexp"
"strconv"
"strings"
)
// ? - Should we add a new permission or permission zone (like per-forum permissions) specifically for profile comment creation
// ? - Should we allow banned users to make reports? How should we handle report abuse?
2017-09-15 22:20:01 +00:00
// TODO: Add a permission to stop certain users from using custom avatars
2017-09-13 15:40:49 +00:00
// ? - Log username changes and put restrictions on this?
2017-10-30 09:57:08 +00:00
func routeTopicCreate ( w http . ResponseWriter , r * http . Request , user User , sfid string ) RouteError {
2017-09-13 15:40:49 +00:00
var fid int
var err error
if sfid != "" {
fid , err = strconv . Atoi ( sfid )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "You didn't provide a valid number for the forum ID." , w , r , user )
2017-09-13 15:40:49 +00:00
}
}
2017-09-23 19:57:13 +00:00
if fid == 0 {
fid = config . DefaultForum
}
2017-09-13 15:40:49 +00:00
2017-10-30 09:57:08 +00:00
headerVars , ferr := ForumUserCheck ( w , r , & user , fid )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
2017-09-15 22:20:01 +00:00
if ! user . Perms . ViewTopic || ! user . Perms . CreateTopic {
2017-10-30 09:57:08 +00:00
return NoPermissions ( w , r , user )
2017-09-13 15:40:49 +00:00
}
BuildWidgets ( "create_topic" , nil , headerVars , r )
// Lock this to the forum being linked?
// Should we always put it in strictmode when it's linked from another forum? Well, the user might end up changing their mind on what forum they want to post in and it would be a hassle, if they had to switch pages, even if it is a single click for many (exc. mobile)
var strictmode bool
if vhooks [ "topic_create_pre_loop" ] != nil {
runVhook ( "topic_create_pre_loop" , w , r , fid , & headerVars , & user , & strictmode )
}
2017-11-02 04:12:51 +00:00
// TODO: Re-add support for plugin_guilds
2017-09-13 15:40:49 +00:00
var forumList [ ] Forum
var canSee [ ] int
if user . IsSuperAdmin {
canSee , err = fstore . GetAllVisibleIDs ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
} else {
2017-09-15 22:20:01 +00:00
group , err := gstore . Get ( user . Group )
if err != nil {
2017-10-30 09:57:08 +00:00
// TODO: Refactor this
2017-09-15 22:20:01 +00:00
LocalError ( "Something weird happened behind the scenes" , w , r , user )
2017-10-30 09:57:08 +00:00
log . Printf ( "Group #%d doesn't exist, but it's set on User #%d" , user . Group , user . ID )
return nil
2017-09-15 22:20:01 +00:00
}
2017-09-13 15:40:49 +00:00
canSee = group . CanSee
}
// TODO: plugin_superadmin needs to be able to override this loop. Skip flag on topic_create_pre_loop?
for _ , ffid := range canSee {
2017-11-02 04:12:51 +00:00
// TODO: Surely, there's a better way of doing this. I've added it in for now to support plugin_guilds, but we really need to clean this up
2017-09-13 15:40:49 +00:00
if strictmode && ffid != fid {
continue
}
// Do a bulk forum fetch, just in case it's the SqlForumStore?
forum := fstore . DirtyGet ( ffid )
2017-09-24 00:49:41 +00:00
if forum . Name != "" && forum . Active {
2017-09-28 22:16:34 +00:00
fcopy := forum . Copy ( )
2017-09-24 00:49:41 +00:00
if hooks [ "topic_create_frow_assign" ] != nil {
// TODO: Add the skip feature to all the other row based hooks?
if runHook ( "topic_create_frow_assign" , & fcopy ) . ( bool ) {
continue
}
2017-09-13 15:40:49 +00:00
}
2017-09-24 00:49:41 +00:00
forumList = append ( forumList , fcopy )
2017-09-13 15:40:49 +00:00
}
}
ctpage := CreateTopicPage { "Create Topic" , user , headerVars , forumList , fid }
if preRenderHooks [ "pre_render_create_topic" ] != nil {
if runPreRenderHook ( "pre_render_create_topic" , w , r , & user , & ctpage ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err = template_create_topic_handle ( ctpage , w )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
// POST functions. Authorised users only.
2017-10-30 09:57:08 +00:00
func routeTopicCreateSubmit ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// TODO: Reduce this to 1MB for attachments for each file?
if r . ContentLength > int64 ( config . MaxRequestSize ) {
size , unit := convertByteUnit ( float64 ( config . MaxRequestSize ) )
2017-10-30 09:57:08 +00:00
return CustomError ( "Your attachments are too big. Your files need to be smaller than " + strconv . Itoa ( int ( size ) ) + unit + "." , http . StatusExpectationFailed , "Error" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
r . Body = http . MaxBytesReader ( w , r . Body , int64 ( config . MaxRequestSize ) )
err := r . ParseMultipartForm ( int64 ( megabyte ) )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Unable to parse the form" , w , r , user )
2017-09-13 15:40:49 +00:00
}
fid , err := strconv . Atoi ( r . PostFormValue ( "topic-board" ) )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "The provided ForumID is not a valid number." , w , r , user )
2017-09-13 15:40:49 +00:00
}
// TODO: Add hooks to make use of headerLite
2017-10-30 09:57:08 +00:00
_ , ferr := SimpleForumUserCheck ( w , r , & user , fid )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
2017-09-15 22:20:01 +00:00
if ! user . Perms . ViewTopic || ! user . Perms . CreateTopic {
2017-10-30 09:57:08 +00:00
return NoPermissions ( w , r , user )
2017-09-13 15:40:49 +00:00
}
topicName := html . EscapeString ( r . PostFormValue ( "topic-name" ) )
content := html . EscapeString ( preparseMessage ( r . PostFormValue ( "topic-content" ) ) )
ipaddress , _ , err := net . SplitHostPort ( r . RemoteAddr )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad IP" , w , r , user )
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
tid , err := topics . Create ( fid , topicName , content , user . ID , ipaddress )
2017-09-13 15:40:49 +00:00
if err != nil {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
switch err {
case ErrNoRows :
2017-10-30 09:57:08 +00:00
return LocalError ( "Something went wrong, perhaps the forum got deleted?" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
case ErrNoTitle :
2017-10-30 09:57:08 +00:00
return LocalError ( "This topic doesn't have a title" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
case ErrNoBody :
2017-10-30 09:57:08 +00:00
return LocalError ( "This topic doesn't have a body" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
default :
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . addSubscription . Exec ( user . ID , tid , "topic" )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
err = user . increasePostStats ( wordCount ( content ) , true )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// Handle the file attachments
2017-10-12 03:24:14 +00:00
// TODO: Stop duplicating this code
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if user . Perms . UploadFiles {
2017-10-12 03:24:14 +00:00
files , ok := r . MultipartForm . File [ "upload_files" ]
if ok {
if len ( files ) > 5 {
2017-10-30 09:57:08 +00:00
return LocalError ( "You can't attach more than five files" , w , r , user )
2017-10-12 03:24:14 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
2017-10-12 03:24:14 +00:00
for _ , file := range files {
2017-10-30 09:57:08 +00:00
if dev . DebugMode {
log . Print ( "file.Filename " , file . Filename )
}
2017-10-12 03:24:14 +00:00
extarr := strings . Split ( file . Filename , "." )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if len ( extarr ) < 2 {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad file" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
ext := extarr [ len ( extarr ) - 1 ]
// TODO: Can we do this without a regex?
reg , err := regexp . Compile ( "[^A-Za-z0-9]+" )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad file extension" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
ext = strings . ToLower ( reg . ReplaceAllString ( ext , "" ) )
if ! allowedFileExts . Contains ( ext ) {
2017-10-30 09:57:08 +00:00
return LocalError ( "You're not allowed to upload files with this extension" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
2017-10-12 03:24:14 +00:00
infile , err := file . Open ( )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
defer infile . Close ( )
hasher := sha256 . New ( )
_ , err = io . Copy ( hasher , infile )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed [Hashing Failed]" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
infile . Close ( )
checksum := hex . EncodeToString ( hasher . Sum ( nil ) )
filename := checksum + "." + ext
outfile , err := os . Create ( "." + "/attachs/" + filename )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed [File Creation Failed]" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
defer outfile . Close ( )
2017-10-12 03:24:14 +00:00
infile , err = file . Open ( )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
defer infile . Close ( )
_ , err = io . Copy ( outfile , infile )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed [Copy Failed]" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . addAttachment . Exec ( fid , "forums" , tid , "topics" , user . ID , filename )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
}
}
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
http . Redirect ( w , r , "/topic/" + strconv . Itoa ( tid ) , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeCreateReply ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
2017-10-12 03:24:14 +00:00
// TODO: Reduce this to 1MB for attachments for each file?
if r . ContentLength > int64 ( config . MaxRequestSize ) {
size , unit := convertByteUnit ( float64 ( config . MaxRequestSize ) )
2017-10-30 09:57:08 +00:00
return CustomError ( "Your attachments are too big. Your files need to be smaller than " + strconv . Itoa ( int ( size ) ) + unit + "." , http . StatusExpectationFailed , "Error" , w , r , user )
2017-10-12 03:24:14 +00:00
}
r . Body = http . MaxBytesReader ( w , r . Body , int64 ( config . MaxRequestSize ) )
err := r . ParseMultipartForm ( int64 ( megabyte ) )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Unable to parse the form" , w , r , user )
2017-09-13 15:40:49 +00:00
}
2017-10-12 03:24:14 +00:00
2017-09-13 15:40:49 +00:00
tid , err := strconv . Atoi ( r . PostFormValue ( "tid" ) )
if err != nil {
2017-10-30 09:57:08 +00:00
return PreError ( "Failed to convert the Topic ID" , w , r )
2017-09-13 15:40:49 +00:00
}
2017-09-15 22:20:01 +00:00
topic , err := topics . Get ( tid )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return PreError ( "Couldn't find the parent topic" , w , r )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
// TODO: Add hooks to make use of headerLite
2017-10-30 09:57:08 +00:00
_ , ferr := SimpleForumUserCheck ( w , r , & user , topic . ParentID )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
2017-09-15 22:20:01 +00:00
if ! user . Perms . ViewTopic || ! user . Perms . CreateReply {
2017-10-30 09:57:08 +00:00
return NoPermissions ( w , r , user )
2017-09-13 15:40:49 +00:00
}
2017-10-12 03:24:14 +00:00
// Handle the file attachments
// TODO: Stop duplicating this code
if user . Perms . UploadFiles {
files , ok := r . MultipartForm . File [ "upload_files" ]
if ok {
if len ( files ) > 5 {
2017-10-30 09:57:08 +00:00
return LocalError ( "You can't attach more than five files" , w , r , user )
2017-10-12 03:24:14 +00:00
}
for _ , file := range files {
log . Print ( "file.Filename " , file . Filename )
extarr := strings . Split ( file . Filename , "." )
if len ( extarr ) < 2 {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad file" , w , r , user )
2017-10-12 03:24:14 +00:00
}
ext := extarr [ len ( extarr ) - 1 ]
// TODO: Can we do this without a regex?
reg , err := regexp . Compile ( "[^A-Za-z0-9]+" )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad file extension" , w , r , user )
2017-10-12 03:24:14 +00:00
}
ext = strings . ToLower ( reg . ReplaceAllString ( ext , "" ) )
if ! allowedFileExts . Contains ( ext ) {
2017-10-30 09:57:08 +00:00
return LocalError ( "You're not allowed to upload files with this extension" , w , r , user )
2017-10-12 03:24:14 +00:00
}
infile , err := file . Open ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed" , w , r , user )
2017-10-12 03:24:14 +00:00
}
defer infile . Close ( )
hasher := sha256 . New ( )
_ , err = io . Copy ( hasher , infile )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed [Hashing Failed]" , w , r , user )
2017-10-12 03:24:14 +00:00
}
infile . Close ( )
checksum := hex . EncodeToString ( hasher . Sum ( nil ) )
filename := checksum + "." + ext
outfile , err := os . Create ( "." + "/attachs/" + filename )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed [File Creation Failed]" , w , r , user )
2017-10-12 03:24:14 +00:00
}
defer outfile . Close ( )
infile , err = file . Open ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed" , w , r , user )
2017-10-12 03:24:14 +00:00
}
defer infile . Close ( )
_ , err = io . Copy ( outfile , infile )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed [Copy Failed]" , w , r , user )
2017-10-12 03:24:14 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . addAttachment . Exec ( topic . ParentID , "forums" , tid , "replies" , user . ID , filename )
2017-10-12 03:24:14 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-10-12 03:24:14 +00:00
}
}
}
}
2017-09-13 15:40:49 +00:00
content := preparseMessage ( html . EscapeString ( r . PostFormValue ( "reply-content" ) ) )
ipaddress , _ , err := net . SplitHostPort ( r . RemoteAddr )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad IP" , w , r , user )
2017-09-13 15:40:49 +00:00
}
2017-10-12 03:24:14 +00:00
_ , err = rstore . Create ( tid , content , ipaddress , topic . ParentID , user . ID )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-09-28 22:16:34 +00:00
err = fstore . UpdateLastTopic ( tid , user . ID , topic . ParentID )
2017-09-13 15:40:49 +00:00
if err != nil && err != ErrNoRows {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
res , err := stmts . addActivity . Exec ( user . ID , topic . CreatedBy , "reply" , "topic" , tid )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
lastID , err := res . LastInsertId ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . notifyWatchers . Exec ( lastID )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
// Alert the subscribers about this post without blocking this post from being posted
if enableWebsockets {
go notifyWatchers ( lastID )
}
http . Redirect ( w , r , "/topic/" + strconv . Itoa ( tid ) , http . StatusSeeOther )
2017-10-12 03:24:14 +00:00
wcount := wordCount ( content )
2017-09-13 15:40:49 +00:00
err = user . increasePostStats ( wcount , false )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-12 03:24:14 +00:00
// TODO: Refactor this
2017-10-30 09:57:08 +00:00
func routeLikeTopic ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
2017-09-13 15:40:49 +00:00
err := r . ParseForm ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return PreError ( "Bad Form" , w , r )
2017-09-13 15:40:49 +00:00
}
tid , err := strconv . Atoi ( r . URL . Path [ len ( "/topic/like/submit/" ) : ] )
if err != nil {
2017-10-30 09:57:08 +00:00
return PreError ( "Topic IDs can only ever be numbers." , w , r )
2017-09-13 15:40:49 +00:00
}
2017-09-15 22:20:01 +00:00
topic , err := topics . Get ( tid )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return PreError ( "The requested topic doesn't exist." , w , r )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
// TODO: Add hooks to make use of headerLite
2017-10-30 09:57:08 +00:00
_ , ferr := SimpleForumUserCheck ( w , r , & user , topic . ParentID )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
if ! user . Perms . ViewTopic || ! user . Perms . LikeItem {
2017-10-30 09:57:08 +00:00
return NoPermissions ( w , r , user )
2017-09-13 15:40:49 +00:00
}
if topic . CreatedBy == user . ID {
2017-10-30 09:57:08 +00:00
return LocalError ( "You can't like your own topics" , w , r , user )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
err = stmts . hasLikedTopic . QueryRow ( user . ID , tid ) . Scan ( & tid )
2017-09-13 15:40:49 +00:00
if err != nil && err != ErrNoRows {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
} else if err != ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "You already liked this!" , w , r , user )
2017-09-13 15:40:49 +00:00
}
2017-09-15 22:20:01 +00:00
_ , err = users . Get ( topic . CreatedBy )
2017-09-13 15:40:49 +00:00
if err != nil && err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "The target user doesn't exist" , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
score := 1
2017-11-05 09:55:34 +00:00
_ , err = stmts . createLike . Exec ( score , tid , "topics" , user . ID )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . addLikesToTopic . Exec ( 1 , tid )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
res , err := stmts . addActivity . Exec ( user . ID , topic . CreatedBy , "like" , "topic" , tid )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
lastID , err := res . LastInsertId ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . notifyOne . Exec ( topic . CreatedBy , lastID )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
// Live alerts, if the poster is online and WebSockets is enabled
_ = wsHub . pushAlert ( topic . CreatedBy , int ( lastID ) , "like" , "topic" , user . ID , topic . CreatedBy , tid )
2017-09-22 02:21:17 +00:00
// Flush the topic out of the cache
tcache , ok := topics . ( TopicCache )
if ok {
tcache . CacheRemove ( tid )
2017-09-13 15:40:49 +00:00
}
http . Redirect ( w , r , "/topic/" + strconv . Itoa ( tid ) , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeReplyLikeSubmit ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
2017-09-13 15:40:49 +00:00
err := r . ParseForm ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return PreError ( "Bad Form" , w , r )
2017-09-13 15:40:49 +00:00
}
rid , err := strconv . Atoi ( r . URL . Path [ len ( "/reply/like/submit/" ) : ] )
if err != nil {
2017-10-30 09:57:08 +00:00
return PreError ( "The provided Reply ID is not a valid number." , w , r )
2017-09-13 15:40:49 +00:00
}
2017-10-12 03:24:14 +00:00
reply , err := rstore . Get ( rid )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return PreError ( "You can't like something which doesn't exist!" , w , r )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
var fid int
2017-11-05 09:55:34 +00:00
err = stmts . getTopicFID . QueryRow ( reply . ParentID ) . Scan ( & fid )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return PreError ( "The parent topic doesn't exist." , w , r )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
// TODO: Add hooks to make use of headerLite
2017-10-30 09:57:08 +00:00
_ , ferr := SimpleForumUserCheck ( w , r , & user , fid )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
if ! user . Perms . ViewTopic || ! user . Perms . LikeItem {
2017-10-30 09:57:08 +00:00
return NoPermissions ( w , r , user )
2017-09-13 15:40:49 +00:00
}
if reply . CreatedBy == user . ID {
2017-10-30 09:57:08 +00:00
return LocalError ( "You can't like your own replies" , w , r , user )
2017-09-13 15:40:49 +00:00
}
2017-09-15 22:20:01 +00:00
_ , err = users . Get ( reply . CreatedBy )
2017-09-13 15:40:49 +00:00
if err != nil && err != ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "The target user doesn't exist" , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-10-12 03:24:14 +00:00
err = reply . Like ( user . ID )
if err == ErrAlreadyLiked {
2017-10-30 09:57:08 +00:00
return LocalError ( "You've already liked this!" , w , r , user )
2017-10-12 03:24:14 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
res , err := stmts . addActivity . Exec ( user . ID , reply . CreatedBy , "like" , "post" , rid )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
lastID , err := res . LastInsertId ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . notifyOne . Exec ( reply . CreatedBy , lastID )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
// Live alerts, if the poster is online and WebSockets is enabled
_ = wsHub . pushAlert ( reply . CreatedBy , int ( lastID ) , "like" , "post" , user . ID , reply . CreatedBy , rid )
http . Redirect ( w , r , "/topic/" + strconv . Itoa ( reply . ParentID ) , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeProfileReplyCreate ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
2017-09-15 22:20:01 +00:00
if ! user . Perms . ViewTopic || ! user . Perms . CreateReply {
2017-10-30 09:57:08 +00:00
return NoPermissions ( w , r , user )
2017-09-13 15:40:49 +00:00
}
err := r . ParseForm ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad Form" , w , r , user )
2017-09-13 15:40:49 +00:00
}
uid , err := strconv . Atoi ( r . PostFormValue ( "uid" ) )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Invalid UID" , w , r , user )
2017-09-13 15:40:49 +00:00
}
ipaddress , _ , err := net . SplitHostPort ( r . RemoteAddr )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad IP" , w , r , user )
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
content := html . EscapeString ( preparseMessage ( r . PostFormValue ( "reply-content" ) ) )
2017-11-05 09:55:34 +00:00
_ , err = stmts . createProfileReply . Exec ( uid , content , parseMessage ( content , 0 , "" ) , user . ID , ipaddress )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
var userName string
2017-11-05 09:55:34 +00:00
err = stmts . getUserName . QueryRow ( uid ) . Scan ( & userName )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "The profile you're trying to post on doesn't exist." , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
http . Redirect ( w , r , "/user/" + strconv . Itoa ( uid ) , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeReportSubmit ( w http . ResponseWriter , r * http . Request , user User , sitemID string ) RouteError {
2017-09-13 15:40:49 +00:00
if ! user . Loggedin {
2017-10-30 09:57:08 +00:00
return LoginRequired ( w , r , user )
2017-09-13 15:40:49 +00:00
}
if user . IsBanned {
2017-10-30 09:57:08 +00:00
return Banned ( w , r , user )
2017-09-13 15:40:49 +00:00
}
err := r . ParseForm ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad Form" , w , r , user )
2017-09-13 15:40:49 +00:00
}
if r . FormValue ( "session" ) != user . Session {
2017-10-30 09:57:08 +00:00
return SecurityError ( w , r , user )
2017-09-13 15:40:49 +00:00
}
itemID , err := strconv . Atoi ( sitemID )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad ID" , w , r , user )
2017-09-13 15:40:49 +00:00
}
itemType := r . FormValue ( "type" )
var fid = 1
var title , content string
if itemType == "reply" {
2017-10-12 03:24:14 +00:00
reply , err := rstore . Get ( itemID )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "We were unable to find the reported post" , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-09-15 22:20:01 +00:00
topic , err := topics . Get ( reply . ParentID )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "We weren't able to find the topic the reported post is supposed to be in" , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
title = "Reply: " + topic . Title
content = reply . Content + "\n\nOriginal Post: #rid-" + strconv . Itoa ( itemID )
} else if itemType == "user-reply" {
2017-10-12 03:24:14 +00:00
userReply , err := prstore . Get ( itemID )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "We weren't able to find the reported post" , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
err = stmts . getUserName . QueryRow ( userReply . ParentID ) . Scan ( & title )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "We weren't able to find the profile the reported post is supposed to be on" , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
title = "Profile: " + title
content = userReply . Content + "\n\nOriginal Post: @" + strconv . Itoa ( userReply . ParentID )
} else if itemType == "topic" {
2017-11-05 09:55:34 +00:00
err = stmts . getTopicBasic . QueryRow ( itemID ) . Scan ( & title , & content )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return NotFound ( w , r )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
title = "Topic: " + title
content = content + "\n\nOriginal Post: #tid-" + strconv . Itoa ( itemID )
} else {
if vhooks [ "report_preassign" ] != nil {
runVhookNoreturn ( "report_preassign" , & itemID , & itemType )
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
// Don't try to guess the type
2017-10-30 09:57:08 +00:00
return LocalError ( "Unknown type" , w , r , user )
2017-09-13 15:40:49 +00:00
}
var count int
2017-11-05 09:55:34 +00:00
rows , err := stmts . reportExists . Query ( itemType + "_" + strconv . Itoa ( itemID ) )
2017-09-13 15:40:49 +00:00
if err != nil && err != ErrNoRows {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
for rows . Next ( ) {
err = rows . Scan ( & count )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
}
if count != 0 {
2017-10-30 09:57:08 +00:00
return LocalError ( "Someone has already reported this!" , w , r , user )
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// TODO: Repost attachments in the reports forum, so that the mods can see them
2017-09-18 17:03:52 +00:00
// ? - Can we do this via the TopicStore?
2017-11-05 09:55:34 +00:00
res , err := stmts . createReport . Exec ( title , content , parseMessage ( content , 0 , "" ) , user . ID , user . ID , itemType + "_" + strconv . Itoa ( itemID ) )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
lastID , err := res . LastInsertId ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
2017-11-06 04:02:35 +00:00
err = fstore . AddTopic ( int ( lastID ) , user . ID , fid )
2017-09-13 15:40:49 +00:00
if err != nil && err != ErrNoRows {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
http . Redirect ( w , r , "/topic/" + strconv . FormatInt ( lastID , 10 ) , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeAccountOwnEditCritical ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
headerVars , ferr := UserCheck ( w , r , & user )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
pi := Page { "Edit Password" , user , headerVars , tList , nil }
if preRenderHooks [ "pre_render_account_own_edit_critical" ] != nil {
if runPreRenderHook ( "pre_render_account_own_edit_critical" , w , r , & user , & pi ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err := templates . ExecuteTemplate ( w , "account-own-edit.html" , pi )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeAccountOwnEditCriticalSubmit ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
headerVars , ferr := UserCheck ( w , r , & user )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
err := r . ParseForm ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad Form" , w , r , user )
2017-09-13 15:40:49 +00:00
}
var realPassword , salt string
currentPassword := r . PostFormValue ( "account-current-password" )
newPassword := r . PostFormValue ( "account-new-password" )
confirmPassword := r . PostFormValue ( "account-confirm-password" )
2017-11-05 09:55:34 +00:00
err = stmts . getPassword . QueryRow ( user . ID ) . Scan ( & realPassword , & salt )
2017-09-13 15:40:49 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return LocalError ( "Your account no longer exists." , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
err = CheckPassword ( realPassword , currentPassword , salt )
if err == ErrMismatchedHashAndPassword {
2017-10-30 09:57:08 +00:00
return LocalError ( "That's not the correct password." , w , r , user )
2017-09-13 15:40:49 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
if newPassword != confirmPassword {
2017-10-30 09:57:08 +00:00
return LocalError ( "The two passwords don't match." , w , r , user )
2017-09-13 15:40:49 +00:00
}
SetPassword ( user . ID , newPassword )
// Log the user out as a safety precaution
auth . ForceLogout ( user . ID )
headerVars . NoticeList = append ( headerVars . NoticeList , "Your password was successfully updated" )
pi := Page { "Edit Password" , user , headerVars , tList , nil }
if preRenderHooks [ "pre_render_account_own_edit_critical" ] != nil {
if runPreRenderHook ( "pre_render_account_own_edit_critical" , w , r , & user , & pi ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err = templates . ExecuteTemplate ( w , "account-own-edit.html" , pi )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeAccountOwnEditAvatar ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
headerVars , ferr := UserCheck ( w , r , & user )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
2017-09-13 15:40:49 +00:00
pi := Page { "Edit Avatar" , user , headerVars , tList , nil }
if preRenderHooks [ "pre_render_account_own_edit_avatar" ] != nil {
if runPreRenderHook ( "pre_render_account_own_edit_avatar" , w , r , & user , & pi ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err := templates . ExecuteTemplate ( w , "account-own-edit-avatar.html" , pi )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeAccountOwnEditAvatarSubmit ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
2017-09-13 15:40:49 +00:00
if r . ContentLength > int64 ( config . MaxRequestSize ) {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
size , unit := convertByteUnit ( float64 ( config . MaxRequestSize ) )
2017-10-30 09:57:08 +00:00
return CustomError ( "Your avatar's too big. Avatars must be smaller than " + strconv . Itoa ( int ( size ) ) + unit , http . StatusExpectationFailed , "Error" , w , r , user )
2017-09-13 15:40:49 +00:00
}
r . Body = http . MaxBytesReader ( w , r . Body , int64 ( config . MaxRequestSize ) )
2017-10-30 09:57:08 +00:00
headerVars , ferr := UserCheck ( w , r , & user )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
err := r . ParseMultipartForm ( int64 ( megabyte ) )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed" , w , r , user )
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
var filename , ext string
2017-09-13 15:40:49 +00:00
for _ , fheaders := range r . MultipartForm . File {
for _ , hdr := range fheaders {
infile , err := hdr . Open ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed" , w , r , user )
2017-09-13 15:40:49 +00:00
}
defer infile . Close ( )
// We don't want multiple files
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// TODO: Check the length of r.MultipartForm.File and error rather than doing this x.x
2017-09-13 15:40:49 +00:00
if filename != "" {
if filename != hdr . Filename {
os . Remove ( "./uploads/avatar_" + strconv . Itoa ( user . ID ) + "." + ext )
2017-10-30 09:57:08 +00:00
return LocalError ( "You may only upload one avatar" , w , r , user )
2017-09-13 15:40:49 +00:00
}
} else {
filename = hdr . Filename
}
if ext == "" {
extarr := strings . Split ( hdr . Filename , "." )
if len ( extarr ) < 2 {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad file" , w , r , user )
2017-09-13 15:40:49 +00:00
}
ext = extarr [ len ( extarr ) - 1 ]
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// TODO: Can we do this without a regex?
2017-09-13 15:40:49 +00:00
reg , err := regexp . Compile ( "[^A-Za-z0-9]+" )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad file extension" , w , r , user )
2017-09-13 15:40:49 +00:00
}
ext = reg . ReplaceAllString ( ext , "" )
ext = strings . ToLower ( ext )
}
outfile , err := os . Create ( "./uploads/avatar_" + strconv . Itoa ( user . ID ) + "." + ext )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed [File Creation Failed]" , w , r , user )
2017-09-13 15:40:49 +00:00
}
defer outfile . Close ( )
_ , err = io . Copy ( outfile , infile )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Upload failed [Copy Failed]" , w , r , user )
2017-09-13 15:40:49 +00:00
}
}
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
err = user . ChangeAvatar ( "." + ext )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
user . Avatar = "/uploads/avatar_" + strconv . Itoa ( user . ID ) + "." + ext
headerVars . NoticeList = append ( headerVars . NoticeList , "Your avatar was successfully updated" )
pi := Page { "Edit Avatar" , user , headerVars , tList , nil }
if preRenderHooks [ "pre_render_account_own_edit_avatar" ] != nil {
if runPreRenderHook ( "pre_render_account_own_edit_avatar" , w , r , & user , & pi ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err = templates . ExecuteTemplate ( w , "account-own-edit-avatar.html" , pi )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeAccountOwnEditUsername ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
headerVars , ferr := UserCheck ( w , r , & user )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
2017-09-13 15:40:49 +00:00
pi := Page { "Edit Username" , user , headerVars , tList , user . Name }
if preRenderHooks [ "pre_render_account_own_edit_username" ] != nil {
if runPreRenderHook ( "pre_render_account_own_edit_username" , w , r , & user , & pi ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err := templates . ExecuteTemplate ( w , "account-own-edit-username.html" , pi )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeAccountOwnEditUsernameSubmit ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
headerVars , ferr := UserCheck ( w , r , & user )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
err := r . ParseForm ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad Form" , w , r , user )
2017-09-13 15:40:49 +00:00
}
newUsername := html . EscapeString ( r . PostFormValue ( "account-new-username" ) )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
err = user . ChangeName ( newUsername )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "Unable to change the username. Does someone else already have this name?" , w , r , user )
2017-09-13 15:40:49 +00:00
}
user . Name = newUsername
headerVars . NoticeList = append ( headerVars . NoticeList , "Your username was successfully updated" )
pi := Page { "Edit Username" , user , headerVars , tList , nil }
if preRenderHooks [ "pre_render_account_own_edit_username" ] != nil {
if runPreRenderHook ( "pre_render_account_own_edit_username" , w , r , & user , & pi ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err = templates . ExecuteTemplate ( w , "account-own-edit-username.html" , pi )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeAccountOwnEditEmail ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
headerVars , ferr := UserCheck ( w , r , & user )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
email := Email { UserID : user . ID }
var emailList [ ] interface { }
2017-11-05 09:55:34 +00:00
rows , err := stmts . getEmailsByUser . Query ( user . ID )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-11-05 09:55:34 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
defer rows . Close ( )
for rows . Next ( ) {
err := rows . Scan ( & email . Email , & email . Validated , & email . Token )
if err != nil {
2017-11-05 09:55:34 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
if email . Email == user . Email {
email . Primary = true
}
emailList = append ( emailList , email )
}
err = rows . Err ( )
if err != nil {
2017-11-05 09:55:34 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
// Was this site migrated from another forum software? Most of them don't have multiple emails for a single user.
// This also applies when the admin switches site.EnableEmails on after having it off for a while.
if len ( emailList ) == 0 {
email . Email = user . Email
email . Validated = false
email . Primary = true
emailList = append ( emailList , email )
}
if ! site . EnableEmails {
headerVars . NoticeList = append ( headerVars . NoticeList , "The mail system is currently disabled." )
}
pi := Page { "Email Manager" , user , headerVars , emailList , nil }
if preRenderHooks [ "pre_render_account_own_edit_email" ] != nil {
if runPreRenderHook ( "pre_render_account_own_edit_email" , w , r , & user , & pi ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err = templates . ExecuteTemplate ( w , "account-own-edit-email.html" , pi )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
func routeAccountOwnEditEmailTokenSubmit ( w http . ResponseWriter , r * http . Request , user User , token string ) RouteError {
2017-10-30 09:57:08 +00:00
headerVars , ferr := UserCheck ( w , r , & user )
if ferr != nil {
return ferr
2017-09-13 15:40:49 +00:00
}
email := Email { UserID : user . ID }
targetEmail := Email { UserID : user . ID }
var emailList [ ] interface { }
2017-11-05 09:55:34 +00:00
rows , err := stmts . getEmailsByUser . Query ( user . ID )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
defer rows . Close ( )
for rows . Next ( ) {
err := rows . Scan ( & email . Email , & email . Validated , & email . Token )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
if email . Email == user . Email {
email . Primary = true
}
if email . Token == token {
targetEmail = email
}
emailList = append ( emailList , email )
}
err = rows . Err ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
if len ( emailList ) == 0 {
2017-10-30 09:57:08 +00:00
return LocalError ( "A verification email was never sent for you!" , w , r , user )
2017-09-13 15:40:49 +00:00
}
if targetEmail . Token == "" {
2017-10-30 09:57:08 +00:00
return LocalError ( "That's not a valid token!" , w , r , user )
2017-09-13 15:40:49 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . verifyEmail . Exec ( user . Email )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
// If Email Activation is on, then activate the account while we're here
if headerVars . Settings [ "activation_type" ] == 2 {
2017-11-05 09:55:34 +00:00
_ , err = stmts . activateUser . Exec ( user . ID )
2017-09-13 15:40:49 +00:00
if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
2017-09-13 15:40:49 +00:00
}
}
if ! site . EnableEmails {
headerVars . NoticeList = append ( headerVars . NoticeList , "The mail system is currently disabled." )
}
headerVars . NoticeList = append ( headerVars . NoticeList , "Your email was successfully verified" )
pi := Page { "Email Manager" , user , headerVars , emailList , nil }
if preRenderHooks [ "pre_render_account_own_edit_email" ] != nil {
if runPreRenderHook ( "pre_render_account_own_edit_email" , w , r , & user , & pi ) {
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
}
2017-10-30 09:57:08 +00:00
err = templates . ExecuteTemplate ( w , "account-own-edit-email.html" , pi )
if err != nil {
return InternalError ( err , w , r )
}
return nil
2017-09-13 15:40:49 +00:00
}
2017-10-30 09:57:08 +00:00
func routeLogout ( w http . ResponseWriter , r * http . Request , user User ) RouteError {
2017-09-13 15:40:49 +00:00
if ! user . Loggedin {
2017-10-30 09:57:08 +00:00
return LocalError ( "You can't logout without logging in first." , w , r , user )
2017-09-13 15:40:49 +00:00
}
auth . Logout ( w , user . ID )
http . Redirect ( w , r , "/" , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-09-13 15:40:49 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
2017-10-30 09:57:08 +00:00
func routeShowAttachment ( w http . ResponseWriter , r * http . Request , user User , filename string ) RouteError {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
err := r . ParseForm ( )
if err != nil {
2017-10-30 09:57:08 +00:00
return PreError ( "Bad Form" , w , r )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
filename = Stripslashes ( filename )
var ext = filepath . Ext ( "./attachs/" + filename )
//log.Print("ext ", ext)
//log.Print("filename ", filename)
if ! allowedFileExts . Contains ( strings . TrimPrefix ( ext , "." ) ) {
2017-10-30 09:57:08 +00:00
return LocalError ( "Bad extension" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
sectionID , err := strconv . Atoi ( r . FormValue ( "sectionID" ) )
if err != nil {
2017-10-30 09:57:08 +00:00
return LocalError ( "The sectionID is not an integer" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
var sectionTable = r . FormValue ( "sectionType" )
var originTable string
var originID , uploadedBy int
2017-11-05 09:55:34 +00:00
err = stmts . getAttachment . QueryRow ( filename , sectionID , sectionTable ) . Scan ( & sectionID , & sectionTable , & originID , & originTable , & uploadedBy , & filename )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if err == ErrNoRows {
2017-10-30 09:57:08 +00:00
return NotFound ( w , r )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
} else if err != nil {
2017-10-30 09:57:08 +00:00
return InternalError ( err , w , r )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
if sectionTable == "forums" {
2017-10-30 09:57:08 +00:00
_ , ferr := SimpleForumUserCheck ( w , r , & user , sectionID )
if ferr != nil {
return ferr
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
if ! user . Perms . ViewTopic {
2017-10-30 09:57:08 +00:00
return NoPermissions ( w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
} else {
2017-10-30 09:57:08 +00:00
return LocalError ( "Unknown section" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
if originTable != "topics" && originTable != "replies" {
2017-10-30 09:57:08 +00:00
return LocalError ( "Unknown origin" , w , r , user )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
// TODO: Fix the problem where non-existent files aren't greeted with custom 404s on ServeFile()'s side
http . ServeFile ( w , r , "./attachs/" + filename )
2017-10-30 09:57:08 +00:00
return nil
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}