fix(password recovery): Add default from mail parameter

This commit is contained in:
smizrahi
2024-01-09 10:28:41 +01:00
parent 153f444c3f
commit 26b14671f5
4 changed files with 27 additions and 5 deletions

View File

@@ -808,6 +808,9 @@ specified as an array of dictionaries.
|S |SOGoPasswordRecoveryDomains
|List of domains where password recovery is enabled, for example `(example.org, example.net)`. If empty array `()`, disabled for all domains. If not set, enabled for all domains.
|D |SOGoPasswordRecoveryFrom
|From email when `SOGoPasswordRecoverySecondaryEmail` is set and no user domain is defined - otherwise it will use noreply@foo.bar where foo.bar is the selected user domain. Default value is `noreply@domain.com`.
|U |SOGoPasswordRecoveryMode
|User password recovery mode. Values can be `Disabled`, `SecretQuestion` or `SecondaryEmail`.

View File

@@ -99,6 +99,8 @@
- (BOOL) createIdentitiesDisabled;
- (NSString *) passwordRecoveryFrom;
@end
#endif /* SOGODOMAINDEFAULTS_H */

View File

@@ -448,4 +448,16 @@
return [self boolForKey: @"SOGoCreateIdentitiesDisabled"];
}
- (NSString *) passwordRecoveryFrom
{
NSString *emailFrom;
emailFrom = [self stringForKey: @"SOGoPasswordRecoveryFrom"];
if (!emailFrom)
emailFrom = @"noreply@domain.com"; // Default email from when no domain set
return emailFrom;
}
@end

View File

@@ -869,11 +869,18 @@ static const NSString *kJwtKey = @"jwt";
if (!mode && jwtToken) {
response = [self _standardDefaultAction];
} else if ([mode isEqualToString: SOGoPasswordRecoverySecondaryEmail]) {
if (mailDomain && username) {
if (username) {
ownerUser = [SOGoUser userWithLogin: username];
dd = [ownerUser domainDefaults];
// Email recovery
// Create email from
fromEmail = [NSString stringWithFormat:@"noreply@%@", mailDomain];
if (mailDomain) {
fromEmail = [NSString stringWithFormat:@"noreply@%@", mailDomain];
} else {
fromEmail = [dd passwordRecoveryFrom];
}
// Get password recovery email
info = [um contactInfosForUserWithUIDorEmail: username];
@@ -887,8 +894,6 @@ static const NSString *kJwtKey = @"jwt";
jwtToken = [um generateAndSavePasswordRecoveryTokenWithUid: uid username: username domain: domain];
// Send mail
ownerUser = [SOGoUser userWithLogin: username];
dd = [ownerUser domainDefaults];
mailer = [SOGoMailer mailerWithDomainDefaults: dd];
url = [NSString stringWithFormat:@"%@%@?token=%@"
, [[request headers] objectForKey:@"origin"]
@@ -922,7 +927,7 @@ static const NSString *kJwtKey = @"jwt";
andString: @"Invalid configuration for email password recovery"];
}
} else {
[self logWithFormat: @"No user domain found for password recovery"];
[self logWithFormat: @"No user found for password recovery"];
response = [self responseWithStatus: 403
andString: @"Invalid configuration for email password recovery"];
}