private void SetUser(string login)
 {
     using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
     {
         var users = UserSearchHelper.GetUsers(dataContext.Users.Where(c => c.Login == login), true);
         if (users.Length > 0)
         {
             _currentUser = users[0];
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Получить из User объект TestorCoreUser
        /// </summary>
        /// <param name="user">Пользователь</param>
        /// <returns>Пользователь</returns>
        public static TestorCoreUser GetUser(User user)
        {
            var retValue = new TestorCoreUser()
            {
                UserId     = user.UserId,
                LastName   = user.LastName,
                FirstName  = user.FirstName,
                SecondName = user.SecondName,
                StudNumber = user.StudNumber,
                Login      = user.Login
            };

            return(retValue);
        }
Beispiel #3
0
 public void SetSettings(TestorCoreUser user)
 {
     AfinaId     = user.AfinaId;
     Birthday    = user.Birthday;
     Email       = user.Email;
     FirstName   = user.FirstName;
     IsLocalUser = user.IsLocalUser;
     LastName    = user.LastName;
     Login       = user.Login;
     NewPassword = user.NewPassword;
     Password    = user.Password;
     SecondName  = user.SecondName;
     Sex         = user.Sex;
     Status      = user.Status;
     StudNumber  = user.StudNumber;
     UserGroups  = user.UserGroups;
     UserId      = user.UserId;
     UserRole    = user.UserRole;
 }
Beispiel #4
0
        /// <summary>
        /// Получить из User объект TestorCoreUser
        /// </summary>
        /// <param name="user">Пользователь</param>
        /// <returns>Пользователь</returns>
        public static TestorCoreUser GetDetailsUser(User user)
        {
            var retValue = new TestorCoreUser()
            {
                UserId     = user.UserId,
                LastName   = user.LastName,
                FirstName  = user.FirstName,
                SecondName = user.SecondName,
                Login      = user.Login,
                Sex        = user.Sex,
                Status     = (TestorUserStatus)user.Status,
                UserRole   = (TestorUserRole)user.UserRole,
                Email      = user.Email,
                StudNumber = user.StudNumber,
                Birthday   = user.Birthday.HasValue ? user.Birthday.Value : new DateTime(1900, 1, 1)
            };

            return(retValue);
        }
 private void SetAnonymousUser()
 {
     using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
     {
         int userId = -1;
         if (_context != null)
         {
             if (_context.Session["AnonymousCreatTime"] != null)
             {
                 DateTime createTime = (DateTime)_context.Session["AnonymousCreatTime"];
                 if ((DateTime.Now - createTime).TotalHours > 2)
                 {
                     var anonymous = dataContext.AnonymousUsers.Where(c => c.AnonymousUserId == (int)_context.Session["AnonymousUserId"]).First();
                     anonymous.CreateTime = DateTime.Now;
                     dataContext.SubmitChanges();
                     _context.Session["AnonymousUserId"]    = anonymous.AnonymousUserId;
                     _context.Session["AnonymousCreatTime"] = anonymous.CreateTime;
                 }
             }
             if (_context.Session["AnonymousUserId"] == null)
             {
                 AnonymousUser anonymous = new AnonymousUser();
                 dataContext.AnonymousUsers.InsertOnSubmit(anonymous);
                 anonymous.CreateTime = DateTime.Now;
                 dataContext.AnonymousUsers.DeleteAllOnSubmit(dataContext.AnonymousUsers.Where(c => (DateTime.Now - c.CreateTime).TotalHours > 3));
                 dataContext.SubmitChanges();
                 _context.Session["AnonymousUserId"]    = anonymous.AnonymousUserId;
                 _context.Session["AnonymousCreatTime"] = anonymous.CreateTime;
             }
             userId = (int)_context.Session["AnonymousUserId"];
         }
         _currentUser = new TestorCoreUser()
         {
             Login    = "******",
             Status   = TestorUserStatus.InetUser,
             UserId   = userId,
             UserRole = TestorUserRole.Anonymous
         };
     }
 }
Beispiel #6
0
 public static void SetInitalConfiguration()
 {
     using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
     {
         dataContext.SystemSettings.DeleteAllOnSubmit(dataContext.SystemSettings);
         //---------------------------------------------------------------
         SystemSetting anonymousPolicy = new SystemSetting();
         anonymousPolicy.PropertyName  = SystemProperties.ANONYMOUS_POLICY;
         anonymousPolicy.PropertyValue = "-1";
         dataContext.SystemSettings.InsertOnSubmit(anonymousPolicy);
         //---------------------------------------------------------------
         SystemSetting smtpFrom = new SystemSetting();
         smtpFrom.PropertyName  = SystemProperties.SMTP_FROM;
         smtpFrom.PropertyValue = "*****@*****.**";
         dataContext.SystemSettings.InsertOnSubmit(smtpFrom);
         //---------------------------------------------------------------
         SystemSetting smtpServer = new SystemSetting();
         smtpServer.PropertyName  = SystemProperties.SMTP_SERVER;
         smtpServer.PropertyValue = "mail.localhost.ru";
         dataContext.SystemSettings.InsertOnSubmit(smtpServer);
         //---------------------------------------------------------------
         SystemSetting smtpLogin = new SystemSetting();
         smtpLogin.PropertyName  = SystemProperties.SMTP_LOGIN;
         smtpLogin.PropertyValue = "*****@*****.**";
         dataContext.SystemSettings.InsertOnSubmit(smtpLogin);
         //---------------------------------------------------------------
         SystemSetting smtpPassword = new SystemSetting();
         smtpPassword.PropertyName  = SystemProperties.SMTP_PASSWORD;
         smtpPassword.PropertyValue = "password";
         dataContext.SystemSettings.InsertOnSubmit(smtpPassword);
         //---------------------------------------------------------------
         SystemSetting allowIntranet = new SystemSetting();
         allowIntranet.PropertyName  = SystemProperties.SESSION_ALLOW_INTRANET;
         allowIntranet.PropertyValue = SystemProperties.SESSION_TRUE;
         dataContext.SystemSettings.InsertOnSubmit(allowIntranet);
         //---------------------------------------------------------------
         SystemSetting allowPublic = new SystemSetting();
         allowPublic.PropertyName  = SystemProperties.SESSION_ALLOW_PUBLIC;
         allowPublic.PropertyValue = SystemProperties.SESSION_TRUE;
         dataContext.SystemSettings.InsertOnSubmit(allowPublic);
         //---------------------------------------------------------------
         SystemSetting localNetworks = new SystemSetting();
         localNetworks.PropertyName  = SystemProperties.SESSION_LOCAL_NETWORKS;
         localNetworks.PropertyValue = "192.168.;10.;127.0";
         dataContext.SystemSettings.InsertOnSubmit(localNetworks);
         //---------------------------------------------------------------
         SystemSetting regMail = new SystemSetting();
         regMail.PropertyName  = SystemProperties.REGISTER_MAIL;
         regMail.PropertyValue = "Ваш логин: {0}\nДля активации аккаунта пройдите по ссылке: {1}";
         dataContext.SystemSettings.InsertOnSubmit(regMail);
         //---------------------------------------------------------------
         SystemSetting restoreMail = new SystemSetting();
         restoreMail.PropertyName  = SystemProperties.RESTORE_MAIL;
         restoreMail.PropertyValue = "Ваш логин: {0}\nДля восстановления пароля пройдите по ссылке: {1}";
         dataContext.SystemSettings.InsertOnSubmit(restoreMail);
         //---------------------------------------------------------------
         TestorCoreUser admin = new TestorCoreUser()
         {
             Birthday   = DateTime.Now,
             Email      = "",
             FirstName  = "Администратор",
             LastName   = "Системный",
             Login      = "******",
             Password   = "******",
             Sex        = true,
             Status     = TestorUserStatus.InetUser,
             StudNumber = String.Empty,
             UserRole   = TestorUserRole.Administrator,
             UserGroups = new TestorTreeItem[] { }
         };
         User           testorUser = new User();
         UserManagement um         = new UserManagement();
         um.SetUserSettings(testorUser, admin, true, true, dataContext);
         testorUser.UserRole = (short)TestorUserRole.Administrator;
         testorUser.Status   = (short)TestorUserStatus.InetUser;
         if (dataContext.Users.Where(c => c.Login == admin.Login).Count() == 0)
         {
             dataContext.Users.InsertOnSubmit(testorUser);
         }
         dataContext.SubmitChanges();
     }
 }
Beispiel #7
0
 public TestorCoreUser(TestorCoreUser user)
 {
     SetSettings(user);
 }
Beispiel #8
0
 public static void Login(string userName, string password, string server, int sendTimeOut, IServerProvider provider)
 {
     if (_isLogin)
     {
         return;
     }
     NullClients();
     _provider = provider;
     if (provider != null)
     {
         if (!_provider.ValidateCurrentUser(userName, password))
         {
             throw new Exception("Неверное имя пользователя и/или пароль.");
         }
     }
     else
     {
         _userName = userName;
         _password = password;
         _server   = server.ToLower();
         if (_server[_server.Length - 1] == '/')
         {
             _server = _server.Remove(_server.Length - 1, 1);
         }
         if (_server.StartsWith("http://"))
         {
             _binding = new WSHttpBinding(SecurityMode.Message);
             WSHttpBinding currentBinding = (_binding as WSHttpBinding);
             currentBinding.TransactionFlow = false;
             currentBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
             currentBinding.MaxBufferPoolSize           = int.MaxValue;
             currentBinding.MaxReceivedMessageSize      = int.MaxValue;
             currentBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
             currentBinding.SendTimeout = TimeSpan.FromSeconds(5);
             currentBinding.OpenTimeout = TimeSpan.FromHours(10);
             _prefix = "http://";
         }
         else
         {
             _binding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential, true);
             NetTcpBinding currentBinding = (_binding as NetTcpBinding);
             currentBinding.TransactionFlow = false;
             currentBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
             currentBinding.MaxBufferPoolSize           = int.MaxValue;
             currentBinding.MaxReceivedMessageSize      = int.MaxValue;
             currentBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
             currentBinding.SendTimeout = TimeSpan.FromSeconds(5);
             currentBinding.OpenTimeout = TimeSpan.FromHours(10);
             _prefix = "net.tcp://";
         }
         if (_server.StartsWith(_prefix))
         {
             _server = _server.Replace(_prefix, String.Empty);
         }
     }
     //---------------------------------------------------------------------------------------------------------
     _currentUser = HelperService.GetServerVersion(TestingSystem.ProtocolVersionString);
     if (provider == null)
     {
         _binding.SendTimeout = TimeSpan.FromSeconds(sendTimeOut);
     }
     _isLogin = true;
 }