diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-02-26 16:44:52 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-02-26 16:44:52 +0200 |
| commit | 6f62fafb2ef10b11189e9474ab13f531e614cf49 (patch) | |
| tree | 110aca8a50f72b51bcf9a2b54e7f78b9871c6a88 /Software/Visual_Studio/Web/Tango.MachineService/Controllers | |
| parent | b462fdd744f491b04137fd99863f6cb6c623cfa0 (diff) | |
| parent | 47691cbb0207d32c7b86113e3c425138907265d9 (diff) | |
| download | Tango-6f62fafb2ef10b11189e9474ab13f531e614cf49.tar.gz Tango-6f62fafb2ef10b11189e9474ab13f531e614cf49.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers')
4 files changed, 135 insertions, 14 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs new file mode 100644 index 000000000..0a395b00e --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Security.Authentication; +using System.Web; +using System.Web.Mvc; +using System.Web.Security; +using Tango.BL; +using Tango.MachineService.Models; +using Tango.Web.ActiveDirectory; +using Tango.Web.Helpers; + +namespace Tango.MachineService.Controllers +{ + public class AccountController : Controller + { + private ActiveDirectoryManager _ad_manager; + + public AccountController() + { + _ad_manager = new ActiveDirectoryManager(); + } + + public ActionResult Login() + { + if (HttpContext.User.Identity.IsAuthenticated) + { + return RedirectToAction("Index", "Downloads", null); + } + + return View(); + } + + [HttpPost] + public ActionResult Login(AccountLogin request) + { + var authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password); + + if (!_ad_manager.CanUserAccessCurrentEnvironment(request.Email)) + { + throw new AuthenticationException($"You do not have permissions to access the {MachineServiceConfig.DEPLOYMENT_SLOT.ToDescription()} environment."); + } + + + FormsAuthentication.SetAuthCookie(request.Email, true); + return new HttpStatusCodeResult(HttpStatusCode.OK); + } + + [Authorize] + public ActionResult Logout() + { + FormsAuthentication.SignOut(); + return Login(); + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DownloadsController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DownloadsController.cs new file mode 100644 index 000000000..ecdbf662c --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DownloadsController.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using Tango.MachineService.Filters; +using Tango.MachineService.Models; +using Tango.MachineService.Views.Downloads; + +namespace Tango.MachineService.Controllers +{ + public class DownloadsController : Controller + { + [Authorize] + public ActionResult Index() + { + List<DownloadModel> downloads = new List<DownloadModel>(); + for (int i = 0; i < 10; i++) + { + downloads.Add(new DownloadModel() + { + Name = "Downloads " + i, + Comments = "Some comments...\nWith a new line", + Date = DateTime.Now.ToString(), + User = "Roy", + ID = i.ToString(), + }); + } + + IndexViewModel model = new IndexViewModel(); + model.Downloads = downloads; + + return View(model); + } + + [Authorize] + public ActionResult Download(String id) + { + return File(new byte[] { 25, 255, 255 }, System.Net.Mime.MediaTypeNames.Application.Octet,"Machine Studio v1.0.exe"); + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 29cc067d6..b718887af 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -162,11 +162,11 @@ namespace Tango.MachineService.Controllers if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersions)) { var latestVersion = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - Version currentVersion = Version.Parse(request.Version); + Version local_version = Version.Parse(request.Version); - if (latestVersion == null || currentVersion > Version.Parse(latestVersion.Version)) + if (latestVersion == null || local_version > Version.Parse(latestVersion.Version)) { - String newVersionFileName = "Machine Studio Version" + " " + currentVersion.ToString() + ".zip"; + String newVersionFileName = "Machine Studio v" + local_version.ToString() + ".zip"; var manager = new BlobStorageManager(); var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); @@ -175,14 +175,24 @@ namespace Tango.MachineService.Controllers response.Token = Guid.NewGuid().ToString(); response.BlobAddress = blob.GenerateWriteSignature(TimeSpan.FromMinutes(30)); - _pendingUploads.Add(new MachineStudioPendingUpload() + MachineStudioPendingUpload pending_upload = new MachineStudioPendingUpload() { UserGuid = user.Guid, Comments = request.Comments, Token = response.Token, Version = request.Version, BlobName = blob.Name, - }); + }; + + if (request.WithInstaller) + { + String installerVersionFileName = "Machine Studio v" + local_version.ToString() + ".exe"; + var installerBlob = container.CreateEmptyBlob(installerVersionFileName); + response.InstallerBlobAddress = installerBlob.GenerateWriteSignature(TimeSpan.FromMinutes(30)); + pending_upload.InstallerBlobName = installerBlob.Name; + } + + _pendingUploads.Add(pending_upload); } else { @@ -206,7 +216,7 @@ namespace Tango.MachineService.Controllers /// <exception cref="System.ArgumentException">Invalid Token.</exception> [HttpPost] [JwtTokenFilter] - public UploadCompletedResponse NotifyUploadCompleted(UploadCompletedRequest request) + public UploadCompletedResponse NotifyVersionUploadCompleted(UploadCompletedRequest request) { MachineStudioPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); @@ -220,6 +230,7 @@ namespace Tango.MachineService.Controllers { Comments = upload.Comments, BlobName = upload.BlobName, + InstallerBlobName = upload.InstallerBlobName, UserGuid = upload.UserGuid, Version = upload.Version, }); diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 0f36fa040..a2016d4e0 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -190,7 +190,7 @@ namespace Tango.MachineService.Controllers [HttpPost] [JwtTokenFilter] - public CheckForUpdateResponse CheckForUpdate(CheckForUpdateRequest request) + public CheckForUpdateResponse CheckForUpdates(CheckForUpdateRequest request) { CheckForUpdateResponse response = new CheckForUpdateResponse(); @@ -325,11 +325,11 @@ namespace Tango.MachineService.Controllers latestVersion = versions.FirstOrDefault(); } - Version currentVersion = Version.Parse(request.Version); + Version local_version = Version.Parse(request.Version); - if (currentVersion > Version.Parse(latestVersion.Version)) + if (local_version > Version.Parse(latestVersion.Version)) { - String newVersionFileName = $"{machine_version.Name} - Tango Version {currentVersion.ToString()}.tup"; + String newVersionFileName = $"{machine_version.Name} - Tango Version {local_version.ToString()}.tup"; var manager = new BlobStorageManager(); var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); @@ -338,7 +338,7 @@ namespace Tango.MachineService.Controllers response.Token = Guid.NewGuid().ToString(); response.BlobAddress = blob.GenerateWriteSignature(TimeSpan.FromMinutes(30)); - _pendingUploads.Add(new PPCPendingUpload() + PPCPendingUpload pending_upload = new PPCPendingUpload() { UserGuid = user.Guid, Comments = request.Comments, @@ -346,7 +346,17 @@ namespace Tango.MachineService.Controllers Version = request.Version, BlobName = blob.Name, MachineVersionGuid = request.MachineVersionGuid, - }); + }; + + if (request.WithInstaller) + { + String installerVersionFileName = Path.ChangeExtension(newVersionFileName, ".exe"); + var installerBlob = container.CreateEmptyBlob(installerVersionFileName); + response.InstallerBlobAddress = installerBlob.GenerateWriteSignature(TimeSpan.FromMinutes(30)); + pending_upload.InstallerBlobName = installerBlob.Name; + } + + _pendingUploads.Add(pending_upload); } else { @@ -364,7 +374,7 @@ namespace Tango.MachineService.Controllers [HttpPost] [JwtTokenFilter] - public UploadCompletedResponse NotifyUploadCompleted(UploadCompletedRequest request) + public UploadCompletedResponse NotifyVersionUploadCompleted(UploadCompletedRequest request) { PPCPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); @@ -378,9 +388,10 @@ namespace Tango.MachineService.Controllers { Comments = upload.Comments, BlobName = upload.BlobName, + InstallerBlobName = upload.InstallerBlobName, UserGuid = upload.UserGuid, Version = upload.Version, - MachineVersionGuid = upload.MachineVersionGuid + MachineVersionGuid = upload.MachineVersionGuid, }); db.SaveChanges(); |
