fixed bug with auto-join communities
This commit is contained in:
@@ -774,20 +774,19 @@ func AmGetCommunityAccessLevel(ctx context.Context, uid int32, commid int32) (ui
|
|||||||
/* AmAutoJoinCommunities joins the specified user to any communities they're not yet a part of.
|
/* AmAutoJoinCommunities joins the specified user to any communities they're not yet a part of.
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ctx - Standard Go context value.
|
* ctx - Standard Go context value.
|
||||||
* tx - The current transaction to be used for database access.
|
|
||||||
* user - The user to be auto-joined to communities.
|
* user - The user to be auto-joined to communities.
|
||||||
* Returns:
|
* Returns:
|
||||||
* Standard Go error status.
|
* Standard Go error status.
|
||||||
*/
|
*/
|
||||||
func AmAutoJoinCommunities(ctx context.Context, tx *sqlx.Tx, user *User) error {
|
func AmAutoJoinCommunities(ctx context.Context, user *User) error {
|
||||||
// get list of current communities
|
// get list of current communities
|
||||||
var current []int32 = make([]int32, 0)
|
var current []int32 = make([]int32, 0)
|
||||||
if err := tx.SelectContext(ctx, ¤t, "SELECT commid FROM commmember WHERE uid = ?", user.Uid); err != nil {
|
if err := amdb.SelectContext(ctx, ¤t, "SELECT commid FROM commmember WHERE uid = ?", user.Uid); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for candidate communities
|
// look for candidate communities
|
||||||
rows, err := tx.QueryxContext(ctx, `SELECT m.commid, m.locked FROM users u, communities c, commmember m
|
rows, err := amdb.QueryxContext(ctx, `SELECT m.commid, m.locked FROM users u, communities c, commmember m
|
||||||
WHERE m.uid = u.uid AND m.commid = c.commid AND u.is_anon = 1 AND c.join_lvl <= ?`, user.BaseLevel)
|
WHERE m.uid = u.uid AND m.commid = c.commid AND u.is_anon = 1 AND c.join_lvl <= ?`, user.BaseLevel)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
@@ -799,7 +798,7 @@ func AmAutoJoinCommunities(ctx context.Context, tx *sqlx.Tx, user *User) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !slices.Contains(current, cid) {
|
if !slices.Contains(current, cid) {
|
||||||
_, err = tx.ExecContext(ctx, "INSERT INTO commmember (commid, uid, granted_lvl, locked) VALUES (?, ?, ?, ?)",
|
_, err = amdb.ExecContext(ctx, "INSERT INTO commmember (commid, uid, granted_lvl, locked) VALUES (?, ?, ?, ?)",
|
||||||
cid, user.Uid, grantLevel, lock)
|
cid, user.Uid, grantLevel, lock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
|
|||||||
+9
-19
@@ -242,13 +242,6 @@ func (u *User) ConfirmEMailAddress(ctx context.Context, confnum int32, remoteIP
|
|||||||
defer func() {
|
defer func() {
|
||||||
AmStoreAudit(ar)
|
AmStoreAudit(ar)
|
||||||
}()
|
}()
|
||||||
success := false
|
|
||||||
tx := amdb.MustBegin()
|
|
||||||
defer func() {
|
|
||||||
if !success {
|
|
||||||
tx.Rollback()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
log.Debugf("ConfirmEMailAddress for UID %d", u.Uid)
|
log.Debugf("ConfirmEMailAddress for UID %d", u.Uid)
|
||||||
u.Mutex.Lock()
|
u.Mutex.Lock()
|
||||||
@@ -262,18 +255,15 @@ func (u *User) ConfirmEMailAddress(ctx context.Context, confnum int32, remoteIP
|
|||||||
ar = AmNewAudit(AuditVerifyEmailFail, u.Uid, remoteIP, "Invalid confirmation number")
|
ar = AmNewAudit(AuditVerifyEmailFail, u.Uid, remoteIP, "Invalid confirmation number")
|
||||||
return errors.New("confirmation number is incorrect. Please try again")
|
return errors.New("confirmation number is incorrect. Please try again")
|
||||||
}
|
}
|
||||||
_, err := tx.ExecContext(ctx, "UPDATE users SET verify_email = 1, base_lvl = ? WHERE uid = ?",
|
_, err := amdb.ExecContext(ctx, "UPDATE users SET verify_email = 1, base_lvl = ? WHERE uid = ?",
|
||||||
AmDefaultRole("Global.AfterVerify").Level(), u.Uid)
|
AmDefaultRole("Global.AfterVerify").Level(), u.Uid)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
u.VerifyEMail = true
|
u.VerifyEMail = true
|
||||||
u.BaseLevel = AmDefaultRole("Global.AfterVerify").Level()
|
u.BaseLevel = AmDefaultRole("Global.AfterVerify").Level()
|
||||||
if err = AmAutoJoinCommunities(ctx, tx, u); err == nil {
|
if err = AmAutoJoinCommunities(ctx, u); err == nil {
|
||||||
if err = tx.Commit(); err == nil {
|
|
||||||
success = true
|
|
||||||
ar = AmNewAudit(AuditVerifyEmailOK, u.Uid, remoteIP)
|
ar = AmNewAudit(AuditVerifyEmailOK, u.Uid, remoteIP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,18 +755,18 @@ func AmCreateNewUser(ctx context.Context, username string, password string, remi
|
|||||||
tx.ExecContext(ctx, "UNLOCK TABLES;")
|
tx.ExecContext(ctx, "UNLOCK TABLES;")
|
||||||
unlock = false
|
unlock = false
|
||||||
|
|
||||||
// auto-join communities
|
|
||||||
if err = AmAutoJoinCommunities(ctx, tx, user); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: copy conference hotlists
|
|
||||||
|
|
||||||
if err = tx.Commit(); err != nil {
|
if err = tx.Commit(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
success = true
|
success = true
|
||||||
|
|
||||||
|
// auto-join communities
|
||||||
|
if err = AmAutoJoinCommunities(ctx, user); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: copy conference hotlists
|
||||||
|
|
||||||
// operation was a success - add an audit record
|
// operation was a success - add an audit record
|
||||||
ar = AmNewAudit(AuditAccountCreated, user.Uid, remoteIP)
|
ar = AmNewAudit(AuditAccountCreated, user.Uid, remoteIP)
|
||||||
return user, nil
|
return user, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user