Ejemplo n.º 1
0
        public LoginDialog()
        {
            this.Build ();
            this.CustomBuild();
            this.Connect();

            this.Success = false;
            this.Hits = 0;
            this.MaxHits = 3;
            this.ActiveAdmins = -1;
            this.Model = new UserModel();
        }
Ejemplo n.º 2
0
        public static User FromId(long id)
        {
            UserModel model = new UserModel();
            User user = null;
            System.Data.IDataReader reader = model.GetById(id);
            if(reader.Read())
            {
                user.Id = id;
                user.Name = (string) reader["Name"];
                user.Alias = (string) reader["Alias"];
                user.Password = (string) reader["Password"];
                user.Active = (bool) reader["Active"];
                user.Admin = (bool) reader["Admin"];
            }

            return user;
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }