Skip to content

Commit

Permalink
verifyEmailSuccessPath config setting
Browse files Browse the repository at this point in the history
resolves #1998
  • Loading branch information
brandonkelly committed Mar 21, 2019
1 parent 8979f41 commit e1bd028
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

## Unreleased

### Added
- Added the `verifyEmailSuccessPath` config setting.
- Added `craft\config\GeneralConfig::getVerifyEmailSuccessPath()`.

### Changed
- Users without access to the Control Panel are now redirected according to the `verifyEmailSuccessPath` config setting after verifying a new email address. ([#1998](https://github.com/craftcms/cms/issues/1998))
- The `_includes/forms/text` Control Panel template now supports passing `autocorrect: false` and `autocapitalize: false`, to disable autocorrect and auto-capitalization on iOS devices.
- iOS autocorrect and auto-capitalization has been disabled for all core “Handle” and “Slug” fields in the Control Panel. ([#4009](https://github.com/craftcms/cms/issues/4009))

Expand Down
22 changes: 22 additions & 0 deletions docs/config/config-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2499,5 +2499,27 @@ See [craft\helpers\ConfigHelper::durationInSeconds()](https://docs.craftcms.com/



### `verifyEmailSuccessPath`

Allowed types

: `mixed`

Default value

: `''`

Defined by

: [GeneralConfig::$verifyEmailSuccessPath](api:craft\config\GeneralConfig::$verifyEmailSuccessPath)



The URI that users without access to the Control Panel should be redirected to after verifying a new email address.

See [craft\helpers\ConfigHelper::localizedValue()](https://docs.craftcms.com/api/v3/craft-helpers-confighelper.html#method-localizedvalue) for a list of supported value types.




<!-- END SETTINGS -->
19 changes: 19 additions & 0 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,13 @@ class GeneralConfig extends BaseObject
* See [[ConfigHelper::durationInSeconds()]] for a list of supported value types.
*/
public $verificationCodeDuration = 86400;
/**
* @var mixed The URI that users without access to the Control Panel should be redirected to after verifying a new email address.
*
* See [[ConfigHelper::localizedValue()]] for a list of supported value types.
* @see getVerifyEmailSuccessPath()
*/
public $verifyEmailSuccessPath = '';

/**
* @var array Stores any custom config settings
Expand Down Expand Up @@ -970,6 +977,18 @@ public function getActivateAccountSuccessPath(string $siteHandle = null): string
return ConfigHelper::localizedValue($this->activateAccountSuccessPath, $siteHandle);
}

/**
* Returns the localized Verify Email Success Path value.
*
* @param string|null $siteHandle The site handle the value should be defined for. Defaults to the current site.
* @return string
* @see verifyEmailSuccessPath
*/
public function getVerifyEmailSuccessPath(string $siteHandle = null): string
{
return ConfigHelper::localizedValue($this->verifyEmailSuccessPath, $siteHandle);
}

/**
* Returns the localized Invalid User Token Path value.
*
Expand Down
28 changes: 26 additions & 2 deletions src/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,19 @@ public function actionVerifyEmail(): Response
}
}

$url = UrlHelper::url('');
return $this->redirect($url);
// If they're logged in, give them a success notice
if (!Craft::$app->getUser()->getIsGuest()) {
Craft::$app->getSession()->setNotice(Craft::t('app', 'Email verified'));
}

if ($userIsPending) {
// They were just activated, so treat this as an activation request
if (($response = $this->_onAfterActivateUser($user)) !== null) {
return $response;
}
}

return $this->_redirectUserToCp($user) ?? $this->_redirectUserAfterEmailVerification($user);
}

/**
Expand Down Expand Up @@ -2033,6 +2044,19 @@ private function _redirectUserAfterAccountActivation(User $user): Response
return $this->redirectToPostedUrl($user, $url);
}

/**
* Redirect the browser after a user has verified their new email address
*
* @param User $user The user that just verified their email
* @return Response
*/
private function _redirectUserAfterEmailVerification(User $user): Response
{
$verifyEmailSuccessPath = Craft::$app->getConfig()->getGeneral()->getVerifyEmailSuccessPath();
$url = UrlHelper::siteUrl($verifyEmailSuccessPath);
return $this->redirectToPostedUrl($user, $url);
}

/**
* @param string[] $errors
* @param string|null $loginName
Expand Down

0 comments on commit e1bd028

Please sign in to comment.