mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2026-01-01 04:08:45 -05:00
feat(uesrprofile): email requirement and validation
This commit is contained in:
@@ -137,6 +137,8 @@ export class User {
|
||||
@UpdateDateColumn()
|
||||
public updatedAt: Date;
|
||||
|
||||
public warnings: string[] = [];
|
||||
|
||||
constructor(init?: Partial<User>) {
|
||||
Object.assign(this, init);
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ interface FullPublicSettings extends PublicSettings {
|
||||
enablePushRegistration: boolean;
|
||||
locale: string;
|
||||
emailEnabled: boolean;
|
||||
userEmailRequired: boolean;
|
||||
newPlexLogin: boolean;
|
||||
}
|
||||
|
||||
@@ -159,6 +160,7 @@ export interface NotificationAgentSlack extends NotificationAgentConfig {
|
||||
|
||||
export interface NotificationAgentEmail extends NotificationAgentConfig {
|
||||
options: {
|
||||
userEmailRequired: boolean;
|
||||
emailFrom: string;
|
||||
smtpHost: string;
|
||||
smtpPort: number;
|
||||
@@ -335,6 +337,7 @@ class Settings {
|
||||
email: {
|
||||
enabled: false,
|
||||
options: {
|
||||
userEmailRequired: false,
|
||||
emailFrom: '',
|
||||
smtpHost: '',
|
||||
smtpPort: 587,
|
||||
@@ -529,6 +532,8 @@ class Settings {
|
||||
enablePushRegistration: this.data.notifications.agents.webpush.enabled,
|
||||
locale: this.data.main.locale,
|
||||
emailEnabled: this.data.notifications.agents.email.enabled,
|
||||
userEmailRequired:
|
||||
this.data.notifications.agents.email.options.userEmailRequired,
|
||||
newPlexLogin: this.data.main.newPlexLogin,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Permission } from '../lib/permissions';
|
||||
import { getSettings } from '../lib/settings';
|
||||
import logger from '../logger';
|
||||
import { isAuthenticated } from '../middleware/auth';
|
||||
import * as EmailValidator from 'email-validator';
|
||||
|
||||
const authRoutes = Router();
|
||||
|
||||
@@ -24,6 +25,16 @@ authRoutes.get('/me', isAuthenticated(), async (req, res) => {
|
||||
where: { id: req.user.id },
|
||||
});
|
||||
|
||||
// check if email is required in settings and if user has an valid email
|
||||
const settings = await getSettings();
|
||||
if (
|
||||
settings.notifications.agents.email.options.userEmailRequired &&
|
||||
!EmailValidator.validate(user.email)
|
||||
) {
|
||||
user.warnings.push('userEmailRequired');
|
||||
logger.warn(`User ${user.username} has no valid email address`);
|
||||
}
|
||||
|
||||
return res.status(200).json(user);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user