diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-26 10:55:44 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-26 10:55:44 +0300 |
| commit | 6e2fbaffeec9d6e3518ea9706eea107a4f1b348c (patch) | |
| tree | f50b3d8962dd37188061f8f52c1a7aeff1642232 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs | |
| parent | db3dc558ec5fe5f3584081795865cd22f912da7d (diff) | |
| parent | e6704dce7a2b7f6d5f9bbf1b8374cc7f00ea061e (diff) | |
| download | Tango-6e2fbaffeec9d6e3518ea9706eea107a4f1b348c.tar.gz Tango-6e2fbaffeec9d6e3518ea9706eea107a4f1b348c.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs | 43 |
1 files changed, 25 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..c16f76449 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,38 @@ 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()) + { - 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> |
