diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-12-23 12:44:08 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-12-23 12:44:08 +0200 |
| commit | 4e496467dcc8549605917a44263d78cef40f71bb (patch) | |
| tree | 3e385e90ec94c5f7d590aaa71991b40fcc05df67 /Software/Visual_Studio/Web/Tango.MachineService/Controllers | |
| parent | 5cb09f7732429d15477321e7f748d010ef27c85d (diff) | |
| download | Tango-4e496467dcc8549605917a44263d78cef40f71bb.tar.gz Tango-4e496467dcc8549605917a44263d78cef40f71bb.zip | |
Implemented machine studio active directory secure login.
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers')
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs | 31 | ||||
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs | 3 |
2 files changed, 22 insertions, 12 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 8225d75e1..8485cd67d 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -14,6 +14,7 @@ using Tango.Core.Cryptography; using Tango.MachineService.Helpers; using Tango.MachineService.Models; using Tango.MachineStudio.Common.Authentication; +using System.Data.Entity; using Tango.MachineStudio.Common.Update; namespace Tango.MachineService.Controllers @@ -191,40 +192,45 @@ namespace Tango.MachineService.Controllers #endregion + [HttpPost] 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); + AuthenticationResult authResult = AzureDirectoryHelper.AuthenticateUser(request.Email, request.Password); 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); + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower()); + + IHashGenerator g = new BasicHashGenerator(); if (user == null) { //Than add the user !! - - IHashGenerator g = new BasicHashGenerator(); - - BL.Entities.User new_user = new User(); + 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.Password = g.Encrypt(request.Password); + new_user.Organization = db.Organizations.Include(x => x.Address).Single(x => x.Name == "Twine"); + new_user.Address = new_user.Organization.Address.Clone(); new_user.Contact = new Contact() { FirstName = authResult.UserInfo.GivenName, LastName = authResult.UserInfo.FamilyName, + FullName = authResult.UserInfo.GivenName + " " + authResult.UserInfo.FamilyName, + Email = request.Email, }; new_user.Roles.Add(db.Roles.Single(x => (Roles)x.Code == Roles.User)); } + else + { + user.Password = g.Encrypt(request.Password); + } + + db.SaveChanges(); } return new LoginResponse() @@ -234,6 +240,7 @@ namespace Tango.MachineService.Controllers Address = Config.DB_ADDRESS, Catalog = Config.DB_CATALOG, Type = Core.DataSourceType.Azure, + IntegratedSecurity = false, UserName = request.Email, Password = request.Password, } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 662883223..68f597fcc 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -108,6 +108,7 @@ namespace Tango.MachineService.Controllers Catalog = Config.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, + IntegratedSecurity = false, Type = DataSourceType.SQLServer, }; @@ -173,6 +174,7 @@ namespace Tango.MachineService.Controllers Catalog = Config.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, + IntegratedSecurity = false, Type = DataSourceType.SQLServer, }; } @@ -249,6 +251,7 @@ namespace Tango.MachineService.Controllers Catalog = Config.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, + IntegratedSecurity = false, Type = DataSourceType.SQLServer, }; } |
