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; using Tango.BL.Entities; using Tango.Core; using Tango.Core.Cryptography; using Tango.Core.DB; using Tango.FSE.Web.Messages; using Tango.MachineService.Filters; using Tango.Web.Controllers; using Tango.Web.Helpers; 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 TokenObject { public String UserGuid { get; set; } } public class PasswordReset { public String ID { get; set; } public String UserGuid { get; set; } public String FullName { get; set; } } public static List PendingPasswordResets { get; set; } static FSEController() { PendingPasswordResets = new List(); } [HttpPost] public LoginResponse Login(LoginRequest request) { User user = null; DataSource dataSource = null; IHashGenerator hash = new BasicHashGenerator(); Version client_version; if (!Version.TryParse(request.Version, out client_version)) { client_version = new Version("1.0.0.0"); } var password = hash.Encrypt(request.Password); using (var db = ObservablesContextHelper.CreateContext()) { user = new UserBuilder(db).Set(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == password).WithRolesAndPermissions().WithDeleted().Build(); if (user == null) { throw new AuthenticationException("Invalid email or password."); } if (user.Deleted) { throw new AuthenticationException("Your account has been disabled. Please contact your administrator."); } user.LastLogin = DateTime.UtcNow; db.SaveChanges(); } SQLServerManager sqlServer = new SQLServerManager(); var accessToken = sqlServer.GetAccessToken(); dataSource = new DataSource() { Address = MachineServiceConfig.DB_ADDRESS, Catalog = MachineServiceConfig.DB_CATALOG, Type = DataSourceType.AccessToken, IntegratedSecurity = false, AccessToken = accessToken.AccessToken, AccessTokenExpiration = accessToken.ExpiresOn.UtcDateTime }; //Return data source return new LoginResponse() { DataSource = dataSource, AccessToken = WebToken.CreateNew(MachineServiceConfig.JWT_TOKEN_SECRET, new TokenObject() { UserGuid = user.Guid, }, DateTime.UtcNow.AddDays(1)).AccessToken, PasswordChangeRequired = user.PasswordChangeRequired }; } [HttpPost] [JwtTokenFilter] public BugReportingInfoResponse GetBugReportInfo(BugReportingInfoRequest request) { return new BugReportingInfoResponse() { CollectionUrl = MachineServiceConfig.TFS_COLLECTION_URL, PersonalToken = MachineServiceConfig.TFS_PERSONAL_TOKEN, UserEmail = MachineServiceConfig.FSE_TFS_USER_EMAIL }; } [HttpPost] [JwtTokenFilter] public DownloadTangoVersionResponse DownloadTangoVersion(DownloadTangoVersionRequest request) { DownloadTangoVersionResponse response = new DownloadTangoVersionResponse(); using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { var tangoVersion = db.TangoVersions.SingleOrDefault(x => x.Guid == request.TangoVersionGuid); if (tangoVersion == null) { throw new ArgumentException("Could not locate the specified Tango version."); } response.Version = tangoVersion.Version; var manager = new BlobStorageManager(); var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); var blob = container.GetBlockBlobReference(tangoVersion.BlobName); response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT)) {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.MachineStudio.Common.Notifications;

namespace Tango.MachineStudio.DB.ViewModels
{
    public class LinearMassDensityUnitsViewVM : DbTableViewModel<LinearMassDensityUnit>
    {
        public LinearMassDensityUnitsViewVM(INotificationProvider notification) : base(notification)
        {
        }
    }
}