diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-23 09:34:03 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-23 09:34:03 +0200 |
| commit | 5bec920df45bb79e5912a97f2d0afc1a849adbd2 (patch) | |
| tree | a0a4a7b62df4bae64b4fb45760f445baad21f4e4 /Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs | |
| parent | e0b0859f62924d38c8cd7ac9975303c4bfb08624 (diff) | |
| download | Tango-5bec920df45bb79e5912a97f2d0afc1a849adbd2.tar.gz Tango-5bec920df45bb79e5912a97f2d0afc1a849adbd2.zip | |
Fixed some issues with observables generator.
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs')
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index ed1a807be..8225d75e1 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -6,10 +7,13 @@ using System.Net.Http; using System.Security.Authentication; using System.Web.Http; using Tango.BL; +using Tango.BL.Builders; using Tango.BL.Entities; using Tango.BL.Enumerations; +using Tango.Core.Cryptography; using Tango.MachineService.Helpers; using Tango.MachineService.Models; +using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Update; namespace Tango.MachineService.Controllers @@ -23,6 +27,8 @@ namespace Tango.MachineService.Controllers _pendingUploads = new List<MachineStudioPendingUpload>(); } + #region Update + [HttpPost] public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request) { @@ -182,5 +188,57 @@ namespace Tango.MachineService.Controllers return new LatestVersionResponse() { Version = version != null ? version.Version : "0.0.0.0" }; } } + + #endregion + + public LoginResponse Login(LoginRequest request) + { + var authContext = new AuthenticationContext("https://login.microsoftonline.com/2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4"); + UserCredential userCredential = new UserCredential(request.Email, request.Password); + AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", "ec612854-7abc-457b-808a-5d0c5ba80c57", userCredential); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + + db.Roles.ToList(); + db.Permissions.ToList(); + db.UsersRoles.ToList(); + db.RolesPermissions.ToList(); + + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); + + if (user == null) + { + //Than add the user !! + + IHashGenerator g = new BasicHashGenerator(); + + BL.Entities.User new_user = new User(); + new_user.Email = request.Email; + new_user.Password = g.Encrypt("Aa123456"); + new_user.Organization = db.Organizations.Single(x => x.Name == "Twine"); + new_user.Address = new Address() { }; + new_user.Contact = new Contact() + { + FirstName = authResult.UserInfo.GivenName, + LastName = authResult.UserInfo.FamilyName, + }; + new_user.Roles.Add(db.Roles.Single(x => (Roles)x.Code == Roles.User)); + } + } + + return new LoginResponse() + { + DataSource = new Core.DataSource() + { + Address = Config.DB_ADDRESS, + Catalog = Config.DB_CATALOG, + Type = Core.DataSourceType.Azure, + UserName = request.Email, + Password = request.Password, + } + }; + } + } } |
