Esempio n. 1
0
        public bool AssignRightsToUser(string username, ArrayList rights)
        {
            bool ret = true;

            try
            {
                User usr = User.LoadByUsername(username);
                foreach (string right in rights)
                {
                    if (!usr.HasRight(right))
                    {
                        usr.AssignRight(right);
                    }
                }
                List <UserRight> tmp = new List <UserRight>(usr.Rights);
                foreach (UserRight right in tmp)
                {
                    if (!rights.Contains(right.Name))
                    {
                        usr.RemoveRight(right.Name);
                    }
                }
                usr.Update();
            }
            catch (Exception e)
            {
                EventController.TriggerEvent(new ErrorOccuredEvent(e));
                Log.Error(e);
                ret = false;
            }
            return(ret);
        }
Esempio n. 2
0
        internal static void DisableUser(string userName)
        {
            User usr = LoadByUsername(userName);

            if (usr != null)
            {
                usr.Disabled = true;
                usr.Update();
            }
        }
Esempio n. 3
0
        internal static void LockUser(string userName)
        {
            User usr = LoadByUsername(userName);

            if (usr != null)
            {
                usr.Locked = true;
                usr.Update();
            }
        }
Esempio n. 4
0
 public bool UpdateUserPassword(string username, string newpass)
 {
     try
     {
         User usr = User.LoadByUsername(username);
         usr.SetPassword(newpass, Constants.HTTP_AUTH_REALM);
         usr.Update();
     }
     catch (Exception e)
     {
         EventController.TriggerEvent(new ErrorOccuredEvent(e));
         Log.Error(e);
         return(false);
     }
     return(true);
 }
Esempio n. 5
0
        public static UserRight CreateRight(string name)
        {
            Log.Trace("Creating UserRight " + name);
            Connection conn = ConnectionPoolManager.GetConnection(typeof(UserRight));

            Log.Trace("Checking is UserRight " + name + " already exists");
            List <Org.Reddragonit.Dbpro.Structure.Table> tmp = conn.Select(typeof(UserRight),
                                                                           new SelectParameter[] { new EqualParameter("Name", name) });
            UserRight ret = null;

            if (tmp.Count > 0)
            {
                Log.Trace("UserRight " + name + " already exists in the database");
                ret = (UserRight)tmp[0];
            }
            else
            {
                Log.Trace("UserRight " + name + " does not exists in the database, adding it now");
                ret      = new UserRight();
                ret.Name = name;
                ret      = (UserRight)conn.Save(ret);
                conn.Commit();
                User u = User.LoadByUsername("admin");
                if (u != null)
                {
                    bool found = false;
                    foreach (UserRight ur in u.Rights)
                    {
                        if (ur.Name == ret.Name)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        List <UserRight> rights = new List <UserRight>(u.Rights);
                        rights.Add(ret);
                        u.Rights = rights.ToArray();
                        u.Update();
                    }
                }
            }
            conn.CloseConnection();
            return(ret);
        }
 public static void PostAuthenticationFailure(HttpRequest request, string username)
 {
     _loginCount++;
     if (_loginCount >= _maxAttempts)
     {
         EventController.TriggerEvent(new UserLoginEvent(username, ((IPEndPoint)request.Client).Address, UserLoginEvent.LoginEventTypes.ATTEMPTS_EXCEEDED));
         User usr = User.LoadByUsername(username);
         if (usr != null)
         {
             usr.Locked = true;
             usr.Update();
         }
         request.ResponseStatus = HttpStatusCodes.Forbidden;
     }
     else
     {
         EventController.TriggerEvent(new UserLoginEvent(username, ((IPEndPoint)request.Client).Address, UserLoginEvent.LoginEventTypes.FAILURE));
     }
 }
Esempio n. 7
0
        public bool UpdateUserInformation(long id, string username, string firstname, string lastname, string email, string extension, string domain)
        {
            bool ret = true;

            try
            {
                User usr = User.Load(id.ToString());
                usr.UserName      = username;
                usr.FirstName     = firstname;
                usr.LastName      = lastname;
                usr.Email         = email;
                usr.UserExtension = Extension.Load(extension, Domain.Load(domain));
                usr.Update();
            }
            catch (Exception e)
            {
                EventController.TriggerEvent(new ErrorOccuredEvent(e));
                Log.Error(e);
                ret = false;
            }
            return(ret);
        }