2017-11-11 04:06:16 +00:00
package common
import (
2019-03-03 04:00:04 +00:00
"crypto/tls"
2019-03-03 05:31:13 +00:00
"fmt"
"net/mail"
2017-11-11 04:06:16 +00:00
"net/smtp"
2019-10-30 06:41:05 +00:00
"strings"
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
2019-10-30 06:41:05 +00:00
p "github.com/Azareal/Gosora/common/phrases"
2017-11-11 04:06:16 +00:00
)
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func SendActivationEmail ( username , email , token string ) error {
2019-09-29 04:56:39 +00:00
schema := "http"
2019-11-04 11:55:52 +00:00
if Config . SslSchema {
2017-11-11 04:06:16 +00:00
schema += "s"
}
// TODO: Move these to the phrase system
2019-10-30 06:41:05 +00:00
subject := "Account Activation - " + Site . Name
2019-03-11 08:47:45 +00:00
msg := "Dear " + username + ", to complete your registration on our forums, we need you to validate your email, so that we can confirm that this email actually belongs to you.\n\nClick on the following link to do so. " + schema + "://" + Site . URL + "/user/edit/token/" + token + "\n\nIf you haven't created an account here, then please feel free to ignore this email.\nWe're sorry for the inconvenience this may have caused."
2017-11-11 04:06:16 +00:00
return SendEmail ( email , subject , msg )
}
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func SendValidationEmail ( username , email , token string ) error {
2019-10-30 06:41:05 +00:00
schema := "http"
2019-11-04 11:55:52 +00:00
if Config . SslSchema {
2019-10-30 06:41:05 +00:00
schema += "s"
}
r := func ( body * string ) func ( name , val string ) {
return func ( name , val string ) {
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
* body = strings . Replace ( * body , "{{" + name + "}}" , val , - 1 )
2019-10-30 06:41:05 +00:00
}
}
subject := p . GetAccountPhrase ( "ValidateEmailSubject" )
r1 := r ( & subject )
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
r1 ( "name" , Site . Name )
2019-10-30 06:41:05 +00:00
body := p . GetAccountPhrase ( "ValidateEmailBody" )
r2 := r ( & body )
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
r2 ( "username" , username )
r2 ( "schema" , schema )
r2 ( "url" , Site . URL )
r2 ( "token" , token )
2019-10-30 06:41:05 +00:00
return SendEmail ( email , subject , body )
}
2017-11-11 04:06:16 +00:00
// TODO: Refactor this
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func SendEmail ( email , subject , msg string ) ( err error ) {
2017-11-11 04:06:16 +00:00
// This hook is useful for plugin_sendmail or for testing tools. Possibly to hook it into some sort of mail server?
2018-10-21 13:54:32 +00:00
ret , hasHook := GetHookTable ( ) . VhookNeedHook ( "email_send_intercept" , email , subject , msg )
if hasHook {
2019-03-03 03:19:32 +00:00
return ret . ( error )
2017-11-11 04:06:16 +00:00
}
2019-03-03 05:31:13 +00:00
from := mail . Address { "" , Site . Email }
to := mail . Address { "" , email }
headers := make ( map [ string ] string )
headers [ "From" ] = from . String ( )
headers [ "To" ] = to . String ( )
headers [ "Subject" ] = subject
body := ""
for k , v := range headers {
body += fmt . Sprintf ( "%s: %s\r\n" , k , v )
}
body += "\r\n" + msg
2017-11-11 04:06:16 +00:00
2019-03-03 04:00:04 +00:00
var c * smtp . Client
if Config . SMTPEnableTLS {
tlsconfig := & tls . Config {
InsecureSkipVerify : true ,
ServerName : Config . SMTPServer ,
}
conn , err := tls . Dial ( "tcp" , Config . SMTPServer + ":" + Config . SMTPPort , tlsconfig )
if err != nil {
2019-03-03 04:49:03 +00:00
LogWarning ( err )
2019-03-03 04:00:04 +00:00
return err
}
c , err = smtp . NewClient ( conn , Config . SMTPServer )
} else {
c , err = smtp . Dial ( Config . SMTPServer + ":" + Config . SMTPPort )
2019-10-30 06:41:05 +00:00
}
if err != nil {
LogWarning ( err )
return err
2017-11-11 04:06:16 +00:00
}
if Config . SMTPUsername != "" {
auth := smtp . PlainAuth ( "" , Config . SMTPUsername , Config . SMTPPassword , Config . SMTPServer )
2019-03-03 04:00:04 +00:00
err = c . Auth ( auth )
2017-11-11 04:06:16 +00:00
if err != nil {
2019-03-03 04:49:03 +00:00
LogWarning ( err )
2019-03-03 03:19:32 +00:00
return err
2017-11-11 04:06:16 +00:00
}
}
2019-10-30 06:41:05 +00:00
if err = c . Mail ( from . Address ) ; err != nil {
2019-03-03 04:49:03 +00:00
LogWarning ( err )
2019-03-03 03:19:32 +00:00
return err
2017-11-11 04:06:16 +00:00
}
2019-10-30 06:41:05 +00:00
if err = c . Rcpt ( to . Address ) ; err != nil {
2019-03-03 04:49:03 +00:00
LogWarning ( err )
2019-03-03 03:19:32 +00:00
return err
2017-11-11 04:06:16 +00:00
}
2019-03-03 04:00:04 +00:00
w , err := c . Data ( )
2017-11-11 04:06:16 +00:00
if err != nil {
2019-03-03 04:49:03 +00:00
LogWarning ( err )
2019-03-03 03:19:32 +00:00
return err
2017-11-11 04:06:16 +00:00
}
2019-03-03 04:00:04 +00:00
_ , err = w . Write ( [ ] byte ( body ) )
2017-11-11 04:06:16 +00:00
if err != nil {
2019-03-03 04:49:03 +00:00
LogWarning ( err )
2019-03-03 03:19:32 +00:00
return err
2017-11-11 04:06:16 +00:00
}
2019-10-30 06:41:05 +00:00
if err = w . Close ( ) ; err != nil {
2019-03-03 04:49:03 +00:00
LogWarning ( err )
2019-03-03 03:19:32 +00:00
return err
2017-11-11 04:06:16 +00:00
}
2019-10-30 06:41:05 +00:00
if err = c . Quit ( ) ; err != nil {
2019-03-03 04:49:03 +00:00
LogWarning ( err )
return err
}
return nil
2017-11-11 04:06:16 +00:00
}