ASC.People: ProfileAction: sending email change instructions

This commit is contained in:
Andrey Savihin 2019-09-13 17:30:24 +03:00
parent b196c81209
commit bdb5b05748
10 changed files with 115 additions and 9 deletions

View File

@ -5,7 +5,7 @@ import { Avatar, Button, Textarea, Text, toastr, ModalDialog, TextInput } from '
import { withTranslation } from 'react-i18next';
import { toEmployeeWrapper, getUserRole, getUserContactsPattern, getUserContacts, mapGroupsToGroupSelectorOptions, mapGroupSelectorOptionsToGroups, filterGroupSelectorOptions } from "../../../../../store/people/selectors";
import { updateProfile } from '../../../../../store/profile/actions';
import { sendInstructionsToChangePassword } from "../../../../../store/services/api";
import { sendInstructionsToChangePassword, sendInstructionsToChangeEmail } from "../../../../../store/services/api";
import { MainContainer, AvatarContainer, MainFieldsContainer } from './FormFields/Form'
import TextField from './FormFields/TextField'
import TextChangeField from './FormFields/TextChangeField'
@ -73,7 +73,7 @@ class UpdateUserForm extends React.Component {
header: "",
body: "",
buttons: [],
newEmail: "",
newEmail: profile.email,
},
selector: {
visible: false,
@ -150,6 +150,10 @@ class UpdateUserForm extends React.Component {
}
onEmailChange(event) {
const emailRegex = /.+@.+\..+/;
const newEmail = event.target.value || this.state.dialog.newEmail;
const hasError = !emailRegex.test(newEmail);
const dialog = {
visible: true,
header: "Change email",
@ -160,8 +164,9 @@ class UpdateUserForm extends React.Component {
id="new-email"
scale={true}
isAutoFocussed={true}
value={event.target.value}
value={newEmail}
onChange={this.onEmailChange}
hasError={hasError}
/>
</Text.Body>
),
@ -172,16 +177,21 @@ class UpdateUserForm extends React.Component {
size="medium"
primary={true}
onClick={this.onSendEmailChangeInstructions}
isDisabled={hasError}
/>
],
newEmail: event.target.value
newEmail: newEmail
};
this.setState({ dialog: dialog })
}
onSendEmailChangeInstructions() {
toastr.success("Context action: Change email");
this.onDialogClose();
sendInstructionsToChangeEmail(this.state.profile.id, this.state.dialog.newEmail)
.then((res) => {
res.data.error ? toastr.error(res.data.error.message) : toastr.success(res.data.response)
})
.catch((error) => toastr.error(error.message))
.finally(this.onDialogClose);
}
onPasswordChange() {
@ -208,7 +218,9 @@ class UpdateUserForm extends React.Component {
onSendPasswordChangeInstructions() {
sendInstructionsToChangePassword(this.state.profile.email)
.then((res) => toastr.success(res.data.response))
.then((res) => {
res.data.error ? toastr.error(res.data.error.message) : toastr.success(res.data.response)
})
.catch((error) => toastr.error(error.message))
.finally(this.onDialogClose);
}
@ -241,7 +253,7 @@ class UpdateUserForm extends React.Component {
}
onDialogClose() {
const dialog = { visible: false };
const dialog = { visible: false, newEmail: this.state.profile.email };
this.setState({ dialog: dialog })
}

View File

@ -111,10 +111,16 @@ export function sendInstructionsToDelete() {
export function sendInstructionsToChangePassword(email) {
return IS_FAKE
? fakeApi.sendInstructionsToChangePassword(email)
? fakeApi.sendInstructionsToChangePassword()
: axios.post(`${API_URL}/people/password.json`, { email });
}
export function sendInstructionsToChangeEmail(userId, email) {
return IS_FAKE
? fakeApi.sendInstructionsToChangeEmail()
: axios.post(`${API_URL}/people/email.json`, { userId, email });
}
export function deleteUser(userId) {
return IS_FAKE
? fakeApi.deleteUser(userId)

View File

@ -520,6 +520,10 @@ export function sendInstructionsToChangePassword() {
return fakeResponse("Instruction has been sent successfully");
}
export function sendInstructionsToChangeEmail() {
return fakeResponse("Instruction has been sent successfully");
}
export function getGroup(groupId) {
return fakeResponse({
id: "06448c0a-7f10-4c6d-9ad4-f94de2235778",

View File

@ -800,6 +800,54 @@ namespace ASC.Employee.Core.Controllers
return new EmployeeWraperFull(GetUserInfo(userid.ToString()), ApiContext);
}
[Create("email", false)]
public string SendEmailChangeInstructions(UpdateMemberModel model)
{
Guid.TryParse(model.UserId, out Guid userid);
if (userid == Guid.Empty) throw new ArgumentNullException("userid");
var email = (model.Email ?? "").Trim();
if (string.IsNullOrEmpty(email)) throw new Exception(Resource.ErrorEmailEmpty);
if (!email.TestEmailRegex()) throw new Exception(Resource.ErrorNotCorrectEmail);
var viewer = CoreContext.UserManager.GetUsers(Tenant.TenantId, SecurityContext.CurrentAccount.ID);
var user = CoreContext.UserManager.GetUsers(Tenant.TenantId, userid);
if (user == null)
throw new Exception(Resource.ErrorUserNotFound);
if (viewer == null || (user.IsOwner(Tenant) && viewer.ID != user.ID))
throw new Exception(Resource.ErrorAccessDenied);
var existentUser = CoreContext.UserManager.GetUserByEmail(Tenant.TenantId, email);
if (existentUser.ID != Constants.LostUser.ID)
throw new Exception(CustomNamingPeople.Substitute<Resource>("ErrorEmailAlreadyExists"));
if (!viewer.IsAdmin(Tenant))
{
StudioNotifyService.SendEmailChangeInstructions(Tenant.TenantId, user, email);
}
else
{
if (email == user.Email)
throw new Exception(Resource.ErrorEmailsAreTheSame);
user.Email = email;
user.ActivationStatus = EmployeeActivationStatus.NotActivated;
CoreContext.UserManager.SaveUserInfo(Tenant, user);
StudioNotifyService.SendEmailActivationInstructions(Tenant.TenantId, user, email);
}
MessageService.Send(MessageAction.UserSentEmailChangeInstructions, user.DisplayUserName(false));
return string.Format(Resource.MessageEmailChangeInstuctionsSentOnEmail, email);
}
private UserInfo GetUserInfo(string userNameOrId)
{
UserInfo user;

View File

@ -94,6 +94,9 @@
<data name="ErrorEmailEmpty" xml:space="preserve">
<value>Das Feld für die E-Mail-Adresse ist leer</value>
</data>
<data name="ErrorEmailsAreTheSame" xml:space="preserve">
<value>Die aktuelle E-Mail-Adresse und die neue sind gleich</value>
</data>
<data name="ErrorEmptyUploadFileSelected" xml:space="preserve">
<value>Die hochgeladene Datei konnte nicht gefunden werden</value>
</data>
@ -154,6 +157,9 @@
<data name="LdapSettingsTooManyOperations" xml:space="preserve">
<value>Zu viele LDAP-Operationen.</value>
</data>
<data name="MessageEmailChangeInstuctionsSentOnEmail" xml:space="preserve">
<value>Die Hinweise für die Änderung der E-Mail-Adresse wurden erfolgreich gesendet</value>
</data>
<data name="MessageYourPasswordSuccessfullySendedToEmail" xml:space="preserve">
<value>Die Hinweise für die Änderung des Kennworts wurden an die folgende E-Mail-Adresse versandt: {0}</value>
</data>

View File

@ -94,6 +94,9 @@
<data name="ErrorEmailEmpty" xml:space="preserve">
<value>Campo de correo electrónico está vacío</value>
</data>
<data name="ErrorEmailsAreTheSame" xml:space="preserve">
<value>El correo electrónico actual y el nuevo correo electrónico son iguales</value>
</data>
<data name="ErrorEmptyUploadFileSelected" xml:space="preserve">
<value>Imposible encontrar el archivo subido</value>
</data>
@ -154,6 +157,9 @@
<data name="LdapSettingsTooManyOperations" xml:space="preserve">
<value>Demasiado muchas operaciones LDAP.</value>
</data>
<data name="MessageEmailChangeInstuctionsSentOnEmail" xml:space="preserve">
<value>Las instrucciones para cambiar el correo electrónico se han enviado con éxito</value>
</data>
<data name="MessageYourPasswordSuccessfullySendedToEmail" xml:space="preserve">
<value>La contraseña de usuario ha sido enviada al e-mail {0}</value>
</data>

View File

@ -94,6 +94,9 @@
<data name="ErrorEmailEmpty" xml:space="preserve">
<value>Le champ Email est vide</value>
</data>
<data name="ErrorEmailsAreTheSame" xml:space="preserve">
<value>L'adresse email actuelle et la nouvelle adresse sont les mêmes</value>
</data>
<data name="ErrorEmptyUploadFileSelected" xml:space="preserve">
<value>Le fichier chargé ne peut pas être trouvé</value>
</data>
@ -156,6 +159,9 @@
<data name="LdapSettingsTooManyOperations" xml:space="preserve">
<value>Trop d'opérations LDAP.</value>
</data>
<data name="MessageEmailChangeInstuctionsSentOnEmail" xml:space="preserve">
<value>Les instructions de changement d'émail ont été envoyées avec succès</value>
</data>
<data name="MessageYourPasswordSuccessfullySendedToEmail" xml:space="preserve">
<value>Les instructions de changement de mot de passe ont été envoyées à {0}</value>
</data>

View File

@ -94,6 +94,9 @@
<data name="ErrorEmailEmpty" xml:space="preserve">
<value>Il campo Email è vuoto</value>
</data>
<data name="ErrorEmailsAreTheSame" xml:space="preserve">
<value>L'indirizzo email corrente coincide con quello nuovo.</value>
</data>
<data name="ErrorEmptyUploadFileSelected" xml:space="preserve">
<value>E' impossibile trovare il file caricato</value>
</data>
@ -154,6 +157,9 @@
<data name="LdapSettingsTooManyOperations" xml:space="preserve">
<value>Troppe operazioni LDAP</value>
</data>
<data name="MessageEmailChangeInstuctionsSentOnEmail" xml:space="preserve">
<value>Le istruzioni di modifica dell'email sono state inviate correttamente</value>
</data>
<data name="MessageYourPasswordSuccessfullySendedToEmail" xml:space="preserve">
<value>Le istruzioni di modifica della password sono state inviate all'indirizzo email {0}.</value>
</data>

View File

@ -94,6 +94,9 @@
<data name="ErrorEmailEmpty" xml:space="preserve">
<value>Email field is empty</value>
</data>
<data name="ErrorEmailsAreTheSame" xml:space="preserve">
<value>The current email and the new email are the same</value>
</data>
<data name="ErrorEmptyUploadFileSelected" xml:space="preserve">
<value>The uploaded file could not be found</value>
</data>
@ -154,6 +157,9 @@
<data name="LdapSettingsTooManyOperations" xml:space="preserve">
<value>Too many LDAP operations.</value>
</data>
<data name="MessageEmailChangeInstuctionsSentOnEmail" xml:space="preserve">
<value>The email change instructions have been successfuly sent</value>
</data>
<data name="MessageYourPasswordSuccessfullySendedToEmail" xml:space="preserve">
<value>The password change instructions have been sent to the {0} email address.</value>
</data>

View File

@ -94,6 +94,9 @@
<data name="ErrorEmailEmpty" xml:space="preserve">
<value>Не заполнено поле адреса электронной почты</value>
</data>
<data name="ErrorEmailsAreTheSame" xml:space="preserve">
<value>Текущий адрес электронной почты совпадает с новым адресом</value>
</data>
<data name="ErrorEmptyUploadFileSelected" xml:space="preserve">
<value>Загружаемый файл не найден</value>
</data>
@ -154,6 +157,9 @@
<data name="LdapSettingsTooManyOperations" xml:space="preserve">
<value>Слишком много операций LDAP.</value>
</data>
<data name="MessageEmailChangeInstuctionsSentOnEmail" xml:space="preserve">
<value>Инструкции по изменению электронной почты были успешно отправлены</value>
</data>
<data name="MessageYourPasswordSuccessfullySendedToEmail" xml:space="preserve">
<value>Инструкции по изменению пароля были высланы на email {0}</value>
</data>