internal void AssignRight(string right) { List <UserRight> tmp = new List <UserRight>(); if (Rights != null) { tmp.AddRange(Rights); } tmp.Add(UserRight.Load(right)); this.Rights = tmp.ToArray(); }
internal static UserRight Load(string name) { UserRight ret = null; Connection conn = ConnectionPoolManager.GetConnection(typeof(UserRight)); List <Org.Reddragonit.Dbpro.Structure.Table> tmp = conn.Select(typeof(UserRight), new SelectParameter[] { new EqualParameter("Name", name) }); if (tmp.Count > 0) { ret = (UserRight)tmp[0]; } conn.CloseConnection(); return(ret); }
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 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 User Create(string username, string firstname, string lastname, string password,string email, Extension extension,UserRight[] rights) { Log.Trace("Creating new user with username " + username); if (LoadByUsername(username)!=null) throw new Exception("Unable to create user, one already exists with that username."); User ret = new User(); ret.UserName = username; ret.FirstName = firstname; ret.LastName = lastname; ret.SetPassword(password, Constants.HTTP_AUTH_REALM); ret.UserExtension = extension; ret.Rights = rights; ret.Email = email; Connection conn = ConnectionPoolManager.GetConnection(typeof(User)); ret = (User)conn.Save(ret); conn.CloseConnection(); return ret; }