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