Ejemplo n.º 1
0
 public EditUserHelper(Gtk.Window win, ref DoubleListView dlv, User u)
 {
     this.doubleListView = dlv;
     _adminObj = (IAdmin) RemotingHelper.GetObject(typeof(IAdmin));
     _user = u;
     base.Init(win);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Called to populate User from form, before saving such an user at the server side
        /// </summary>
        public void PopulateUser(string userName, string realName, string password, 
						string email, bool active)
        {
            if (_user == null)
            {
                _user = new User();
            }
            _user.UserName = userName;
            _user.RealName = realName;
            _user.Password = password;
            _user.Email = email;
            _user.Active = active;
            if (_user.Groups != null)
            {
                _user.Groups.Clear();
            }
            else
            {
                _user.Groups = new HashedSet();
            }
            List<IBoxerpModel> userGroups = doubleListView.GetLeftObjectList();
            if (userGroups != null)
            {
                foreach(Group g in userGroups)
                {
                    _user.Groups.Add(g);
                }
            }
        }
Ejemplo n.º 3
0
 // Constructor: To edit an existing user
 // FIXME: get groups from client cache instead of passing in to this method
 public EditUserWindow(Group[] groups, User u)
     : base("")
 {
     Stetic.Gui.Build(this, typeof(administrator.EditUserWindow));
     _helper = new EditUserHelper(this, ref dtreeview, u);
     IsNewUser = false;
     this.PopulateUserFields();
     dtreeview.LeftLabel = "User groups:";
     dtreeview.RightLabel = "Rest of groups:";
     _helper.PopulateGUI(groups);
     //_helper.StartTransfer(ResponsiveEnum.Read);
 }
Ejemplo n.º 4
0
 public int DeleteUser(User user)
 {
     try
     {
     if (sessionsMgr.IsValidSessionThenUpdate(UserInformation.GetSessionToken()))
     {
         //Console.WriteLine(u.Id +","+u.UserName+","+u.RealName+","+
         //                  u.Email +","+u.Active);
         //ActiveRecordBase.Replicate(u);
         User persistentUser;
         if ((user == null) || (user.Id != 0))
         {
             persistentUser = User.Find(user.Id);
         }
         else
         {
             throw new NullReferenceException("User not found");
         }
         int id = persistentUser.Id;
         foreach (Group i in user.Groups)
         {
             Group group = Group.Find(i.Id);
             if (group != null)
             {
                 if (group.Users.Contains(persistentUser))
                 {
                     group.Users.Remove(persistentUser);
                 }
                 group.Save();
             }
         }
         persistentUser.Delete();
         return id;
     }
     else
     {
         Console.WriteLine("not valid user");
         return -1 ;
     }
     }
     catch (UnauthorizedException ex)
     {
     throw ex;
     }
     catch (Exception ex)
     {
     Console.WriteLine("ERROR:" + ex.Message + ":" + ex.StackTrace);
     if (ex.InnerException != null)
         Console.WriteLine("ERROR:" + ex.InnerException.Message +
                           ":" + ex.InnerException.StackTrace);
     throw ex;
     }
 }
Ejemplo n.º 5
0
 public string GetSession(User user)
 {
     if (user != null)
     {
     string session = user.UserName + DateTime.Now.GetHashCode() + random.NextDouble().ToString();
     SessionStruct sstruct = new SessionStruct();
     sstruct.user = user;
     sstruct.lastHit = DateTime.Now;
     sHash[session] = sstruct;
     return session;
     }
     else
     {
     throw new NullReferenceException();
     }
 }
Ejemplo n.º 6
0
 protected virtual void OnCancelClicked(object sender, System.EventArgs e)
 {
     User = null;
     IsNewUser = false;
     this.Destroy();
 }
Ejemplo n.º 7
0
        public int SaveUser(User user)
        {
            try
            {
            if (sessionsMgr.IsValidSessionThenUpdate(UserInformation.GetSessionToken()))
            {
                //Console.WriteLine(u.Id +","+u.UserName+","+u.RealName+","+
                //                  u.Email +","+u.Active);
                //ActiveRecordBase.Replicate(u);
                User persistentUser;
                if (user.Id != 0)
                {
                    persistentUser = User.Find(user.Id);
                    persistentUser.UserName = user.UserName;
                    persistentUser.RealName = user.RealName;
                    persistentUser.Email = user.Email;
                    persistentUser.Active = user.Active;
                    persistentUser.Password = user.Password;
                    persistentUser.Save();
                }
                else
                {
                    persistentUser = user;
                    persistentUser.Save();
                }
                if (user.Groups != null)
                {
                    foreach (Group i in user.Groups)
                    {
                        Group group = Group.Find(i.Id);
                        if (group != null)
                        {
                            if (! group.Users.Contains(persistentUser))
                            {

                                Console.WriteLine(persistentUser.Id +","+ persistentUser.UserName+","+ persistentUser.RealName);
                                group.Users.Add(persistentUser);
                                //persistentUser.Groups.Add(g);
                                //g.Update();
                            }
                            group.Save();
                        }
                    }
                }
                persistentUser.Save();
                return persistentUser.Id;
            }
            else
            {
                Console.WriteLine("not valid user");
                return -1 ;
            }
            }
            catch (UnauthorizedException ex)
            {
            throw ex;
            }
            catch (Exception ex)
            {
            Console.WriteLine("ERROR:" + ex.Message + ":" + ex.StackTrace);
            if (ex.InnerException != null)
                Console.WriteLine("ERROR:" + ex.InnerException.Message +
                                  ":" + ex.InnerException.StackTrace);
            throw ex;
            }
        }
Ejemplo n.º 8
0
 public Group[] GetDistinctGroups(User u)
 {
     try
     {
     if (sessionsMgr.IsValidSessionThenUpdate(UserInformation.GetSessionToken()))
     {
         if (u != null)
         {
             Group[] allGroups = Group.FindAll();
             ArrayList groups = new ArrayList();
             foreach(Group i in allGroups)
             {
                 if (!u.Groups.Contains(i))
                     groups.Add(i);
             }
             if (groups.Count > 0)
                 return (Group[])groups.ToArray(groups[0].GetType());
             else
                 return null;
         }
         return null;
     }
     else
     {
         return null;
     }
     }
     catch (UnauthorizedException ex)
     {
     throw ex;
     }
     catch (Exception ex)
     {
     Console.WriteLine("ERROR:" + ex.Message + ":" + ex.StackTrace);
     return null;
     }
 }
 public bool StartAction(User u, Sections s, Actions a)
 {
     if (u != null)
     {
         if (!cHash.ContainsKey(s.ToString()+a.ToString()))
         {
             ConcurrencyStruct cstruct = new ConcurrencyStruct();
             cstruct.user = u;
             cstruct.lastHit = DateTime.Now;
             cstruct.section = s;
             cstruct.action = a;
             cHash[s.ToString()+a.ToString()] = cstruct;
             return true;
         }
         else
         {
             if (s == Sections.ADMIN)
             {
                 return false;	// another user is inside administrator
             }
             return true;
         }
     }
     else
     {
         throw new NullReferenceException();
     }
 }
 public bool EndAction(User u, Sections s, Actions a)
 {
     if (u != null)
     {
         if (cHash.ContainsKey(s.ToString()+a.ToString()))
         {
             cHash.Remove(s.ToString()+a.ToString());
             return true;
         }
         else
         {
             return false;	// something is wrong
         }
     }
     else
     {
         throw new NullReferenceException();
     }
 }