Пример #1
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;
 }
Пример #2
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);
        }
Пример #3
0
 /// <summary>
 /// Gets the user list.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <returns>A list of users available on the db</returns>
 /// <remarks>Documented by Dev05, 2008-09-10</remarks>
 public static IList<UserStruct> GetUserList(ConnectionStringStruct connectionString)
 {
     if (connectionString.Typ == DatabaseType.Web)
     {
         MLifterLearningModulesService webService = new MLifterLearningModulesService();
         webService.Url = connectionString.ConnectionString;
         List<UserStruct> users = new List<UserStruct>();
         foreach (KeyValuePair<string, UserAuthenticationTyp> pair in webService.GetUserList())
             users.Add(new UserStruct(pair.Key, pair.Value));
         return users;
     }
     return GetConnector(connectionString).GetUserList();
 }