aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2018-12-23 12:44:08 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2018-12-23 12:44:08 +0200
commit4e496467dcc8549605917a44263d78cef40f71bb (patch)
tree3e385e90ec94c5f7d590aaa71991b40fcc05df67 /Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
parent5cb09f7732429d15477321e7f748d010ef27c85d (diff)
downloadTango-4e496467dcc8549605917a44263d78cef40f71bb.tar.gz
Tango-4e496467dcc8549605917a44263d78cef40f71bb.zip
Implemented machine studio active directory secure login.
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs31
1 files changed, 19 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,
}