Exemple #1
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;
        }
Exemple #2
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;
        }
Exemple #3
0
 internal UncUser(XmlUser xmluser, DbUser dbuser, ConnectionStringStruct connection)
 {
     xmlUser = xmluser;
     dbUser = dbuser;
     con = connection;
 }