From 0626cf4876a44b2b5dc43bf49eac1c68c872c2d4 Mon Sep 17 00:00:00 2001 From: Nikita Golovin Date: Fri, 1 Jan 2021 12:25:30 +0300 Subject: [PATCH] Simple email changing (without verification) due to updating Parse Server to actual version, not my fork. I hope it's temporary. --- .../MainArea/UserProfile/UserProfile.js | 57 ++++++------------- src/ducks/user.js | 51 +---------------- src/models/UserData.js | 3 +- 3 files changed, 22 insertions(+), 89 deletions(-) diff --git a/src/containers/MainArea/UserProfile/UserProfile.js b/src/containers/MainArea/UserProfile/UserProfile.js index 11cddcb1..4849981d 100644 --- a/src/containers/MainArea/UserProfile/UserProfile.js +++ b/src/containers/MainArea/UserProfile/UserProfile.js @@ -8,7 +8,7 @@ import CSSModules from 'react-css-modules'; import InputControl from 'components/elements/InputControl/InputControl'; import ButtonControl from 'components/elements/ButtonControl/ButtonControl'; import ContainerComponent from 'components/elements/ContainerComponent/ContainerComponent'; -import {update, updateEmail, updatePassword, resendVerEmail, ERROR_USER_EXISTS, ERROR_OTHER} from 'ducks/user'; +import {update, updatePassword, ERROR_USER_EXISTS, ERROR_OTHER} from 'ducks/user'; import {URL_PAY_PLANS, URL_USERSPACE, URL_PAYMENT_METHODS} from "ducks/nav"; import {config, changeServerURL} from 'utils/initialize'; import {checkURL, checkEmail, getTextDate} from 'utils/strings'; @@ -34,10 +34,9 @@ export class UserProfile extends Component { successData: ``, email: this.userData.email, - emailNew: '', dirtyEmail: false, errorEmail: null, - successEmailState: false, + successEmail: ``, passwordOld: ``, password: '', @@ -57,14 +56,6 @@ export class UserProfile extends Component { constructor(props) { super(props); - - if (this.userData.emailNew) { - this.state.emailNew = this.userData.emailNew; - this.state.successEmailState = true; - } else { - this.state.emailNew = this.userData.email; - } - this.state.serverURL = config.serverURL; } @@ -85,12 +76,10 @@ export class UserProfile extends Component { } if (errorEmail) { - this.setState({ - emailNew: this.userData.emailNew ? this.userData.emailNew : this.userData.email, - errorEmail - }); + this.setState({errorEmail}); } else { - this.setState({successEmailState: true}); + this.setState({successEmail: `Email was successfully changed!`}); + setTimeout(() => this.setState({successEmail: ``}), 2500); } break; @@ -131,9 +120,11 @@ export class UserProfile extends Component { if (this.validateEmail()) { this.setState({dirtyEmail: false}); this.lastChange = CHG_EMAIL; - - const {updateEmail} = this.props.userActions; - updateEmail(this.state.emailNew); + + this.userData.email = this.state.email; + + const {update} = this.props.userActions; + update(this.userData); } }; @@ -176,7 +167,7 @@ export class UserProfile extends Component { } validateEmail() { - if (!checkEmail(this.state.emailNew)) { + if (!checkEmail(this.state.email)) { this.setState({errorEmail: `Invalid email!`}); return false; } @@ -214,10 +205,10 @@ export class UserProfile extends Component { this.setState({lastName, dirtyData: true, errorData: null}); }; - onChangeEmail = emailNew => { + onChangeEmail = email => { this.setState({ - emailNew, - dirtyEmail: emailNew != this.userData.emailNew, + email, + dirtyEmail: email != this.userData.email, errorEmail: null }); }; @@ -241,11 +232,6 @@ export class UserProfile extends Component { this.setState({serverURL, dirtyServer: true, errorServer: null}); }; - resendVerification = e => { - const {resendVerEmail} = this.props.userActions; - resendVerEmail(); - }; - onChangePayPlan = () => { browserHistory.push(`/${URL_USERSPACE}/${URL_PAY_PLANS}`); }; @@ -320,7 +306,7 @@ export class UserProfile extends Component {
@@ -332,15 +318,8 @@ export class UserProfile extends Component { disabled={!this.state.dirtyEmail || this.state.errorEmail} value="Change Email"/> - {this.state.successEmailState && -
-
- Your email was changed. We've sent to your new email a link to confirm it. You can use your old email {this.state.email} before confirmation. -
-
- Resend confirmation email -
-
+ {this.state.successEmail && +
{this.state.successEmail}
} {this.state.errorEmail &&
{this.state.errorEmail}
@@ -483,7 +462,7 @@ function mapStateToProps(state) { function mapDispatchToProps(dispatch) { return { - userActions: bindActionCreators({update, updateEmail, updatePassword, resendVerEmail}, dispatch) + userActions: bindActionCreators({update, updatePassword}, dispatch) }; } diff --git a/src/ducks/user.js b/src/ducks/user.js index 32eb3aa8..454812e8 100644 --- a/src/ducks/user.js +++ b/src/ducks/user.js @@ -16,7 +16,6 @@ export const REGISTER_REQUEST = 'app/user/REGISTER_REQUEST'; export const REGISTER_RESPONSE = 'app/user/REGISTER_RESPONSE'; export const LOGOUT = 'app/user/LOGOUT'; export const UPDATE = 'app/user/UPDATE'; -export const UPDATE_EMAIL = 'app/user/UPDATE_EMAIL'; export const UPDATE_PASSWORD = 'app/user/UPDATE_PASSWORD'; export const RESTORE_PASSWORD = 'app/user/RESTORE_PASSWORD'; export const RESEND_VERIF = 'app/user/RESEND_VERIF'; @@ -194,36 +193,6 @@ export function update(data) { }; } -export function updateEmail(email) { - if (!email) - return null; - - return dispatch => { - const userData = Parse.User.current(); - send(userData.requestEmailChange(email)) - .then(() => { - dispatch({ - type: UPDATE_EMAIL, - status: OK, - email - }); - }) - .catch(error => { - let status = ERROR_OTHER; - switch (error.code) { - case PARSE_ERROR_CODE__USERNAME_TAKEN: - case PARSE_ERROR_CODE__EMAIL_TAKEN: - status = ERROR_USER_EXISTS; - break; - } - dispatch({ - type: UPDATE_EMAIL, - status - }); - }); - }; -} - export function updatePassword(password) { if (!password) return null; @@ -260,14 +229,9 @@ export function restorePassword(email) { } export function resendVerEmail(email) { - if (!email) { - let userData = store.getState().user.userData; - if (userData && userData.emailNew) - email = userData.emailNew; - else - return null; - } - + if (!email) + return null; + return dispatch => { send(fetch(config.serverURL + '/verificationEmailRequest', { method: 'POST', @@ -436,15 +400,6 @@ export default function userReducer(state = initialState, action) { ...state, userData: action.data }; - - case UPDATE_EMAIL: - if (action.email) - userData.emailNew = action.email; - return { - ...state, - userData, - status: action.status - }; case RESTORE_PASSWORD: return { diff --git a/src/models/UserData.js b/src/models/UserData.js index 677e702e..5c1fc345 100644 --- a/src/models/UserData.js +++ b/src/models/UserData.js @@ -5,7 +5,6 @@ export class UserData { origin = null; email = ""; - emailNew = ""; firstName = ""; lastName = ""; avatar = null; @@ -22,7 +21,6 @@ export class UserData { if (origin.get('email')) this.email = origin.get('email'); if (!this.email) this.email = origin.get('username'); - if (origin.get('emailNew')) this.emailNew = origin.get('emailNew'); if (origin.get('firstName')) this.firstName = origin.get('firstName'); if (origin.get('lastName')) this.lastName = origin.get('lastName'); if (origin.get('avatar')) this.avatar = origin.get('avatar'); @@ -33,6 +31,7 @@ export class UserData { } updateOrigin() { + this.origin.set("email", this.email); this.origin.set("firstName", this.firstName); this.origin.set("lastName", this.lastName); this.origin.set("avatar", this.avatar);