diff --git a/umbraco/businesslogic/User.cs b/umbraco/businesslogic/User.cs
index ffbd844db9..b43e95283e 100644
--- a/umbraco/businesslogic/User.cs
+++ b/umbraco/businesslogic/User.cs
@@ -6,12 +6,13 @@ using umbraco.DataLayer;
using System.Collections.Generic;
using System.Linq;
-namespace umbraco.BusinessLogic {
+namespace umbraco.BusinessLogic
+{
///
/// represents a Umbraco back end user
///
- public class User {
-
+ public class User
+ {
private int _id;
private bool _isInitialized;
private string _name;
@@ -31,7 +32,8 @@ namespace umbraco.BusinessLogic {
private Hashtable _notifications = new Hashtable();
private bool _notificationsInitialized = false;
- private static ISqlHelper SqlHelper {
+ private static ISqlHelper SqlHelper
+ {
get { return Application.SqlHelper; }
}
@@ -39,7 +41,8 @@ namespace umbraco.BusinessLogic {
/// Initializes a new instance of the class.
///
/// The ID.
- public User(int ID) {
+ public User(int ID)
+ {
setupUser(ID);
}
@@ -48,7 +51,8 @@ namespace umbraco.BusinessLogic {
///
/// The ID.
/// if set to true [no setup].
- public User(int ID, bool noSetup) {
+ public User(int ID, bool noSetup)
+ {
_id = ID;
}
@@ -57,7 +61,8 @@ namespace umbraco.BusinessLogic {
///
/// The login.
/// The password.
- public User(string Login, string Password) {
+ public User(string Login, string Password)
+ {
setupUser(getUserId(Login, Password));
}
@@ -65,34 +70,33 @@ namespace umbraco.BusinessLogic {
/// Initializes a new instance of the class.
///
/// The login.
- public User(string Login) {
+ public User(string Login)
+ {
setupUser(getUserId(Login));
}
- private void setupUser(int ID) {
+ private void setupUser(int ID)
+ {
_id = ID;
using (IRecordsReader dr = SqlHelper.ExecuteReader(
"Select userNoConsole, userDisabled, userType,startStructureID, startMediaId, userName,userLogin,userEmail,userDefaultPermissions, userLanguage, defaultToLiveEditing from umbracoUser where id = @id",
- SqlHelper.CreateParameter("@id", ID))) {
- if (dr.Read())
- {
- _userNoConsole = dr.GetBoolean("usernoconsole");
- _userDisabled = dr.GetBoolean("userDisabled");
- _name = dr.GetString("userName");
- _loginname = dr.GetString("userLogin");
- _email = dr.GetString("userEmail");
- _language = dr.GetString("userLanguage");
- _startnodeid = dr.GetInt("startStructureID");
- if (!dr.IsNull("startMediaId"))
- _startmediaid = dr.GetInt("startMediaID");
- _usertype = UserType.GetUserType(dr.GetShort("UserType"));
- _defaultToLiveEditing = dr.GetBoolean("defaultToLiveEditing");
- }
- else
- {
- throw new ArgumentException("No User exists with ID " + ID.ToString());
- }
+ SqlHelper.CreateParameter("@id", ID)))
+ {
+ if (dr.Read())
+ {
+ _userNoConsole = dr.GetBoolean("usernoconsole");
+ _userDisabled = dr.GetBoolean("userDisabled");
+ _name = dr.GetString("userName");
+ _loginname = dr.GetString("userLogin");
+ _email = dr.GetString("userEmail");
+ _language = dr.GetString("userLanguage");
+ _startnodeid = dr.GetInt("startStructureID");
+ if (!dr.IsNull("startMediaId"))
+ _startmediaid = dr.GetInt("startMediaID");
+ _usertype = UserType.GetUserType(dr.GetShort("UserType"));
+ _defaultToLiveEditing = dr.GetBoolean("defaultToLiveEditing");
+ }
}
_isInitialized = true;
}
@@ -100,7 +104,8 @@ namespace umbraco.BusinessLogic {
///
/// Used to persist object changes to the database. In Version3.0 it's just a stub for future compatibility
///
- public void Save() {
+ public void Save()
+ {
OnSaving(EventArgs.Empty);
}
@@ -108,13 +113,16 @@ namespace umbraco.BusinessLogic {
/// Gets or sets the users name.
///
/// The name.
- public string Name {
- get {
+ public string Name
+ {
+ get
+ {
if (!_isInitialized)
setupUser(_id);
return _name;
}
- set {
+ set
+ {
_name = value;
SqlHelper.ExecuteNonQuery("Update umbracoUser set UserName = @userName where id = @id", SqlHelper.CreateParameter("@userName", value), SqlHelper.CreateParameter("@id", Id));
FlushFromCache();
@@ -125,13 +133,16 @@ namespace umbraco.BusinessLogic {
/// Gets or sets the users email.
///
/// The email.
- public string Email {
- get {
+ public string Email
+ {
+ get
+ {
if (!_isInitialized)
setupUser(_id);
return _email;
}
- set {
+ set
+ {
_email = value;
SqlHelper.ExecuteNonQuery("Update umbracoUser set UserEmail = @email where id = @id", SqlHelper.CreateParameter("@id", this.Id), SqlHelper.CreateParameter("@email", value));
FlushFromCache();
@@ -142,13 +153,16 @@ namespace umbraco.BusinessLogic {
/// Gets or sets the users language.
///
/// The language.
- public string Language {
- get {
+ public string Language
+ {
+ get
+ {
if (!_isInitialized)
setupUser(_id);
return _language;
}
- set {
+ set
+ {
_language = value;
SqlHelper.ExecuteNonQuery("Update umbracoUser set userLanguage = @language where id = @id", SqlHelper.CreateParameter("@language", value), SqlHelper.CreateParameter("@id", Id));
FlushFromCache();
@@ -159,11 +173,14 @@ namespace umbraco.BusinessLogic {
/// Gets or sets the users password.
///
/// The password.
- public string Password {
- get {
+ public string Password
+ {
+ get
+ {
return GetPassword();
}
- set {
+ set
+ {
SqlHelper.ExecuteNonQuery("Update umbracoUser set UserPassword = @pw where id = @id", SqlHelper.CreateParameter("@pw", value), SqlHelper.CreateParameter("@id", Id));
FlushFromCache();
}
@@ -173,8 +190,9 @@ namespace umbraco.BusinessLogic {
/// Gets the password.
///
///
- public string GetPassword() {
- return
+ public string GetPassword()
+ {
+ return
SqlHelper.ExecuteScalar("select UserPassword from umbracoUser where id = @id",
SqlHelper.CreateParameter("@id", this.Id));
}
@@ -186,13 +204,15 @@ namespace umbraco.BusinessLogic {
///
/// true if this user is admin; otherwise, false.
///
- public bool IsAdmin() {
+ public bool IsAdmin()
+ {
return UserType.Alias == "admin";
}
- public bool ValidatePassword(string password) {
+ public bool ValidatePassword(string password)
+ {
string userLogin =
- SqlHelper.ExecuteScalar("select userLogin from umbracoUser where userLogin = @login and UserPassword = @pw",
+ SqlHelper.ExecuteScalar("select userLogin from umbracoUser where userLogin = @login and UserPassword = @pw",
SqlHelper.CreateParameter("@pw", password),
SqlHelper.CreateParameter("@login", LoginName)
);
@@ -205,7 +225,8 @@ namespace umbraco.BusinessLogic {
///
/// true if this user is root; otherwise, false.
///
- public bool IsRoot() {
+ public bool IsRoot()
+ {
return Id == 0;
}
@@ -213,14 +234,18 @@ namespace umbraco.BusinessLogic {
/// Gets the applications which the user has access to.
///
/// The users applications.
- public Application[] Applications {
- get {
+ public Application[] Applications
+ {
+ get
+ {
if (!_isInitialized)
setupUser(_id);
ArrayList al = new ArrayList();
- using (IRecordsReader appIcons = SqlHelper.ExecuteReader("select appAlias, appIcon, appname from umbracoApp app join umbracoUser2app u2a on u2a.app = app.appAlias and u2a.[user] = @userID order by app.sortOrder", SqlHelper.CreateParameter("@userID", this.Id))) {
- while (appIcons.Read()) {
+ using (IRecordsReader appIcons = SqlHelper.ExecuteReader("select appAlias, appIcon, appname from umbracoApp app join umbracoUser2app u2a on u2a.app = app.appAlias and u2a.[user] = @userID order by app.sortOrder", SqlHelper.CreateParameter("@userID", this.Id)))
+ {
+ while (appIcons.Read())
+ {
Application tmp = new Application();
tmp.name = appIcons.GetString("appName");
tmp.icon = appIcons.GetString("appIcon");
@@ -231,7 +256,8 @@ namespace umbraco.BusinessLogic {
Application[] retVal = new Application[al.Count];
- for (int i = 0; i < al.Count; i++) {
+ for (int i = 0; i < al.Count; i++)
+ {
retVal[i] = (Application)al[i];
}
return retVal;
@@ -242,13 +268,16 @@ namespace umbraco.BusinessLogic {
/// Gets or sets the users login name
///
/// The loginname.
- public string LoginName {
- get {
+ public string LoginName
+ {
+ get
+ {
if (!_isInitialized)
setupUser(_id);
return _loginname;
}
- set {
+ set
+ {
if (!ensureUniqueLoginName(value, this))
throw new Exception(String.Format("A user with the login '{0}' already exists", value));
_loginname = value;
@@ -257,7 +286,8 @@ namespace umbraco.BusinessLogic {
}
}
- private static bool ensureUniqueLoginName(string loginName, User currentUser) {
+ private static bool ensureUniqueLoginName(string loginName, User currentUser)
+ {
User[] u = User.getAllByLoginName(loginName);
if (u.Length != 0)
{
@@ -274,7 +304,8 @@ namespace umbraco.BusinessLogic {
/// The login name.
/// The password.
///
- public static bool validateCredentials(string lname, string passw) {
+ public static bool validateCredentials(string lname, string passw)
+ {
return validateCredentials(lname, passw, true);
}
@@ -285,7 +316,8 @@ namespace umbraco.BusinessLogic {
/// The password.
/// if set to true [check for umbraco console access].
///
- public static bool validateCredentials(string lname, string passw, bool checkForUmbracoConsoleAccess) {
+ public static bool validateCredentials(string lname, string passw, bool checkForUmbracoConsoleAccess)
+ {
string consoleCheckSql = "";
if (checkForUmbracoConsoleAccess)
consoleCheckSql = "and userNoConsole = 0 ";
@@ -304,13 +336,16 @@ namespace umbraco.BusinessLogic {
/// Gets or sets the type of the user.
///
/// The type of the user.
- public UserType UserType {
- get {
+ public UserType UserType
+ {
+ get
+ {
if (!_isInitialized)
setupUser(_id);
return _usertype;
}
- set {
+ set
+ {
_usertype = value;
SqlHelper.ExecuteNonQuery(
@"Update umbracoUser set userType = @type where id = @id",
@@ -325,14 +360,15 @@ namespace umbraco.BusinessLogic {
/// Gets all users
///
///
- public static User[] getAll() {
+ public static User[] getAll()
+ {
IRecordsReader dr;
dr = SqlHelper.ExecuteReader("Select id from umbracoUser");
List users = new List();
- while (dr.Read())
+ while (dr.Read())
{
users.Add(User.GetUser(dr.GetInt("id")));
}
@@ -360,21 +396,24 @@ namespace umbraco.BusinessLogic {
///
/// The email.
///
- public static User[] getAllByEmail(string email) {
+ public static User[] getAllByEmail(string email)
+ {
System.Collections.ArrayList tmpContainer = new System.Collections.ArrayList();
IRecordsReader dr;
dr = SqlHelper.ExecuteReader(
"Select id from umbracoUser where userEmail LIKE %@email%", SqlHelper.CreateParameter("@email", email));
- while (dr.Read()) {
+ while (dr.Read())
+ {
tmpContainer.Add(BusinessLogic.User.GetUser(dr.GetInt("id")));
}
dr.Close();
User[] retVal = new User[tmpContainer.Count];
int c = 0;
- foreach (User u in tmpContainer) {
+ foreach (User u in tmpContainer)
+ {
retVal[c] = u;
c++;
}
@@ -386,21 +425,24 @@ namespace umbraco.BusinessLogic {
///
/// The login.
///
- public static User[] getAllByLoginName(string login) {
+ public static User[] getAllByLoginName(string login)
+ {
System.Collections.ArrayList tmpContainer = new System.Collections.ArrayList();
IRecordsReader dr;
dr = SqlHelper.ExecuteReader(
"Select id from umbracoUser where userLogin LIKE @login", SqlHelper.CreateParameter("@login", String.Format("%{0}%", login)));
- while (dr.Read()) {
+ while (dr.Read())
+ {
tmpContainer.Add(BusinessLogic.User.GetUser(dr.GetInt("id")));
}
dr.Close();
User[] retVal = new User[tmpContainer.Count];
int c = 0;
- foreach (User u in tmpContainer) {
+ foreach (User u in tmpContainer)
+ {
retVal[c] = u;
c++;
}
@@ -414,7 +456,8 @@ namespace umbraco.BusinessLogic {
/// The login name.
/// The password.
/// The user type.
- public static void MakeNew(string name, string lname, string passw, UserType ut) {
+ public static void MakeNew(string name, string lname, string passw, UserType ut)
+ {
SqlHelper.ExecuteNonQuery(@"
insert into umbracoUser
@@ -438,7 +481,8 @@ namespace umbraco.BusinessLogic {
/// The passw.
/// The email.
/// The ut.
- public static void MakeNew(string name, string lname, string passw, string email, UserType ut) {
+ public static void MakeNew(string name, string lname, string passw, string email, UserType ut)
+ {
SqlHelper.ExecuteNonQuery(@"
insert into umbracoUser
(UserType,startStructureId,startMediaId, UserName, userLogin, userPassword, userEmail,userLanguage)
@@ -462,11 +506,12 @@ namespace umbraco.BusinessLogic {
/// The lname.
/// The email.
/// The ut.
- public static void Update(int id, string name, string lname, string email, UserType ut) {
+ public static void Update(int id, string name, string lname, string email, UserType ut)
+ {
if (!ensureUniqueLoginName(lname, User.GetUser(id)))
throw new Exception(String.Format("A user with the login '{0}' already exists", lname));
-
+
SqlHelper.ExecuteNonQuery(@"Update umbracoUser set userName=@name, userLogin=@lname, userEmail=@email, UserType=@type where id = @id",
SqlHelper.CreateParameter("@name", name),
SqlHelper.CreateParameter("@lname", lname),
@@ -481,7 +526,8 @@ namespace umbraco.BusinessLogic {
/// The login name.
/// The password.
/// a user ID
- public static int getUserId(string lname, string passw) {
+ public static int getUserId(string lname, string passw)
+ {
return getUserId("select id from umbracoUser where userDisabled = 0 and userNoConsole = 0 and userLogin = @login and userPassword = @pw",
SqlHelper.CreateParameter("@login", lname),
SqlHelper.CreateParameter("@pw", passw));
@@ -492,21 +538,24 @@ namespace umbraco.BusinessLogic {
///
/// The login name.
/// a user ID
- public static int getUserId(string lname) {
+ public static int getUserId(string lname)
+ {
return getUserId("select id from umbracoUser where userLogin = @login",
SqlHelper.CreateParameter("@login", lname));
}
- private static int getUserId(string query, params IParameter[] parameterValues) {
+ private static int getUserId(string query, params IParameter[] parameterValues)
+ {
object userId = SqlHelper.ExecuteScalar