Skip to content

Commit

Permalink
Merge pull request #1458 from dhis2/DHIS2-18376/verify-email-warning
Browse files Browse the repository at this point in the history
feat: verify email warning
  • Loading branch information
Chisomchima authored Jan 8, 2025
2 parents 09566de + 5ac9cf2 commit 30db2f2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
11 changes: 9 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-11-21T08:20:57.566Z\n"
"PO-Revision-Date: 2024-11-21T08:20:57.566Z\n"
"POT-Creation-Date: 2025-01-07T11:04:56.155Z\n"
"PO-Revision-Date: 2025-01-07T11:04:56.155Z\n"

msgid "Never"
msgstr "Never"
Expand Down Expand Up @@ -376,6 +376,13 @@ msgstr "Failed to send email verification link."
msgid "Verify Email"
msgstr "Verify Email"

msgid ""
"Your email is not verified. Please verify your email to continue using the "
"system."
msgstr ""
"Your email is not verified. Please verify your email to continue using the "
"system."

msgid "Manage personal access tokens"
msgstr "Manage personal access tokens"

Expand Down
15 changes: 14 additions & 1 deletion src/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ class AppRouter extends Component {
return { baseUrl, apiVersion }
}

getDefaultRedirect() {
const enforceVerifiedEmail =
this.props.d2?.system?.settings?.settings?.enforceVerifiedEmail
const emailVerified = this.props.d2.currentUser.emailVerified

// Redirect to the profile page if email is unverified and the setting is enforced
return enforceVerifiedEmail && !emailVerified
? '/profile'
: '/viewProfile'
}

render() {
const defaultRedirect = this.getDefaultRedirect()

return (
<DataProvider {...this.getDataProviderProps()}>
<CssVariables colors spacers />
Expand Down Expand Up @@ -77,7 +90,7 @@ class AppRouter extends Component {
component={PersonalAccessTokens}
/>
<Route path="aboutPage" component={AboutPage} />
<Redirect from="/" to="/viewProfile" />
<Redirect from="/" to={defaultRedirect} />
</Route>
</Router>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/layout/FormFields.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import userSettingsKeyMapping from '../userSettingsMapping.js'
import AvatarEditor from './AvatarEditor.component.js'
import AppTheme from './theme.js'
import { VerifyEmail } from './VerifyEmail.component.js'
import { VerifyEmailWarning } from './VerifyEmailWarning.js'

const styles = {
header: {
Expand Down Expand Up @@ -387,6 +388,9 @@ class FormFields extends Component {
<div className="content-area">
<div style={styles.header}>{this.props.pageLabel}</div>
<form autoComplete="off">
{this.context?.d2 && (
<VerifyEmailWarning config={this.context.d2} />
)}
{this.renderFields(this.props.fieldKeys)}
</form>
</div>
Expand Down
39 changes: 39 additions & 0 deletions src/layout/VerifyEmailWarning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import i18n from '@dhis2/d2-i18n'
import { NoticeBox } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'

export function VerifyEmailWarning({ config }) {
const enforceVerifiedEmail =
config.system?.settings?.settings?.enforceVerifiedEmail || false
const emailVerified = config.currentUser?.emailVerified || false

if (enforceVerifiedEmail && !emailVerified) {
return (
<div className="noticebox-wrapper">
<NoticeBox warning>
{i18n.t(
'Your email is not verified. Please verify your email to continue using the system.'
)}
</NoticeBox>
</div>
)
}

return null
}

VerifyEmailWarning.propTypes = {
config: PropTypes.shape({
currentUser: PropTypes.shape({
emailVerified: PropTypes.bool,
}),
system: PropTypes.shape({
settings: PropTypes.shape({
settings: PropTypes.shape({
enforceVerifiedEmail: PropTypes.bool,
}),
}),
}),
}).isRequired,
}
5 changes: 5 additions & 0 deletions src/layout/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ html, body {
margin: 0;
}

.noticebox-wrapper {
margin-inline-end: 15px;
}


.info-cell-name {
color: #777;
font-size: 12pt;
Expand Down

1 comment on commit 30db2f2

@dhis2-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.