2018-05-27 09:36:35 +00:00
|
|
|
package common
|
|
|
|
|
2019-07-26 22:26:52 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
|
|
)
|
2018-05-27 09:36:35 +00:00
|
|
|
|
|
|
|
var Emails EmailStore
|
|
|
|
|
2019-10-30 06:41:05 +00:00
|
|
|
type Email struct {
|
|
|
|
UserID int
|
|
|
|
Email string
|
|
|
|
Validated bool
|
|
|
|
Primary bool
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
2018-05-27 09:36:35 +00:00
|
|
|
type EmailStore interface {
|
2019-10-30 06:41:05 +00:00
|
|
|
// TODO: Add an autoincrement key
|
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
|
|
|
Get(u *User, email string) (Email, error)
|
|
|
|
GetEmailsByUser(u *User) (emails []Email, err error)
|
2019-10-30 06:41:05 +00:00
|
|
|
Add(uid int, email, token string) error
|
|
|
|
Delete(uid int, email string) error
|
2018-05-27 09:36:35 +00:00
|
|
|
VerifyEmail(email string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultEmailStore struct {
|
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
|
|
|
get *sql.Stmt
|
2018-05-27 09:36:35 +00:00
|
|
|
getEmailsByUser *sql.Stmt
|
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
|
|
|
add *sql.Stmt
|
|
|
|
delete *sql.Stmt
|
2018-05-27 09:36:35 +00:00
|
|
|
verifyEmail *sql.Stmt
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultEmailStore(acc *qgen.Accumulator) (*DefaultEmailStore, error) {
|
2019-10-30 06:41:05 +00:00
|
|
|
e := "emails"
|
2018-05-27 09:36:35 +00:00
|
|
|
return &DefaultEmailStore{
|
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
|
|
|
get: acc.Select(e).Columns("email,validated,token").Where("uid=? AND email=?").Prepare(),
|
2019-10-30 06:41:05 +00:00
|
|
|
getEmailsByUser: acc.Select(e).Columns("email,validated,token").Where("uid=?").Prepare(),
|
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
|
|
|
add: acc.Insert(e).Columns("uid,email,validated,token").Fields("?,?,?,?").Prepare(),
|
|
|
|
delete: acc.Delete(e).Where("uid=? AND email=?").Prepare(),
|
2018-05-27 09:36:35 +00:00
|
|
|
|
|
|
|
// Need to fix this: Empty string isn't working, it gets set to 1 instead x.x -- Has this been fixed?
|
2019-10-30 06:41:05 +00:00
|
|
|
verifyEmail: acc.Update(e).Set("validated=1,token=''").Where("email=?").Prepare(),
|
2018-05-27 09:36:35 +00:00
|
|
|
}, acc.FirstError()
|
|
|
|
}
|
|
|
|
|
2019-10-30 06:41:05 +00:00
|
|
|
func (s *DefaultEmailStore) Get(user *User, email string) (Email, error) {
|
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
|
|
|
e := Email{UserID: user.ID, Primary: email != "" && user.Email == email}
|
2019-10-30 06:41:05 +00:00
|
|
|
err := s.get.QueryRow(user.ID, email).Scan(&e.Email, &e.Validated, &e.Token)
|
|
|
|
return e, err
|
|
|
|
}
|
|
|
|
|
2019-07-26 22:26:52 +00:00
|
|
|
func (s *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err error) {
|
2019-09-29 04:56:39 +00:00
|
|
|
e := Email{UserID: user.ID}
|
2019-07-26 22:26:52 +00:00
|
|
|
rows, err := s.getEmailsByUser.Query(user.ID)
|
2018-05-27 09:36:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return emails, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
2019-09-29 04:56:39 +00:00
|
|
|
err := rows.Scan(&e.Email, &e.Validated, &e.Token)
|
2018-05-27 09:36:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return emails, err
|
|
|
|
}
|
2019-09-29 04:56:39 +00:00
|
|
|
if e.Email == user.Email {
|
|
|
|
e.Primary = true
|
2018-05-27 09:36:35 +00:00
|
|
|
}
|
2019-09-29 04:56:39 +00:00
|
|
|
emails = append(emails, e)
|
2018-05-27 09:36:35 +00:00
|
|
|
}
|
|
|
|
return emails, rows.Err()
|
|
|
|
}
|
|
|
|
|
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 (s *DefaultEmailStore) Add(uid int, email, token string) error {
|
2020-06-16 02:07:21 +00:00
|
|
|
email = CanonEmail(SanitiseSingleLine(email))
|
2019-10-30 06:41:05 +00:00
|
|
|
_, err := s.add.Exec(uid, email, 0, token)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DefaultEmailStore) Delete(uid int, email string) error {
|
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
|
|
|
_, err := s.delete.Exec(uid, email)
|
2019-10-30 06:41:05 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-26 22:26:52 +00:00
|
|
|
func (s *DefaultEmailStore) VerifyEmail(email string) error {
|
2020-06-16 02:07:21 +00:00
|
|
|
email = CanonEmail(SanitiseSingleLine(email))
|
2019-07-26 22:26:52 +00:00
|
|
|
_, err := s.verifyEmail.Exec(email)
|
2018-05-27 09:36:35 +00:00
|
|
|
return err
|
|
|
|
}
|