diff --git a/jam-ui/cypress/e2e/auth/forgot-password.cy.js b/jam-ui/cypress/e2e/auth/forgot-password.cy.js
new file mode 100644
index 000000000..4997a8870
--- /dev/null
+++ b/jam-ui/cypress/e2e/auth/forgot-password.cy.js
@@ -0,0 +1,54 @@
+///
+
+import makeFakeUser from '../../factories/user';
+
+describe('forgot password', () => {
+ beforeEach(() => {
+ const currentUser = makeFakeUser({
+ email: 'sam@example.com'
+ });
+ cy.clearCookie('remeber_token');
+ });
+
+ it('redirects to forgot password page', () => {
+ cy.visit('/');
+ cy.url().should('include', '/authentication/basic/login');
+ cy.get('a')
+ .contains('Forgot password?')
+ .click();
+ cy.url().should('include', '/authentication/basic/forget-password');
+ cy.get('h5').contains('Forgot Your Password');
+ });
+
+ describe('validate forgot password form', () => {
+ beforeEach(() => {
+ cy.visit('/authentication/basic/forget-password');
+ cy.get('[data-testid=email]').clear();
+ cy.get('[data-testid=submit]').should('be.disabled');
+ });
+
+ //invalid email format
+ it('invalid email format', () => {
+ cy.get('[data-testid=email]').type('invalid-email-format@example');
+ cy.get('[data-testid=submit]').click();
+ cy.url().should('not.include', /\/authentication\/basic\/confirm-mail?\S+/);
+ });
+
+ //valid email format but non-existing
+ it('valid email format but non-existing', () => {
+ cy.get('[data-testid=email]').type('valid-email-format@example.com');
+ cy.get('[data-testid=submit]').click();
+ cy.url().should('not.include', /\/authentication\/basic\/confirm-mail?\S+/);
+ });
+
+ //valid and existing email
+ it('valid and existing email', () => {
+ cy.get('[data-testid=email]').type('nuwan@jamkazam.com');
+ cy.get('[data-testid=submit]').click();
+ cy.wait(3000);
+ cy.contains('Please check your email!');
+ cy.url().should('match', /\S+authentication\/basic\/confirm-mail?\S+/);
+ cy.contains('An email has been sent to nuwan@jamkazam.com.')
+ });
+ });
+});
diff --git a/jam-ui/cypress/e2e/auth/login.cy.js b/jam-ui/cypress/e2e/auth/login.cy.js
index 4b6fac0c1..7cf1808f1 100644
--- a/jam-ui/cypress/e2e/auth/login.cy.js
+++ b/jam-ui/cypress/e2e/auth/login.cy.js
@@ -30,9 +30,9 @@ function submitLogin(){
describe('Unauthenticated users redirect to login page', () => {
it('redirects to login page', () => {
cy.clearCookie('remeber_token')
- cy.visit('/friends')
+ cy.visit('/')
cy.url().should('include', '/authentication/basic/login')
- cy.contains('Sign in')
+ cy.contains('Sign In')
})
})
@@ -81,4 +81,13 @@ describe('Login page', () => {
})
+describe('Forget password page', () => {
+ it('submit forget password form', () => {
+ cy.visit('/authentication/basic/forget-password')
+ cy.get('[data-testid=email]').type('peter@example.com')
+ cy.get('[data-testid=submit]').click()
+ cy.contains('An email is sent')
+ })
+})
+
diff --git a/jam-ui/src/components/auth/ConfirmMailContent.js b/jam-ui/src/components/auth/ConfirmMailContent.js
index d08db3d4c..a1a05a3ef 100644
--- a/jam-ui/src/components/auth/ConfirmMailContent.js
+++ b/jam-ui/src/components/auth/ConfirmMailContent.js
@@ -4,20 +4,30 @@ import { Button } from 'reactstrap';
import { Link } from 'react-router-dom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import envelope from '../../assets/img/illustrations/envelope.png';
+import { useBrowserQuery } from '../../context/BrowserQuery';
+import { useTranslation } from 'react-i18next';
-const ConfirmMailContent = ({ layout, titleTag: TitleTag }) => (
-
-
- Please check your email!
-
- An email has been sent to you. Please click on the included link to reset your password.
-
-
-
-);
+const ConfirmMailContent = ({ layout, titleTag: TitleTag }) => {
+ const queryString = useBrowserQuery();
+ const { t } = useTranslation('auth');
+
+ const toWording = queryString && queryString.get('email') ? queryString.get('email') : t('confirmEmailContent.toYou');
+
+ return (
+
+
+ {t('confirmEmailContent.title')}
+ {t('confirmEmailContent.description_1')} {toWording}. {t('confirmEmailContent.description_2')}
+
+ {t('confirmEmailContent.description_3')}
+
+
+
+ );
+};
ConfirmMailContent.propTypes = {
layout: PropTypes.string,
diff --git a/jam-ui/src/components/auth/ForgetPasswordForm.js b/jam-ui/src/components/auth/ForgetPasswordForm.js
index c1a08800b..97c82379e 100644
--- a/jam-ui/src/components/auth/ForgetPasswordForm.js
+++ b/jam-ui/src/components/auth/ForgetPasswordForm.js
@@ -5,12 +5,15 @@ import { toast } from 'react-toastify';
import { Button, Form, FormGroup, Input } from 'reactstrap';
import withRedirect from '../../hoc/withRedirect';
import { requstResetForgotPassword } from '../../helpers/rest';
+import { useTranslation } from 'react-i18next';
const ForgetPasswordForm = ({ setRedirect, setRedirectUrl, layout }) => {
// State
const [email, setEmail] = useState('');
const [submitting, setSubmitting] = useState(false);
+ const { t } = useTranslation('auth');
+
// Handler
const handleSubmit = e => {
e.preventDefault();
@@ -29,35 +32,32 @@ const ForgetPasswordForm = ({ setRedirect, setRedirectUrl, layout }) => {
};
useEffect(() => {
- setRedirectUrl(`/authentication/${layout}/confirm-mail`);
- }, [setRedirectUrl, layout]);
+ setRedirectUrl(`/authentication/${layout}/confirm-mail?email=${email}`);
+ }, [setRedirectUrl, layout, email]);
return (
);
};
diff --git a/jam-ui/src/components/auth/LoginForm.js b/jam-ui/src/components/auth/LoginForm.js
index 104fe6f6a..e68a24504 100644
--- a/jam-ui/src/components/auth/LoginForm.js
+++ b/jam-ui/src/components/auth/LoginForm.js
@@ -8,6 +8,7 @@ import SocialAuthButtons from './SocialAuthButtons';
import withRedirect from '../../hoc/withRedirect';
import { useAuth } from '../../context/UserAuth';
//import { signin } from '../../services/authService';
+import { useTranslation } from 'react-i18next';
const LoginForm = ({ setRedirect, hasLabel, layout }) => {
// State
@@ -17,6 +18,8 @@ const LoginForm = ({ setRedirect, hasLabel, layout }) => {
const [isDisabled, setIsDisabled] = useState(true);
const history = useHistory();
+
+ const { t } = useTranslation('auth');
const location = useLocation();
let { from } = location.state || { from: { pathname: "/" } };
@@ -27,8 +30,8 @@ const LoginForm = ({ setRedirect, hasLabel, layout }) => {
const handleSubmit = async e => {
e.preventDefault();
const credentials = {email, password}
+ setIsDisabled(true);
const user = await login(credentials)
- console.log("handleSubmit", user);
if(user){
setCurrentUser(user)
//localStorage.setItem('user', user)
@@ -40,7 +43,7 @@ const LoginForm = ({ setRedirect, hasLabel, layout }) => {
}else{
toast.error("Incorrect email or password");
}
-
+ setIsDisabled(false);
};
useEffect(() => {
@@ -50,20 +53,20 @@ const LoginForm = ({ setRedirect, hasLabel, layout }) => {
return (