Skip to content

Commit

Permalink
Simple email changing (without verification) due to updating Parse Se…
Browse files Browse the repository at this point in the history
…rver to actual version, not my fork. I hope it's temporary.
  • Loading branch information
Nes-si committed Jan 1, 2021
1 parent bdb6ba0 commit 0626cf4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 89 deletions.
57 changes: 18 additions & 39 deletions src/containers/MainArea/UserProfile/UserProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,10 +34,9 @@ export class UserProfile extends Component {
successData: ``,

email: this.userData.email,
emailNew: '',
dirtyEmail: false,
errorEmail: null,
successEmailState: false,
successEmail: ``,

passwordOld: ``,
password: '',
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
});
};
Expand All @@ -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}`);
};
Expand Down Expand Up @@ -320,7 +306,7 @@ export class UserProfile extends Component {
<div styleName="input-wrapper">
<InputControl type="big"
label="Email"
value={this.state.emailNew}
value={this.state.email}
titled
onChange={this.onChangeEmail} />
</div>
Expand All @@ -332,15 +318,8 @@ export class UserProfile extends Component {
disabled={!this.state.dirtyEmail || this.state.errorEmail}
value="Change Email"/>
</div>
{this.state.successEmailState &&
<div styleName="field-success">
<div>
Your email was changed. We've sent to your new email a link to confirm it. You can use your old email <b>{this.state.email}</b> before confirmation.
</div>
<div styleName="field-success-resend" onClick={this.resendVerification}>
Resend confirmation email
</div>
</div>
{this.state.successEmail &&
<div styleName="field-success">{this.state.successEmail}</div>
}
{this.state.errorEmail &&
<div styleName="field-error">{this.state.errorEmail}</div>
Expand Down Expand Up @@ -483,7 +462,7 @@ function mapStateToProps(state) {

function mapDispatchToProps(dispatch) {
return {
userActions: bindActionCreators({update, updateEmail, updatePassword, resendVerEmail}, dispatch)
userActions: bindActionCreators({update, updatePassword}, dispatch)
};
}

Expand Down
51 changes: 3 additions & 48 deletions src/ducks/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/models/UserData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export class UserData {
origin = null;

email = "";
emailNew = "";
firstName = "";
lastName = "";
avatar = null;
Expand All @@ -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');
Expand All @@ -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);
Expand Down

0 comments on commit 0626cf4

Please sign in to comment.