Compare commits

..

No commits in common. "6af4d494afda6fe92942f1a4667ce1d3d7ab490e" and "2bc87ea594bece14e14a74e51dd157647731a59d" have entirely different histories.

View file

@ -14,9 +14,7 @@
// createuser -id 1000 [-first-name Test] [-last-name User] [-username testuser] -phone "15550001234" // createuser -id 1000 [-first-name Test] [-last-name User] [-username testuser] -phone "15550001234"
// createuser -id 1000 [-first-name Test] [-last-name User] [-username testuser] -email "test@example.com" // createuser -id 1000 [-first-name Test] [-last-name User] [-username testuser] -email "test@example.com"
// //
// Exactly one of -phone or -email is required: login resolves the account by // -phone and -email are mutually exclusive: an email-signup account never
// one of them, so an account with neither can never be signed in to. They are
// mutually exclusive because an email-signup account never
// stores the address in users.phone directly (see internal/domain/emailphone.go) // stores the address in users.phone directly (see internal/domain/emailphone.go)
// -- it gets a synthetic "888"-prefixed display phone instead (the same one // -- it gets a synthetic "888"-prefixed display phone instead (the same one
// assignEmailSignupDisplayPhone hands a real email-signup account), with the // assignEmailSignupDisplayPhone hands a real email-signup account), with the
@ -60,8 +58,8 @@ func main() {
firstName := flag.String("first-name", "Test", "first name") firstName := flag.String("first-name", "Test", "first name")
lastName := flag.String("last-name", "", "last name") lastName := flag.String("last-name", "", "last name")
username := flag.String("username", "", "username, without @ (optional)") username := flag.String("username", "", "username, without @ (optional)")
phone := flag.String("phone", "", "phone number (exactly one of -phone or -email is required)") phone := flag.String("phone", "", "phone number (optional; mutually exclusive with -email)")
email := flag.String("email", "", "email address for an email-signup account (exactly one of -phone or -email is required)") email := flag.String("email", "", "email address for an email-signup account (optional; mutually exclusive with -phone)")
force := flag.Bool("force", false, "skip the reserved-id / sequence-collision safety checks") force := flag.Bool("force", false, "skip the reserved-id / sequence-collision safety checks")
flag.Parse() flag.Parse()
@ -69,10 +67,6 @@ func main() {
fmt.Fprintln(os.Stderr, "createuser: -id is required and must be positive") fmt.Fprintln(os.Stderr, "createuser: -id is required and must be positive")
os.Exit(2) os.Exit(2)
} }
if *phone == "" && *email == "" {
fmt.Fprintln(os.Stderr, "createuser: one of -phone or -email is required - an account with neither cannot be logged in to")
os.Exit(2)
}
if *phone != "" && *email != "" { if *phone != "" && *email != "" {
fmt.Fprintln(os.Stderr, "createuser: -phone and -email are mutually exclusive") fmt.Fprintln(os.Stderr, "createuser: -phone and -email are mutually exclusive")
os.Exit(2) os.Exit(2)
@ -122,8 +116,8 @@ func main() {
} }
// phone/username/signup_email all sit under partial unique indexes that // phone/username/signup_email all sit under partial unique indexes that
// exclude '', so a blank username or (for a phone account) signup_email // exclude '', so leaving any of them blank never collides with another
// never collides with another blank-valued account. // blank-valued account.
row := pool.QueryRow(ctx, ` row := pool.QueryRow(ctx, `
INSERT INTO users (id, access_hash, phone, signup_email, first_name, last_name, username, country_code) INSERT INTO users (id, access_hash, phone, signup_email, first_name, last_name, username, country_code)
VALUES ($1, $2, $3, $4, $5, $6, $7, '') VALUES ($1, $2, $3, $4, $5, $6, $7, '')