mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-06 11:39:42 -06:00
[server] Allow not sending email for invite and password reset
This commit is contained in:
@@ -2,6 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -72,21 +73,22 @@ func setupInviteCommand() *cobra.Command {
|
||||
}
|
||||
}
|
||||
|
||||
if b, _ := cmd.Flags().GetBool("no-email"); !b {
|
||||
if err := mail.SendWelcomeEmail(u); err != nil {
|
||||
return errors.New("unable to send welcome email: " + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("unable to create user: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("User created")
|
||||
if mail.SendWelcomeEmail(u) != nil {
|
||||
fmt.Println("unable to send email: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringP("name", "n", "", "Full Name")
|
||||
cmd.Flags().StringP("base-dir", "b", "/home", "Base directory for home")
|
||||
cmd.Flags().BoolP("no-create-home", "M", false, "Do not make home directory")
|
||||
cmd.Flags().Bool("no-email", false, "Do not send email")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -25,11 +25,19 @@ func setupPasswordResetCommand() *cobra.Command {
|
||||
} else if token, err := manager.CreateResetToken(user); err != nil {
|
||||
fmt.Println("unable to create reset token: " + err.Error())
|
||||
os.Exit(1)
|
||||
} else if err := mail.SendPasswordResetEmail(user, token); err != nil {
|
||||
fmt.Println("unable to send email: " + err.Error())
|
||||
os.Exit(1)
|
||||
} else {
|
||||
if b, _ := cmd.Flags().GetBool("no-email"); b {
|
||||
fmt.Println("Created password reset token: " + token)
|
||||
} else {
|
||||
if err := mail.SendPasswordResetEmail(user, token); err != nil {
|
||||
fmt.Println("unable to send email: " + err.Error())
|
||||
fmt.Println("Use --no-email print the reset token instead instad of sending it by email")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
cmd.Flags().Bool("no-email", false, "Do not send email")
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user