Skip to content

Commit 26dba52

Browse files
authored
Merge pull request #142 from SailingSteve/steveStaffClientFeb7-132pm
Google User Password Reset now working
2 parents 362c78f + 5c69d03 commit 26dba52

6 files changed

Lines changed: 48 additions & 47 deletions

File tree

package-lock.json

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"d3-zoom": "^3.0.0",
108108
"dayjs": "^1.11.13",
109109
"depcheck": "^1.4.7",
110+
"file-saver": "^2.0.5",
110111
"fs-extra": "^10.0.0",
111112
"glob": "^9.0.0",
112113
"https-browserify": "^1.0.0",
@@ -129,6 +130,7 @@
129130
"react-google-recaptcha-v3": "^1.10.1",
130131
"react-gtm-module": "^2.0.11",
131132
"react-helmet-async": "^2.0.5",
133+
"react-papaparse": "^4.4.0",
132134
"react-phone-number-input": "^3.4.3",
133135
"react-router": "^7.1.1",
134136
"react-text-truncate": "^0.19.0",
@@ -138,10 +140,7 @@
138140
"styled-components": "^6.1.15",
139141
"topojson-client": "^3.1.0",
140142
"use-file-picker": "^2.1.2",
141-
"validator": "^13.12.0",
142-
"react-papaparse": "^4.4.0",
143-
"file-saver": "^2.0.5",
144-
"react-router-dom": "^7.1.1"
143+
"validator": "^13.12.0"
145144
},
146145
"bugs": {
147146
"url": "https://github.com/wevote/weconnect/issues"

src/js/components/Navigation/HeaderBar.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { withStyles } from '@mui/styles';
44
import { useQueryClient } from '@tanstack/react-query';
55
import PropTypes from 'prop-types';
66
import React, { useEffect, useMemo, useState } from 'react';
7-
import { useLocation, useNavigate } from 'react-router';
8-
import { Link } from 'react-router-dom';
7+
import { Link, useLocation, useNavigate } from 'react-router';
98
import styled from 'styled-components';
109
import standardBoxShadow from '../../common/components/Style/standardBoxShadow';
1110
import { hasIPhoneNotch } from '../../common/utils/cordovaUtils';

src/js/components/Person/EditPersonForm.jsx

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import { Button, Checkbox, FormControl, FormControlLabel, TextField } from '@mui/material';
2-
import { Launch } from '@mui/icons-material';
1+
import { ErrorOutline, Launch } from '@mui/icons-material';
2+
import { Alert, Button, Checkbox, FormControl, FormControlLabel, TextField } from '@mui/material';
33
import { withStyles } from '@mui/styles';
4+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
45
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
56
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
6-
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
77
import dayjs from 'dayjs';
88
import utc from 'dayjs/plugin/utc';
99
import PropTypes from 'prop-types';
1010
import React, { Suspense, useEffect, useRef, useState } from 'react';
11-
import styled from 'styled-components';
1211
import CopyToClipboard from 'react-copy-to-clipboard';
12+
import styled from 'styled-components';
13+
import DesignTokenColors from '../../common/components/Style/DesignTokenColors';
14+
import generateRandomString from '../../common/utils/generateRandomString';
1315
import { renderLog } from '../../common/utils/logging';
1416
import webAppConfig from '../../config';
1517
import { useConnectAppContext } from '../../contexts/ConnectAppContext';
1618
import { viewerCanSeeOrDo } from '../../models/AuthModel';
17-
import { ActionOption, ActionOptionContainerLeft8, ActionOptionContainerOverflow, ActionOptionList } from '../Style/actionOptionStyles';
1819
import makeRequestParams from '../../react-query/makeRequestParams';
1920
import { usePersonSaveMutation } from '../../react-query/mutations';
21+
import weConnectQueryFn, { METHOD } from '../../react-query/WeConnectQuery';
22+
import { ActionOption, ActionOptionContainerLeft8, ActionOptionContainerOverflow, ActionOptionList } from '../Style/actionOptionStyles';
2023
import { SpanWithLinkStyle } from '../Style/linkStyles';
2124
import EmailOfficialManager from './EmailOfficialManager';
22-
import DesignTokenColors from '../../common/components/Style/DesignTokenColors';
23-
import weConnectQueryFn, { METHOD } from '../../react-query/WeConnectQuery';
24-
import generateRandomString from '../../common/utils/generateRandomString';
2525

2626

2727
dayjs.extend(utc);
@@ -40,6 +40,7 @@ const EditPersonForm = ({ classes }) => {
4040
const [saveButtonActive, setSaveButtonActive] = useState(false);
4141
const [showEmailPreferred, setShowEmailPreferred] = useState(false);
4242
const [showFirstNamePreferred, setShowFirstNamePreferred] = useState(false);
43+
const [emailError, setEmailError] = useState('');
4344
const [showCompletedOnboardingCheckboxes, setShowCompletedOnboardingCheckboxes] = useState(false);
4445
const [initialPerson] = useState(getAppContextValue('profileDrawerPerson'));
4546
// const [initialPerson] = useState(useGetPersonById(getAppContextValue('profileDrawerPersonId')));
@@ -186,20 +187,32 @@ const EditPersonForm = ({ classes }) => {
186187
// console.log('activePerson:', activePerson);
187188

188189

189-
const wevoteUserClick = async () => {
190-
const primaryEmail = activePerson.emailOfficial;
190+
const resetWeVoteEducationClick = async () => {
191+
setEmailError('');
192+
const { emailOfficial, emailPersonal, firstName } = activePerson;
193+
if (!emailOfficial.includes('wevoteeducation.org') && !emailPersonal.includes('wevoteeducation.org')) {
194+
setEmailError(`"${firstName}" does not have a wevoteeducation.org email as either their official (${emailOfficial}) or private (${emailOfficial}) address`);
195+
return;
196+
}
197+
const emailToChange = emailOfficial.includes('wevoteeducation.org') ? emailOfficial : emailPersonal;
191198
const newPassword = generateRandomString(12);
192-
// console.log(`deletewevoteuserpassword ${primaryEmail} ${newPassword}`);
199+
// console.log(`deletewevoteuserpassword ${emailToChange} ${newPassword}`);
193200
const data = await weConnectQueryFn('google-reset-user-password', {
194-
primaryEmail,
201+
primaryEmail: emailToChange,
195202
newPassword,
196203
}, METHOD.POST);
197204
// console.log('reset wevote password', data);
198205
if (data.success) {
199-
setNewPasswordNotification(`Thank you for requesting that your password be reset. These are your new sign in credentials: \n https://team.wevote.org \n user: ${primaryEmail} \n pass: ${newPassword}`);
206+
setNewPasswordNotification(`Thank you for requesting that your password be reset. These are your new sign in credentials: \n https://team.wevote.org \n user: ${emailToChange} \n pass: ${newPassword}`);
200207
setShowNewPasswordNotification(true);
201208
} else {
202-
console.error('Failed to reset password:', data);
209+
// console.error('Failed to reset password:', data);
210+
console.log(`Reset password API error: ${data.error}`);
211+
if (data.error.startsWith('Missing required')) {
212+
setEmailError(`'${emailToChange}' is not an existing valid @wevoteeducation.org email address.`);
213+
} else {
214+
setEmailError(`${data.error}, google api server code: ${data.errorCode}`);
215+
}
203216
}
204217
};
205218

@@ -552,7 +565,7 @@ const EditPersonForm = ({ classes }) => {
552565
classes={viewerIsOnHrTeam ? { root: classes.showThisField } : { root: classes.hideThisField }}
553566
disabled={!emailOfficialCanBeEdited}
554567
id="emailOfficialToBeSaved"
555-
label={`Email Address, ${webAppConfig.ORGANIZATION_NAME} Official`}
568+
label={<span style={{ paddingRight: '8px' }}>Email Address, {webAppConfig.ORGANIZATION_NAME} Official ({webAppConfig.ORGANIZATION_NAME === 'WeVote' ? '@wevoteeducation.org' : ''})</span>}
556569
margin="dense"
557570
name="emailOfficial"
558571
onChange={(event) => {
@@ -565,9 +578,14 @@ const EditPersonForm = ({ classes }) => {
565578
value={emailOfficialLocal}
566579
variant="outlined"
567580
/>
581+
{emailError.length > 0 && (
582+
<Alert icon={<ErrorOutline fontSize="inherit" />} severity="error">
583+
{emailError}
584+
</Alert>
585+
)}
568586
<QuickLink>
569-
<SpanWithLinkStyle onClick={wevoteUserClick}>
570-
Reset WeVote email password
587+
<SpanWithLinkStyle onClick={resetWeVoteEducationClick}>
588+
Reset Official ({webAppConfig.ORGANIZATION_NAME === 'WeVote' ? '@wevoteeducation.org' : ''}) email password
571589
</SpanWithLinkStyle>
572590
</QuickLink>
573591
{showNewPasswordNotification && (

src/js/pages/Login.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const Login = ({ classes }) => {
112112
setAppContextValue('authenticatedPerson', data.person);
113113
queryClient.invalidateQueries('get-auth');
114114
if (data.emailVerified) {
115-
passwordFldRef.current.value = ''; // Blank the email field after signing in
115+
passwordFldRef.current = ''; // Blank the email field after signing in
116116
setWarningLine('');
117117
setAppContextValue('secretCodeVerified', true);
118118
setAppContextValue('openVerifySecretCodeModalDialog', false);
@@ -150,8 +150,10 @@ const Login = ({ classes }) => {
150150
setOpenResetPasswordDialog(false);
151151
setShowCreateStuff(false);
152152
const per = authPerson.current ? authPerson.current : getAppContextValue('authenticatedPerson');
153-
setSuccessLine(`${getFullNamePreferredPerson(per)}, you are signed in!`);
154-
passwordFldRef.current.value = ''; // Blank the email field after signing in
153+
setWarningLine('');
154+
const name = getFullNamePreferredPerson(per);
155+
setSuccessLine(name.length ? `${name}, you are signed in!` : 'You are signed in!');
156+
passwordFldRef.current = ''; // Blank the email field after signing in
155157
}
156158
};
157159

@@ -231,7 +233,7 @@ const Login = ({ classes }) => {
231233

232234
const signOutButtonPressed = async () => {
233235
if (passwordFldRef.current) {
234-
passwordFldRef.current.value = ''; // Blank the email field after signing out
236+
passwordFldRef.current = ''; // Blank the email field after signing out
235237
}
236238
clearSignedInGlobals(setAppContextValue, getAppContextData);
237239
setOpenResetPasswordDialog(false);
@@ -268,7 +270,7 @@ const Login = ({ classes }) => {
268270
} else {
269271
setWarningLine('');
270272
let errStr = '';
271-
const firstName = firstNameFldRef.current.value;
273+
const firstName = firstNameFldRef?.current?.value;
272274
const lastName = lastNameFldRef.current.value;
273275
const location = locationFldRef.current.value;
274276
const emailPersonal = emailPersonalFldRef.current.value;
@@ -311,7 +313,7 @@ const Login = ({ classes }) => {
311313

312314
// console.log(getAppContextData());
313315
const isAdmin = viewerCanSeeOrDo(['canAddTeamMemberAnyTeam'], viewerAccessRights);
314-
const isAuthSafe = getAppContextValue('isAuthenticated') || false;
316+
// const isAuthSafe = getAppContextValue('isAuthenticated') || false;
315317
let isAuthenticated = false;
316318
let authenticatedPerson = {};
317319
if (dataAuth) {

src/js/pages/SystemSettings/FastLoad.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const FastLoad = () => {
2525

2626
useEffect(() => {
2727
const { location: { hostname } } = window;
28-
if (hostname.includes('wevote.org') || webAppConfig.SERVER_IS_SOURCE_OF_TRUTH == true) {
28+
if (hostname.includes('wevote.org') || webAppConfig.SERVER_IS_SOURCE_OF_TRUTH === true) {
2929
setFeatureDisabled(true);
3030
}
3131
}, []);

0 commit comments

Comments
 (0)