aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-05-13 13:27:01 +0300
committerAvi Levkovich <avi@twine-s.com>2020-05-13 13:27:01 +0300
commit15dfc2cdcbc2e518c09c1ee75f32ff149d4a337d (patch)
tree4c0b49773706b85282e6f6b1ec3d2e949d3ca22e /Software/Visual_Studio/Web/Tango.MachineService/Controllers
parent6a49e917c587dcbbfe8175b8dde73840b7d105fc (diff)
parentcd750d626d3780990797faf09446033bbaa4311c (diff)
downloadTango-15dfc2cdcbc2e518c09c1ee75f32ff149d4a337d.tar.gz
Tango-15dfc2cdcbc2e518c09c1ee75f32ff149d4a337d.zip
commit merge
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEAccountController.cs67
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs192
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEDownloadsController.cs60
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs9
4 files changed, 301 insertions, 27 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEAccountController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEAccountController.cs
new file mode 100644
index 000000000..b7728af6a
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEAccountController.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using Tango.BL;
+using Tango.MachineService.Filters;
+using Tango.MachineService.Models;
+using Tango.Web.Helpers;
+using System.Data.Entity;
+using Tango.Web.Storage;
+using System.IO;
+using Microsoft.WindowsAzure.Storage.Blob;
+using System.Net.Http;
+using System.Net;
+using System.Net.Http.Headers;
+using System.Net.Mime;
+using Tango.MachineService.Views.FSEAccount;
+
+namespace Tango.MachineService.Controllers
+{
+ public class FSEAccountController : Controller
+ {
+ private static Random rnd = new Random();
+
+ public ActionResult ResetPassword(String id)
+ {
+ ResetPasswordVM vm = new ResetPasswordVM();
+ vm.FullName = "Full Name";
+ vm.Password = "Password";
+
+ var reset = FSEController.PendingPasswordResets.SingleOrDefault(x => x.ID == id);
+
+ if (reset != null)
+ {
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ var user = db.Users.SingleOrDefault(x => x.Guid == reset.UserGuid);
+
+ if (user != null)
+ {
+ String newPass = GenerateRandomPassword();
+ user.Password = Tango.BL.Entities.User.GetPasswordHash(newPass);
+ user.PasswordChangeRequired = true;
+ vm.Password = newPass;
+ vm.FullName = reset.FullName;
+ db.SaveChanges();
+ }
+ }
+ }
+
+ return View(vm);
+ }
+
+ private String GenerateRandomPassword()
+ {
+ String pass = String.Empty;
+
+ for (int i = 0; i < 4; i++)
+ {
+ pass += rnd.Next(0, 9).ToString();
+ }
+
+ return pass;
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
index bb3ef588f..e471ed20c 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
@@ -1,10 +1,13 @@
-using System;
+using SendGrid;
+using SendGrid.Helpers.Mail;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Authentication;
using System.Threading.Tasks;
+using System.Web;
using System.Web.Http;
using Tango.BL;
using Tango.BL.Builders;
@@ -20,22 +23,32 @@ using Tango.Web.Security;
using Tango.Web.SMO;
using Tango.Web.SQLServer;
using Tango.Web.Storage;
+using System.Data.Entity;
+using static Tango.MachineService.Controllers.FSEController;
namespace Tango.MachineService.Controllers
{
- public class FSEController : TangoController
+ public class FSEController : TangoController<TokenObject>
{
public class TokenObject
{
public String UserGuid { get; set; }
}
- /// <summary>
- /// Login to the service.
- /// </summary>
- /// <param name="request">The request.</param>
- /// <returns></returns>
- /// <exception cref="AuthenticationException"></exception>
+ public class PasswordReset
+ {
+ public String ID { get; set; }
+ public String UserGuid { get; set; }
+ public String FullName { get; set; }
+ }
+
+ public static List<PasswordReset> PendingPasswordResets { get; set; }
+
+ static FSEController()
+ {
+ PendingPasswordResets = new List<PasswordReset>();
+ }
+
[HttpPost]
public LoginResponse Login(LoginRequest request)
{
@@ -83,22 +96,6 @@ namespace Tango.MachineService.Controllers
AccessTokenExpiration = accessToken.ExpiresOn.UtcDateTime
};
-
- //Enforce Machine Studio Version ?
- //if (MachineServiceConfig.ENFORCE_MACHINE_STUDIO_VERSION)
- //{
- // using (var db = ObservablesContextHelper.CreateContext())
- // {
- // var latest_version = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
-
- // if (latest_version != null && Version.Parse(latest_version.Version) != client_version)
- // {
- // versionChangeRequired = true;
- // requiredVersion = latest_version.Version;
- // }
- // }
- //}
-
//Return data source
return new LoginResponse()
{
@@ -179,5 +176,152 @@ 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,
+ };
+ }
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public UserInvitationEmailResponse SendUserInvitationEmail(UserInvitationEmailRequest request)
+ {
+ User user;
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ user = db.Users.Include(x => x.Contact).SingleOrDefault(x => x.Guid == request.UserGuid);
+
+ if (user == null)
+ {
+ throw new InvalidOperationException("User not found.");
+ }
+ }
+
+ var client = new SendGridClient(MachineServiceConfig.SEND_GRID_API_KEY);
+ SendGridMessage msg = new SendGridMessage();
+ msg.SetFrom("info@twine-s.com", "Twine Solutions LTD");
+ msg.AddTo(user.Email);
+ msg.Subject = "Welcome To Tango FSE";
+ msg.SetTemplateId("d-2af42ed0ea3c44b3abaa61016223555a");
+
+ var dynamicTemplateData = new
+ {
+ DownloadUrl = $"{request.MachineServiceAddress}/fse",
+ FullName = user.Contact.FirstName,
+ Password = request.Password,
+ };
+
+ msg.SetTemplateData(dynamicTemplateData);
+
+ var result = client.SendEmailAsync(msg).GetAwaiter().GetResult();
+
+ if (result.StatusCode != HttpStatusCode.Accepted)
+ {
+ throw new HttpException(result.StatusCode.ToString());
+ }
+
+ return new UserInvitationEmailResponse();
+ }
+
+ [HttpPost]
+ public ForgotPasswordResponse SendForgotPasswordEmail(ForgotPasswordRequest request)
+ {
+ User user;
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ user = db.Users.Include(x => x.Contact).SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower());
+
+ if (user == null)
+ {
+ throw new InvalidOperationException("User not found.");
+ }
+ }
+
+ String resetId = Guid.NewGuid().ToString();
+
+ var client = new SendGridClient(MachineServiceConfig.SEND_GRID_API_KEY);
+ SendGridMessage msg = new SendGridMessage();
+ msg.SetFrom("info@twine-s.com", "Twine Solutions LTD");
+ msg.AddTo(request.Email);
+ msg.Subject = "Tango FSE Password Reset";
+ msg.SetTemplateId("d-18065487dae4456b8684d4b47a91e4a6");
+
+ var dynamicTemplateData = new
+ {
+ ResetPasswordUrl = $"{request.MachineServiceAddress}/FSEAccount/ResetPassword?id={resetId}",
+ FullName = user.Contact.FirstName,
+ };
+
+ msg.SetTemplateData(dynamicTemplateData);
+
+ var result = client.SendEmailAsync(msg).GetAwaiter().GetResult();
+
+ if (result.StatusCode != HttpStatusCode.Accepted)
+ {
+ throw new HttpException(result.StatusCode.ToString());
+ }
+
+ PendingPasswordResets.Add(new PasswordReset()
+ {
+ ID = resetId,
+ UserGuid = user.Guid,
+ FullName = user.Contact.FirstName,
+ });
+
+ return new ForgotPasswordResponse();
+ }
}
}
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEDownloadsController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEDownloadsController.cs
new file mode 100644
index 000000000..52eb2bbb5
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEDownloadsController.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using Tango.BL;
+using Tango.MachineService.Filters;
+using Tango.MachineService.Models;
+using Tango.Web.Helpers;
+using System.Data.Entity;
+using Tango.Web.Storage;
+using System.IO;
+using Microsoft.WindowsAzure.Storage.Blob;
+using System.Net.Http;
+using System.Net;
+using System.Net.Http.Headers;
+using System.Net.Mime;
+using Tango.MachineService.Views.FSEDownloads;
+
+namespace Tango.MachineService.Controllers
+{
+ public class FSEDownloadsController : Controller
+ {
+ public ActionResult Index()
+ {
+ IndexViewModel model = new IndexViewModel();
+
+ using (var db = ObservablesContextHelper.CreateContext())
+ {
+ var versions = db.FseVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).Take(6).ToList();
+
+ var manager = new BlobStorageManager();
+ var container = manager.GetContainer(MachineServiceConfig.FSE_VERSIONS_CONTAINER);
+
+ foreach (var item in versions)
+ {
+ var installerBlob = container.GetBlockBlobReference(item.InstallerBlobName);
+
+ model.Downloads.Add(new FSEDownload()
+ {
+ Name = $"Tango FSE v{Version.Parse(item.Version).ToString(3)}",
+ Version = Version.Parse(item.Version).ToString(3),
+ Comments = item.Comments,
+ Date = item.LastUpdated.ToString("dddd, dd MMMM yyyy"),
+ Address = MachineServiceConfig.CDN_ENDPOINT + installerBlob.Uri.AbsolutePath
+ });
+ }
+
+ if (model.Downloads.Count > 0)
+ {
+ var latest = model.Downloads.First();
+ model.Downloads.Remove(latest);
+ model.LatestDownload = latest;
+ }
+ }
+
+ return View(model);
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
index 2049df665..28acb3647 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
@@ -344,11 +344,14 @@ namespace Tango.MachineService.Controllers
response.IsUpdateAvailable = true;
}
- if (!String.IsNullOrWhiteSpace(request.FirmwareVersion))
+ if (!machine.IsDemo && machine.SetupFirmware)
{
- if (Version.Parse(latest_machine_version.FirmwareVersion) > Version.Parse(request.FirmwareVersion))
+ if (!String.IsNullOrWhiteSpace(request.FirmwareVersion))
{
- response.IsUpdateAvailable = true;
+ if (Version.Parse(latest_machine_version.FirmwareVersion) > Version.Parse(request.FirmwareVersion))
+ {
+ response.IsUpdateAvailable = true;
+ }
}
}