From 8336c907a3084b7333e27da3a2ea601dfc4258f2 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 30 Apr 2020 20:17:10 +0300 Subject: FSE automatic update checks. --- .../Controllers/FSEController.cs | 65 +++++++++++++++++++--- 1 file changed, 58 insertions(+), 7 deletions(-) (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs') diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs index bb3ef588f..7bf420df9 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs @@ -20,22 +20,17 @@ using Tango.Web.Security; using Tango.Web.SMO; using Tango.Web.SQLServer; using Tango.Web.Storage; +using static Tango.MachineService.Controllers.FSEController; namespace Tango.MachineService.Controllers { - public class FSEController : TangoController + public class FSEController : TangoController { public class TokenObject { public String UserGuid { get; set; } } - /// - /// Login to the service. - /// - /// The request. - /// - /// [HttpPost] public LoginResponse Login(LoginRequest request) { @@ -179,5 +174,61 @@ namespace Tango.MachineService.Controllers return response; } + + [HttpPost] + [JwtTokenFilter] + public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request) + { + CheckForUpdatesResponse response = new CheckForUpdatesResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + var versions = db.FseVersions.ToList(); + + FseVersion latestVersion = null; + + latestVersion = versions.OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + + Version currentVersion = Version.Parse(request.Version); + + String comments = String.Join(Environment.NewLine, versions.OrderBy(x => Version.Parse(x.Version)).Where(x => Version.Parse(x.Version) > currentVersion).Select(x => x.Comments)); + + if (latestVersion != null && Version.Parse(latestVersion.Version) != currentVersion) + { + var manager = new BlobStorageManager(); + var container = manager.GetContainer(MachineServiceConfig.FSE_VERSIONS_CONTAINER); + //var blob = container.GetBlockBlobReference(latestVersion.BlobName); + var installerBlob = container.GetBlockBlobReference(latestVersion.InstallerBlobName); + + //response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + + if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT)) + { + //response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath; + response.InstallerCdnAddress = MachineServiceConfig.CDN_ENDPOINT + installerBlob.Uri.AbsolutePath; + } + + response.IsUpdateAvailable = true; + response.Version = latestVersion.Version; + response.Comments = latestVersion.Comments; + } + } + + return response; + } + + [HttpPost] + [JwtTokenFilter] + public RefreshTokenResponse RefreshToken(RefreshTokenRequest request) + { + SQLServerManager sqlServer = new SQLServerManager(); + var accessToken = sqlServer.GetAccessToken(); + + return new RefreshTokenResponse() + { + AccessToken = accessToken.AccessToken, + Expiration = accessToken.ExpiresOn.UtcDateTime, + }; + } } } -- cgit v1.3.1 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 ! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../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 + 19 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/Web/Tango.MachineService/Controllers/FSEController.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index d29873151..20cd545f0 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 826bbc8e3..d89fbab3d 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ 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