예제 #1
0
파일: LoginForm.cs 프로젝트: hmehr/OSS
        public static UserStruct? OpenLoginForm(UserStruct userStruct, ConnectionStringStruct connection)
        {
            LoginForm loginForm = new LoginForm();

            //select a server icon depending on connection type
            switch (connection.Typ)
            {
                case DatabaseType.Xml:
                case DatabaseType.Unc:
                case DatabaseType.MsSqlCe:
                    loginForm.ServerIcon = Resources.learning_48;
                    break;
                case DatabaseType.PostgreSQL:
                case DatabaseType.Web:
                    loginForm.ServerIcon = Resources.world_48;
                    break;
                default:
                    loginForm.ServerIcon = Resources.login_48;
                    break;
            }

            UserStruct? newUser = loginForm.AuthentificationControl.Initialize(connection, userStruct);

            if (newUser.HasValue)
                return newUser;

            if (loginForm.ShowDialog() == DialogResult.OK)
                return loginForm.SelectedUser;
            else
                return null;
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WebUser"/> class.
 /// </summary>
 /// <param name="userId">The user id.</param>
 /// <param name="authenticationStruct">The authentication struct.</param>
 /// <param name="connection">The connection.</param>
 /// <param name="service">The service.</param>
 /// <param name="parent">The parent.</param>
 /// <remarks>Documented by Dev05, 2009-03-06</remarks>
 internal WebUser(int userId, UserStruct authenticationStruct, ConnectionStringStruct connection, MLifterLearningModulesService service, ParentClass parent)
 {
     id = userId;
     authStruct = authenticationStruct;
     ConnectionString = connection;
     WebService = service;
     this.parent = parent;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WebUser"/> class.
 /// </summary>
 /// <param name="userId">The user id.</param>
 /// <param name="authenticationStruct">The authentication struct.</param>
 /// <param name="connection">The connection.</param>
 /// <param name="service">The service.</param>
 /// <param name="parent">The parent.</param>
 /// <remarks>Documented by Dev05, 2009-03-06</remarks>
 internal WebUser(int userId, UserStruct authenticationStruct, ConnectionStringStruct connection, MLifterLearningModulesService service, ParentClass parent)
 {
     id               = userId;
     authStruct       = authenticationStruct;
     ConnectionString = connection;
     WebService       = service;
     this.parent      = parent;
 }
예제 #4
0
        /// <summary>
        /// Gets the web user.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2009-03-06</remarks>
        private IUser GetWebUser(ConnectionStringStruct connection)
        {
            MLifterLearningModulesService webService = new MLifterLearningModulesService();

            webService.Url             = connection.ConnectionString;
            webService.CookieContainer = new System.Net.CookieContainer();

            int        uid  = -1;
            UserStruct?user = null;

            do
            {
                user = getLogin.Invoke(user.HasValue ? user.Value : new UserStruct(), new ConnectionStringStruct(DatabaseType.Web, connection.ConnectionString, true));

                if (!user.HasValue)
                {
                    break;
                }
                else if (user.Value.AuthenticationType != UserAuthenticationTyp.ListAuthentication)
                {
                    uid = webService.Login(user.Value.UserName, user.Value.Password);
                }
                else
                {
                    uid = webService.Login(user.Value.UserName, string.Empty);
                }

                UserStruct lastUser = user.Value;
                try { Methods.CheckUserId(uid); lastUser.LastLoginError = LoginError.NoError; }
                catch (InvalidUsernameException) { lastUser.LastLoginError = LoginError.InvalidUsername; }
                catch (InvalidPasswordException) { lastUser.LastLoginError = LoginError.InvalidPassword; }
                catch (WrongAuthenticationException) { lastUser.LastLoginError = LoginError.WrongAuthentication; }
                catch (ForbiddenAuthenticationException) { lastUser.LastLoginError = LoginError.ForbiddenAuthentication; }
                catch (UserSessionCreationException) { lastUser.LastLoginError = LoginError.AlreadyLoggedIn; }
                user = lastUser;
            }while (user.HasValue && uid < 0);

            if (!user.HasValue)
            {
                throw new NoValidUserException();
            }

            return(new WebUser(uid, user.Value, connection, webService, Parent));
        }
예제 #5
0
        /// <summary>
        /// Gets the db user.
        /// </summary>
        /// <param name="connection">A struct containing the connection info.</param>
        /// <param name="errorMessageDelegate">A delegate used to handle login errors.</param>
        /// <param name="standAlone">if set to <c>true</c> [stand alone].</param>
        /// <returns>A DB user which implements IUser</returns>
        /// <remarks>Documented by Dev03, 2008-11-25</remarks>
        private IUser GetDbUser(ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate, bool standAlone)
        {
            CheckConnection(connection);

            UserAuthenticationTyp authTyp = connector.GetAllowedAuthenticationModes().Value;

            bool       ldUserChecked = false;
            IUser      dbUser        = null;
            UserStruct?userStruct    = null;

            while (dbUser == null)
            {
                if (!IsWebService && !ldUserChecked && (authTyp & UserAuthenticationTyp.LocalDirectoryAuthentication) == UserAuthenticationTyp.LocalDirectoryAuthentication)
                {
                    ldUserChecked = true;
                    try { userStruct = GetLocalDirectoryUser(); }
                    catch (NoValidUserException) { userStruct = null; }
                }
                else
                {
                    userStruct = getLogin.Invoke(userStruct.HasValue ? userStruct.Value : new UserStruct(string.Empty, authTyp), ConnectionString);
                }

                if (userStruct.HasValue)
                {
                    UserStruct lastUser = userStruct.Value;
                    try { dbUser = new DbUser(userStruct, Parent, connection, errorMessageDelegate, standAlone); lastUser.LastLoginError = LoginError.NoError; }
                    catch (InvalidUsernameException) { lastUser.LastLoginError = LoginError.InvalidUsername; }
                    catch (InvalidPasswordException) { lastUser.LastLoginError = LoginError.InvalidPassword; }
                    catch (WrongAuthenticationException) { lastUser.LastLoginError = LoginError.WrongAuthentication; }
                    catch (ForbiddenAuthenticationException) { lastUser.LastLoginError = LoginError.ForbiddenAuthentication; }
                    catch (UserSessionCreationException) { lastUser.LastLoginError = LoginError.AlreadyLoggedIn; }
                    userStruct = lastUser;
                }
                else
                {
                    throw new NoValidUserException();
                }
            }

            return(dbUser);
        }
예제 #6
0
 /// <summary>
 /// Gets the admin user.
 /// </summary>
 /// <param name="userStr">The user struct.</param>
 /// <param name="con">The connectionStringStruct.</param>
 /// <returns>The user struct.</returns>
 /// <remarks>Documented by Dev08</remarks>
 public static UserStruct? GetAdminUser(UserStruct userStr, ConnectionStringStruct con)
 {
     UserStruct userStruct = new UserStruct("admin", "admin", UserAuthenticationTyp.FormsAuthentication, false);
     userStruct.CloseOpenSessions = true;
     return userStruct;
 }
예제 #7
0
 internal UserStruct? GetUser(UserStruct user, ConnectionStringStruct connection)
 {
     if (authenticationUsers.ContainsKey(connection.ConnectionString) && (!defaultUserSubmitted.ContainsKey(connection) || !defaultUserSubmitted[connection]))
     {
         defaultUserSubmitted[connection] = true;
         return authenticationUsers[connection.ConnectionString];
     }
     else
     {
         UserStruct? newUser = LoginForm.OpenLoginForm(user, connection);
         if (newUser.HasValue)
             authenticationUsers[connection.ConnectionString] = newUser.Value;
         return newUser;
     }
 }
예제 #8
0
        private UserStruct? GetInvalidFormsUser3(UserStruct userStr, ConnectionStringStruct con)
        {
            if (!invalidFormsUser3Received)
                invalidFormsUser3Received = true;
            else
            {
                LoginError err = userStr.LastLoginError;
                if (err == LoginError.InvalidUsername || err == LoginError.InvalidPassword)
                    throw new NoValidUserException();
                else
                    throw new Exception("Invalide user not recognised");
            }

            System.Security.SecureString SecurePassword = new System.Security.SecureString();
            return new UserStruct("alex", string.Empty, UserAuthenticationTyp.FormsAuthentication, true);
        }
예제 #9
0
        /// <summary>
        /// Initializes the control with the specified connection (name).
        /// </summary>
        /// <param name="connectionName">Name of the connection.</param>
        /// <param name="connection">The connection.</param>
        /// <remarks>Documented by Dev05, 2009-03-03</remarks>
        public UserStruct? Initialize(ConnectionStringStruct connection, UserStruct lastUser)
        {
            ConnectionString = LearningModulesIndex.ConnectionsHandler.GetConnectionFromConnectionStringStruct(connection);
            if (ConnectionString == null)
            {
                LearningModulesIndexEntry entry = RecentLearningModules.GetRecentModules().Find(m => m.ConnectionString.ConnectionString == connection.ConnectionString);
                if (entry != null)
                    ConnectionString = entry.Connection;
            }

            ConnectionName = connection.Typ != DatabaseType.MsSqlCe ? (ConnectionString != null ? ConnectionString.Name : Resources.NO_CONNECTION_NAME) : Path.GetFileName(connection.ConnectionString);
            Connection = connection;

            if (connection.Typ == DatabaseType.MsSqlCe)
                comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDownList;
            else
                comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDown;

            #region error handling
            switch (lastUser.LastLoginError)
            {
                case LoginError.AlreadyLoggedIn:
                    EmulatedTaskDialog taskDialog = new EmulatedTaskDialog();
                    taskDialog.Title = Resources.TASKDIALOG_KICK_TITLE;
                    taskDialog.MainInstruction = string.Format(Resources.TASKDIALOG_KICK_MAIN, lastUser.UserName);
                    taskDialog.Content = string.Format(Resources.TASKDIALOG_KICK_CONTENT, ConnectionName);
                    taskDialog.CommandButtons = Resources.TASKDIALOG_KICK_BUTTONS;

                    taskDialog.VerificationText = string.Empty;
                    taskDialog.VerificationCheckBoxChecked = false;
                    taskDialog.Buttons = TaskDialogButtons.None;
                    taskDialog.MainIcon = TaskDialogIcons.Warning;
                    taskDialog.FooterIcon = TaskDialogIcons.Warning;
                    taskDialog.MainImages = new Image[] { Resources.system_log_out, Resources.processStopBig };
                    taskDialog.HoverImages = new Image[] { Resources.system_log_out, Resources.processStopBig };
                    taskDialog.CenterImages = true;
                    taskDialog.BuildForm();
                    DialogResult dialogResult = taskDialog.ShowDialog();

                    if (dialogResult != DialogResult.Cancel && taskDialog.CommandButtonClickedIndex == 0)
                    {
                        lastUser.CloseOpenSessions = true;
                        return lastUser;
                    }
                    else
                        AllowAutoLogin = false;
                    break;
                case LoginError.InvalidUsername:
                    TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_USER_TITLE, Resources.TASKDIALOG_WRONG_USER_MAIN, Resources.TASKDIALOG_WRONG_USER_CONTENT,
                        TaskDialogButtons.OK, TaskDialogIcons.Error);
                    break;
                case LoginError.InvalidPassword:
                    TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_PASSWORD_TITLE, Resources.TASKDIALOG_WRONG_PASSWORD_MAIN, Resources.TASKDIALOG_WRONG_PASSWORD_CONTENT,
                        TaskDialogButtons.OK, TaskDialogIcons.Error);
                    break;
                case LoginError.WrongAuthentication:
                case LoginError.ForbiddenAuthentication:
                    TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_TITLE, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_MAIN, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_CONTENT,
                        TaskDialogButtons.OK, TaskDialogIcons.Error);
                    break;
                case LoginError.NoError:
                default:
                    break;
            }
            #endregion

            labelHeader.Text = string.Format(Resources.LOGIN_HEADER_TEXT, ConnectionName);

            buttonCancel.Enabled = connection.Typ != DatabaseType.MsSqlCe;

            try
            {
                SetListItems();
                UpdateSelection(false);

                #region persitancy
                Stream outputStream = null;
                try
                {
                    BinaryFormatter binary = new BinaryFormatter();
                    IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForAssembly();
                    outputStream = new IsolatedStorageFileStream(Settings.Default.AuthDataFile, FileMode.Open, storageFile);
                    outputStream = new CryptoStream(outputStream, Rijndael.Create().CreateDecryptor(Encoding.Unicode.GetBytes("mlifter"), Encoding.Unicode.GetBytes("omicron")), CryptoStreamMode.Read);
                    persitancyData = binary.Deserialize(outputStream) as Dictionary<string, SavedUserData>;
                    outputStream.Close();
                }
                catch { persitancyData = new Dictionary<string, SavedUserData>(); }
                finally
                {
                    if (outputStream != null)
                        outputStream.Close();
                }

                if (ConnectionString != null && persitancyData.ContainsKey(ConnectionString.ConnectionString))
                {
                    SavedUserData data = persitancyData[ConnectionString.ConnectionString];
                    if (data.SaveUsername)
                    {
                        checkBoxSaveUsername.Checked = true;
                        ShowOptions = true;
                        comboBoxUserSelection.Text = data.Username;
                        if (data.SavePassword)
                        {
                            checkBoxSavePassword.Checked = true;
                            textBoxPassword.Text = data.Password;
                            textBoxPassword.Tag = PasswordType.Hashed;
                            if (data.AutoLogin)
                            {
                                checkBoxAutoLogin.Checked = true;
                                if (AllowAutoLogin && !MLifter.BusinessLayer.User.PreventAutoLogin)
                                {
                                    Login();
                                    return GetActualUser();
                                }
                            }
                            else
                                checkBoxAutoLogin.Checked = false;
                        }
                        else
                            checkBoxSavePassword.Checked = false;
                    }
                    else
                    {
                        checkBoxSaveUsername.Checked = false;
                        ShowOptions = false;
                    }
                }
                #endregion

                comboBoxUserSelection.Focus();

                if (lastUser.LastLoginError != LoginError.NoError)
                {
                    comboBoxUserSelection.Text = lastUser.UserName;
                    textBoxPassword.Text = string.Empty;
                    textBoxPassword.Tag = PasswordType.ClearText;
                }

                LoginError = lastUser.LastLoginError;
            }
            catch (ConnectionNotSetException ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            return null;
        }
예제 #10
0
        private UserStruct? GetLoginErrorMethod(UserStruct u, ConnectionStringStruct c)
        {
            if (!userSubmitted)
            {
                userSubmitted = true;
                UserStruct user = MLifterTest.DAL.TestInfrastructure.GetTestUser(u, c).Value;
                user.CloseOpenSessions = false;
                return user;
            }

            LoginError err = u.LastLoginError;

            if (err == LoginError.AlreadyLoggedIn)
                throw new DoubleLoginException();
            else
                throw new Exception("The supposed Error 'AlreadyLoggedIn' hasn't occurred!");
        }
예제 #11
0
 public static UserStruct? GetUserAdmin(UserStruct userStr, ConnectionStringStruct con)
 {
     return new UserStruct("admin", "admin", UserAuthenticationTyp.FormsAuthentication, false, true);
 }
예제 #12
0
 private UserStruct? GetUserTeacher(UserStruct userStr, ConnectionStringStruct con)
 {
     return new UserStruct("Teacher", "teacher", UserAuthenticationTyp.FormsAuthentication, false, true);
 }
예제 #13
0
        private UserStruct? GetInvalidListUser2(UserStruct userStr, ConnectionStringStruct con)
        {
            if (!invalidListUser2Received)
                invalidListUser2Received = true;
            else
            {
                LoginError err = userStr.LastLoginError;
                if (err == LoginError.WrongAuthentication)
                    throw new NoValidUserException();
                else
                    throw new Exception("Invalide user not recognised");
            }

            return new UserStruct("alex", UserAuthenticationTyp.ListAuthentication);
        }
예제 #14
0
        private UserStruct? GetInvalidLdUser(UserStruct userStr, ConnectionStringStruct con)
        {
            if (!invalidLdUserReceived)
                invalidLdUserReceived = true;
            else
            {
                LoginError err = userStr.LastLoginError;
                if (err == LoginError.ForbiddenAuthentication)
                    throw new NoValidUserException();
                else
                    throw new Exception("Invalide authentication not recognised");
            }

            return new UserStruct("invalid", UserAuthenticationTyp.LocalDirectoryAuthentication);
        }
예제 #15
0
 /// <summary>
 /// Gets the testuser.
 /// </summary>
 /// <param name="userStr">The user struct.</param>
 /// <param name="con">The connectionStringStruct.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev08</remarks>
 public static UserStruct? GetTestUser(UserStruct userStr, ConnectionStringStruct con)
 {
     UserStruct userStruct = new UserStruct("testuser", UserAuthenticationTyp.ListAuthentication);
     userStruct.CloseOpenSessions = true;
     return userStruct;
 }
예제 #16
0
파일: CopyToTest.cs 프로젝트: hmehr/OSS
 private UserStruct? GetUser(UserStruct user, ConnectionStringStruct connection)
 {
     return authenticationUsers[connection.ConnectionString];
 }
예제 #17
0
        private void UpdatePercistancyData(UserStruct user)
        {
            if (ConnectionString == null)
                return;

            persitancyData[ConnectionString.ConnectionString] = new SavedUserData(checkBoxSaveUsername.Checked, checkBoxSavePassword.Checked, checkBoxAutoLogin.Checked,
                checkBoxSaveUsername.Checked ? comboBoxUserSelection.Text : string.Empty,
                checkBoxSavePassword.Checked ? user.AuthenticationType == UserAuthenticationTyp.ListAuthentication || textBoxPassword.Text.Length <= 0 ? string.Empty :
                    (PasswordType)textBoxPassword.Tag == PasswordType.Hashed ? textBoxPassword.Text : Methods.GetHashedPassword(textBoxPassword.Text) : string.Empty);

            Stream outputStream = null;
            try
            {
                BinaryFormatter binary = new BinaryFormatter();
                IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForAssembly();
                outputStream = new IsolatedStorageFileStream(Settings.Default.AuthDataFile, FileMode.Create, storageFile);
                outputStream = new CryptoStream(outputStream, Rijndael.Create().CreateEncryptor(Encoding.Unicode.GetBytes("mlifter"), Encoding.Unicode.GetBytes("omicron")), CryptoStreamMode.Write);
                binary.Serialize(outputStream, persitancyData);
            }
            catch (Exception e) { Trace.WriteLine(e.ToString()); }
            finally
            {
                if (outputStream != null)
                    outputStream.Close();
            }
        }
예제 #18
0
 private static UserStruct? GetUser(UserStruct user, ConnectionStringStruct connection)
 {
     if (!MLifter.BusinessLayer.User.PreventAutoLogin && authenticationUsers.ContainsKey(connection.ConnectionString) && (!defaultUserSubmitted.ContainsKey(connection) || !defaultUserSubmitted[connection]))
     {
         defaultUserSubmitted[connection] = true;
         return authenticationUsers[connection.ConnectionString];
     }
     else
     {
         UserStruct? newUser = LoginForm.OpenLoginForm(user, connection);
         if (newUser.HasValue)
             authenticationUsers[connection.ConnectionString] = newUser.Value;
         return newUser;
     }
 }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserLoginEventArgs"/> class.
 /// </summary>
 /// <param name="selectedUser">The selected user.</param>
 /// <remarks>Documented by Dev05, 2009-03-03</remarks>
 public UserLoginEventArgs(UserStruct selectedUser)
 {
     SelectedUser = selectedUser;
 }
예제 #20
0
        /// <summary>
        /// Gets the Compact Edition user.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2009-01-13</remarks>
        private IUser GetCeUser(ConnectionStringStruct connection)
        {
            int               userId;
            UserStruct?       userStruct = null;
            List <UserStruct> users      = connector.GetUserList() as List <UserStruct>;

            if (connection.SyncType != SyncType.NotSynchronized)
            {
                if (connection.SyncType == SyncType.FullSynchronized && connection.ServerUser == null)
                {
                    if (users.Count == 2)
                    {
                        userStruct = users[1];
                        userId     = connector.LoginListUser(userStruct.Value.UserName, Guid.NewGuid(), true, true);
                    }
                    else
                    {
                        UserStruct?us = getLogin.Invoke(new UserStruct(Resources.CREATE_NEW_USER, UserAuthenticationTyp.ListAuthentication), connection);
                        if (!us.HasValue || us.Value.UserName == Resources.CREATE_NEW_USER)
                        {
                            userId = connector.LoginFormsUser(CurrentWindowsUserName, CurrentWindowsUserId, new Guid(), true, true);
                        }
                        else
                        {
                            userId = connector.LoginLocalDirectoryUser(us.Value.UserName, CurrentWindowsUserId, new Guid(), true, true);
                        }
                    }
                }
                else
                {
                    userStruct = users.Find(u => u.UserName == connection.ServerUser.UserName);
                    userId     = connector.LoginListUser(userStruct.Value.UserName, connection.ServerUser.ConnectionString.SessionId, true, true);
                }
            }
            else if (Methods.IsOnMLifterStick(connection.ConnectionString))
            {
                if (users.Exists(u => u.UserName == Resources.StickUserName))
                {
                    userStruct = users.Find(u => u.UserName == Resources.StickUserName);
                    userId     = connector.LoginListUser(Resources.StickUserName, new Guid(), true, true);
                }
                else
                {
                    userStruct = new UserStruct(Resources.StickUserName, UserAuthenticationTyp.ListAuthentication);
                    userId     = connector.LoginFormsUser(Resources.StickUserName, string.Empty, new Guid(), true, true);
                }
            }
            else if (users.Exists(u => u.Identifier == CurrentWindowsUserId))
            {
                userStruct = users.Find(u => u.Identifier == CurrentWindowsUserId);
                userId     = connector.LoginListUser(userStruct.Value.UserName, new Guid(), true, true);
            }
            else if (users.Count == 1)
            {
                userId = connector.LoginFormsUser(CurrentWindowsUserName, CurrentWindowsUserId, new Guid(), true, true);
            }
            else
            {
                UserStruct?us = getLogin.Invoke(new UserStruct(Resources.CREATE_NEW_USER, UserAuthenticationTyp.ListAuthentication), connection);
                if (!us.HasValue || us.Value.UserName == Resources.CREATE_NEW_USER)
                {
                    userId = connector.LoginFormsUser(CurrentWindowsUserName, CurrentWindowsUserId, new Guid(), true, true);
                }
                else
                {
                    userId = connector.LoginLocalDirectoryUser(us.Value.UserName, CurrentWindowsUserId, new Guid(), true, true);
                }
            }

            if (!userStruct.HasValue)
            {
                userStruct = new UserStruct(CurrentWindowsUserName, UserAuthenticationTyp.ListAuthentication);
            }

            DbUser newUser = new DbUser(userStruct, Parent, connection, errMsgDel, true);

            newUser.SetId(userId);
            return(newUser);
        }
예제 #21
0
 public static UserStruct? GetUser(UserStruct user, ConnectionStringStruct connection)
 {
     if (authenticationUsers.ContainsKey(connection.ConnectionString) && user.LastLoginError == LoginError.NoError)
     {
         return authenticationUsers[connection.ConnectionString];
     }
     else
     {
         UserStruct? newUser = MLifter.Controls.LoginForm.OpenLoginForm(user, connection);
         if (newUser.HasValue)
         {
             authenticationUsers[connection.ConnectionString] = newUser.Value;
         }
         return newUser;
     }
 }
예제 #22
0
        /// <summary>
        /// Gets the Compact Edition user.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2009-01-13</remarks>
        private IUser GetCeUser(ConnectionStringStruct connection)
        {
            int userId;
            UserStruct? userStruct = null;
            List<UserStruct> users = connector.GetUserList() as List<UserStruct>;
            if (connection.SyncType != SyncType.NotSynchronized)
            {
                if (connection.SyncType == SyncType.FullSynchronized && connection.ServerUser == null)
                {
                    if (users.Count == 2)
                    {
                        userStruct = users[1];
                        userId = connector.LoginListUser(userStruct.Value.UserName, Guid.NewGuid(), true, true);
                    }
                    else
                    {
                        UserStruct? us = getLogin.Invoke(new UserStruct(Resources.CREATE_NEW_USER, UserAuthenticationTyp.ListAuthentication), connection);
                        if (!us.HasValue || us.Value.UserName == Resources.CREATE_NEW_USER)
                            userId = connector.LoginFormsUser(CurrentWindowsUserName, CurrentWindowsUserId, new Guid(), true, true);
                        else
                            userId = connector.LoginLocalDirectoryUser(us.Value.UserName, CurrentWindowsUserId, new Guid(), true, true);
                    }
                }
                else
                {
                    userStruct = users.Find(u => u.UserName == connection.ServerUser.UserName);
                    userId = connector.LoginListUser(userStruct.Value.UserName, connection.ServerUser.ConnectionString.SessionId, true, true);
                }
            }
            else if (Methods.IsOnMLifterStick(connection.ConnectionString))
            {
                if (users.Exists(u => u.UserName == Resources.StickUserName))
                {
                    userStruct = users.Find(u => u.UserName == Resources.StickUserName);
                    userId = connector.LoginListUser(Resources.StickUserName, new Guid(), true, true);
                }
                else
                {
                    userStruct = new UserStruct(Resources.StickUserName, UserAuthenticationTyp.ListAuthentication);
                    userId = connector.LoginFormsUser(Resources.StickUserName, string.Empty, new Guid(), true, true);
                }
            }
            else if (users.Exists(u => u.Identifier == CurrentWindowsUserId))
            {
                userStruct = users.Find(u => u.Identifier == CurrentWindowsUserId);
                userId = connector.LoginListUser(userStruct.Value.UserName, new Guid(), true, true);
            }
            else if (users.Count == 1)
                userId = connector.LoginFormsUser(CurrentWindowsUserName, CurrentWindowsUserId, new Guid(), true, true);
            else
            {
                UserStruct? us = getLogin.Invoke(new UserStruct(Resources.CREATE_NEW_USER, UserAuthenticationTyp.ListAuthentication), connection);
                if (!us.HasValue || us.Value.UserName == Resources.CREATE_NEW_USER)
                    userId = connector.LoginFormsUser(CurrentWindowsUserName, CurrentWindowsUserId, new Guid(), true, true);
                else
                    userId = connector.LoginLocalDirectoryUser(us.Value.UserName, CurrentWindowsUserId, new Guid(), true, true);
            }

            if (!userStruct.HasValue)
                userStruct = new UserStruct(CurrentWindowsUserName, UserAuthenticationTyp.ListAuthentication);

            DbUser newUser = new DbUser(userStruct, Parent, connection, errMsgDel, true);
            newUser.SetId(userId);
            return newUser;
        }
예제 #23
0
        private UserStruct? GetInvalidFormsUser2(UserStruct userStr, ConnectionStringStruct con)
        {
            if (!invalidFormsUser2Received)
                invalidFormsUser2Received = true;
            else
            {
                LoginError err = userStr.LastLoginError;
                if (err == LoginError.WrongAuthentication)
                    throw new NoValidUserException();
                else
                    throw new Exception("Invalide authentication not recognised");
            }

            return new UserStruct("testuser", string.Empty, UserAuthenticationTyp.FormsAuthentication, true);
        }