From d4adb3a3faa36b4500c17e661e09ec2af338b353 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 11 May 2020 03:37:33 +0300 Subject: User invitation via Email ! --- .../ViewModels/OrganizationUsersViewVM.cs | 1 + .../ViewModels/UserDetailsViewVM.cs | 44 +- .../Views/UserDetailsView.xaml | 2 +- .../Tango.FSE.BL/Services/AuthenticationService.cs | 16 + .../Tango.FSE.BL/Services/OrganizationsService.cs | 26 +- .../FSE/Tango.FSE.BL/Web/FSEWebClientBase.cs | 18 + .../Messages/ForgotPasswordRequest.cs | 14 + .../Messages/ForgotPasswordResponse.cs | 14 + .../Messages/UserInvitationEmailRequest.cs | 17 + .../Messages/UserInvitationEmailResponse.cs | 14 + .../FSE/Tango.FSE.Web/Tango.FSE.Web.csproj | 4 + .../Referenced Assemblies/SendGrid/SendGrid.dll | Bin 0 -> 48640 bytes .../Referenced Assemblies/SendGrid/SendGrid.xml | 1388 ++++++++++++++++++++ .../Controllers/FSEController.cs | 80 +- .../Tango.MachineService/MachineServiceConfig.cs | 2 + .../Tango.MachineService.csproj | 5 +- .../Web/Tango.MachineService/Web.config | 2 + 17 files changed, 1621 insertions(+), 26 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Web/Messages/ForgotPasswordRequest.cs create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Web/Messages/ForgotPasswordResponse.cs create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Web/Messages/UserInvitationEmailRequest.cs create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Web/Messages/UserInvitationEmailResponse.cs create mode 100644 Software/Visual_Studio/Referenced Assemblies/SendGrid/SendGrid.dll create mode 100644 Software/Visual_Studio/Referenced Assemblies/SendGrid/SendGrid.xml (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/OrganizationUsersViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/OrganizationUsersViewVM.cs index ff3978dff..334c8c263 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/OrganizationUsersViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/OrganizationUsersViewVM.cs @@ -107,6 +107,7 @@ namespace Tango.FSE.UsersAndRoles.ViewModels ModularNavigationManager.NavigateTo(UsersAndRolesView.UserDetailsView, new UserDetailsViewVM.NavigationObject() { IsNewUser = true, + Organization = Organization }); } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/UserDetailsViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/UserDetailsViewVM.cs index 304ee15c5..51ce71387 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/UserDetailsViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/UserDetailsViewVM.cs @@ -24,10 +24,18 @@ namespace Tango.FSE.UsersAndRoles.ViewModels public class NavigationObject { + public Organization Organization { get; set; } public User User { get; set; } public bool IsNewUser { get; set; } } + private Organization _organization; + public Organization Organization + { + get { return _organization; } + set { _organization = value; RaisePropertyChangedAuto(); } + } + private bool _isNewUser; public bool IsNewUser { @@ -95,6 +103,13 @@ namespace Tango.FSE.UsersAndRoles.ViewModels set { _rolesCollection = value; RaisePropertyChangedAuto(); } } + private bool _sendInvitation; + public bool SendInvitation + { + get { return _sendInvitation; } + set { _sendInvitation = value; RaisePropertyChangedAuto(); } + } + public RelayCommand SaveCommand { get; set; } public RelayCommand GeneratePasswordCommand { get; set; } @@ -103,6 +118,7 @@ namespace Tango.FSE.UsersAndRoles.ViewModels { SaveCommand = new RelayCommand(Save, () => IsFree); GeneratePasswordCommand = new RelayCommand(GeneratePassword); + SendInvitation = true; } private void GeneratePassword() @@ -216,7 +232,7 @@ namespace Tango.FSE.UsersAndRoles.ViewModels IsFree = false; - using (NotificationProvider.PushTaskItem("Saving user details...")) + using (var task = NotificationProvider.PushTaskItem("Saving user details...")) { var rolesToAdd = RolesCollection.Where(x => x.IsSelected).ToList().Where(x => !User.FSERoles.Exists(y => y.Guid == x.Role.Guid)).ToList(); var rolesToRemove = User.FSERoles.ToList().Where(x => !RolesCollection.Where(z => z.IsSelected).ToList().Exists(y => y.Role.Guid == x.Guid)).ToList(); @@ -250,11 +266,36 @@ namespace Tango.FSE.UsersAndRoles.ViewModels } else { + User.OrganizationGuid = Organization.Guid; User.Email = Email; User.Password = Password; await Services.OrganizationsService.InsertUser(User); + if (SendInvitation) + { + bool invitationSent = false; + task.UpdateProgress("Sending email invitation..."); + + while (!invitationSent) + { + try + { + await Services.OrganizationsService.SendNewUserInvitationEmail(Email, FirstName + " " + LastName, Password); + invitationSent = true; + } + catch (Exception ex) + { + if (!await NotificationProvider.ShowWarningQuestion($"The user was created but an error occurred while trying to send the invitation via email.{ex.Message}\nWould you like to try again?")) + { + break; + } + } + } + } + + await NotificationProvider.ShowSuccess("User created successfully!"); + IsNewUser = false; Password = null; userToLoadGuid = User.Guid; @@ -334,6 +375,7 @@ namespace Tango.FSE.UsersAndRoles.ViewModels { User = null; IsNewUser = obj.IsNewUser; + Organization = obj.Organization; if (!IsNewUser) { diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/Views/UserDetailsView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/Views/UserDetailsView.xaml index 98197eaac..a2ad81cf4 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/Views/UserDetailsView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/Views/UserDetailsView.xaml @@ -149,7 +149,7 @@ - Send invitation via email + Send invitation via email