Exemple #1
0
        private void SelectUser(User u)
        {
            NodeStore store = this.UsersNodeView.NodeStore;
            TreeNode node = null;
            bool found = false;

            for(int i = 0; ; i++)
            {
                TreePath path = new TreePath(i.ToString());
                node = (TreeNode) store.GetNode(path);
                User temp = (User) node;

                if(temp == null)
                    break;

                else if(temp.Id == u.Id)
                {
                    found = true;
                    break;
                }
            }

            if(found)
            {
                this.UsersNodeView.NodeSelection.SelectNode(node);
                this.UsersNodeView.HasFocus = true;
            }
        }
Exemple #2
0
        private void SelectCurrent(object sender, EventArgs args)
        {
            SessionRegistry r = SessionRegistry.GetInstance();
            if(((bool) r["user_is_admin"]))
                this.EditButton.Sensitive = true;

            User user = (User) this.UsersNodeView.NodeSelection.SelectedNode;
            this.CurrentUser = user;
            this.AdminCheckBox.Active = user.Admin;
            this.ActiveCheckBox.Active = user.Active;
            this.AliasEntry.Text = user.Alias;
            this.NameEntry.Text = user.Name;
        }
Exemple #3
0
        private void FillNodeView()
        {
            NodeStore store = new NodeStore(typeof(User));
            User u = null;
            UserModel model = new UserModel();
            System.Data.IDataReader reader = model.GetAll();

            while(reader.Read())
            {
                u = new User();
                u.Id = (long) reader["Id"];
                u.Name = (string) reader["Name"];
                u.Alias = (string) reader["Alias"];
                u.Password = (string) reader["Password"];
                u.Active = (bool) reader["Active"];
                u.Admin = (bool) reader["Admin"];

                store.AddNode(u);
            }

            this.UsersNodeView.NodeStore = store;
            this.UsersNodeView.ShowAll();
        }
Exemple #4
0
        private void DoOk(object sender, EventArgs args)
        {
            UserModel model = new UserModel();

            if(this.CrudOp == CrudState.Create)
            {
                User user = new User();
                user.Active = this.ActiveCheckBox.Active;
                user.Admin = this.AdminCheckBox.Active;
                user.Alias = this.AliasEntry.Text.Trim();
                user.Name = this.NameEntry.Text.Trim();
                user.Password = HashHelper.GetMd5Of(this.NewPassword);

                if(model.Insert(user))
                {
                    this.CurrentUser = user;
                    this.CurrentUser.Id = model.LastInsertId;
                }
            }

            else if(this.CrudOp == CrudState.Update)
            {
                User u = this.CurrentUser;
                User to = new User();
                to.Alias = this.AliasEntry.Text;
                to.Active = this.ActiveCheckBox.Active;
                to.Admin = this.AdminCheckBox.Active;
                to.Name = this.NameEntry.Text;

                if(to.Admin != u.Admin)
                    model.UpdateById(u.Id, "Admin", to.Admin);
                if(to.Active != u.Active)
                    model.UpdateById(u.Id, "Active", to.Active);
                if(to.Alias != u.Alias)
                    model.UpdateById(u.Id, "Alias", to.Alias);
                if(to.Name != u.Name)
                    model.UpdateById(u.Id, "Name", to.Name);

                if(this.ChangePassword)
                {
                    SessionRegistry r = SessionRegistry.GetInstance();
                    long sess_id = (long) r["user_id"];
                    bool can_change = false;

                    if(sess_id != u.Id)
                        can_change = true;
                    else
                    {
                        string old_md5 = HashHelper.GetMd5Of(this.OldPassword);
                        if(old_md5 == u.Password)
                            can_change = true;
                    }

                    if(can_change)
                    {
                        string new_md5 = HashHelper.GetMd5Of(this.NewPassword);
                        if(new_md5 != u.Password)
                            model.UpdateById(u.Id, "Password", new_md5);
                    }

                    else
                        GuiHelper.ShowMessage(this, "No se pudo cambiar la contraseña");
                }
            }

            this.InitUsers();
            this.SelectUser(this.CurrentUser);
        }
Exemple #5
0
 public bool Insert(User user)
 {
     return this.Insert(null, user.Alias, user.Password, user.Name, user.Admin, user.Active);
 }
Exemple #6
0
        private void LoadInfo(object sender, EventArgs args)
        {
            string user = this.UserEntry.Text;
            string info = "";
            bool wtf = false;
            this.LoginUser = null;

            if(!string.IsNullOrEmpty(user))
            {
                if(this.CheckAdminHack())
                {
                    info = "Revisar configuración de usuarios";
                    wtf = true;
                }

                else if(this.Model.ExistsBy("Alias", user))
                {
                    System.Data.IDataReader r = this.Model.GetBy("Alias", user);
                    if(r.Read())
                    {
                        this.LoginUser = new User();
                        this.LoginUser.Id = (long) r["Id"];
                        this.LoginUser.Alias = user;
                        this.LoginUser.Password = (string) r["Password"];
                        this.LoginUser.Name = (string) r["Name"];
                        this.LoginUser.Admin = (bool) r["Admin"];
                        this.LoginUser.Active = (bool) r["Active"];

                        wtf = !this.LoginUser.Active;
                        info = wtf ? "Usuario desactivado" : this.LoginUser.Name;
                    }
                }
            }

            this.SetLabel(info, wtf);
        }