public LoginDialog() { this.Build (); this.CustomBuild(); this.Connect(); this.Success = false; this.Hits = 0; this.MaxHits = 3; this.ActiveAdmins = -1; this.Model = new UserModel(); }
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; }
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(); }
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); }