aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-08-20 19:43:15 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-20 19:43:15 +0300
commit51afc4f6a17383e91a72c2ce060e82604d43c3a8 (patch)
treec0aa029d9864fc8f03b69716a42eda5efe65ccd5 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication
parent2ea6653199844f5607d17a8912eb7a99e2471610 (diff)
downloadTango-51afc4f6a17383e91a72c2ce060e82604d43c3a8.tar.gz
Tango-51afc4f6a17383e91a72c2ce060e82604d43c3a8.zip
Working on new Machine Studio DB.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs44
1 files changed, 26 insertions, 18 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
index 4e5425138..de84e43e8 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
@@ -9,6 +9,7 @@ using Tango.BL.Entities;
using Tango.MachineStudio.Common.Authentication;
using Tango.BL;
using Tango.BL.Enumerations;
+using System.Data.Entity;
namespace Tango.MachineStudio.UI.Authentication
{
@@ -48,32 +49,39 @@ namespace Tango.MachineStudio.UI.Authentication
/// <exception cref="AuthenticationException">Login failed for user " + email</exception>
public User Login(string email, string password)
{
- String hash = User.GetPasswordHash(password);
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
+ db.Configuration.LazyLoadingEnabled = false;
- User user = ObservablesEntitiesAdapter.Instance.Users.SingleOrDefault(x => x.Email.ToLower() == email.ToLower() && x.Password == hash);
+ String hash = User.GetPasswordHash(password);
- if (user == null)
- {
- throw new AuthenticationException("Invalid credentials for " + email);
- }
+ db.Roles.Load();
+ db.Permissions.Load();
+ db.RolesPermissions.Load();
- if (!user.HasPermission(Permissions.RunMachineStudio))
- {
- throw new AuthenticationException("It seems like you do not have sufficient privileges to run Machine Studio. Please contact your administrator.");
- }
+ User user = db.Users
+ .Include(x => x.UsersRoles)
+ .Include(x => x.Organization).SingleOrDefault(x => x.Email.ToLower() == email.ToLower() && x.Password == hash);
- if (user != null)
- {
- using (ObservablesContext db = ObservablesContext.CreateDefault())
+ if (user == null)
+ {
+ throw new AuthenticationException("Invalid credentials for " + email);
+ }
+
+ if (!user.HasPermission(Permissions.RunMachineStudio))
{
- var u = db.Users.Single(x => x.Guid == user.Guid);
- u.LastLogin = DateTime.UtcNow;
+ throw new AuthenticationException("It seems like you do not have sufficient privileges to run Machine Studio. Please contact your administrator.");
+ }
+
+ if (user != null)
+ {
+ user.LastLogin = DateTime.UtcNow;
db.SaveChanges();
}
- }
- CurrentUser = user;
- return user;
+ CurrentUser = user;
+ return user;
+ }
}
/// <summary>