feat: complete registration invitation and auth redesign
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
//go:build mysql
|
||||
// +build mysql
|
||||
|
||||
package mysql
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
t "github.com/tinode/chat/server/store/types"
|
||||
)
|
||||
|
||||
func (a *adapter) RegistrationSMSEnabled() (bool, error) {
|
||||
db := a.registryDB
|
||||
if db == nil {
|
||||
db = a.db
|
||||
}
|
||||
if db == nil {
|
||||
return true, t.ErrInternal
|
||||
}
|
||||
ctx, cancel := a.getContext()
|
||||
if cancel != nil {
|
||||
defer cancel()
|
||||
}
|
||||
var value string
|
||||
err := db.GetContext(ctx, &value, `SELECT value FROM hg_sys_config
|
||||
WHERE `+"`group`"+`='im' AND `+"`key`"+`='register_sms_enabled' AND status=1 LIMIT 1`)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return true, t.ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
value = strings.TrimSpace(strings.ToLower(value))
|
||||
switch value {
|
||||
case "1", "true":
|
||||
return true, nil
|
||||
case "0", "false":
|
||||
return false, nil
|
||||
default:
|
||||
if parsed, parseErr := strconv.ParseBool(value); parseErr == nil {
|
||||
return parsed, nil
|
||||
}
|
||||
return true, t.ErrMalformed
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user