protected void gvUsers_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { var newUsername = Utils.ConvertToTrimmedString(e.NewValues["username"]); var newName = Utils.ConvertToTrimmedString(e.NewValues["name"]); var newLastName = Utils.ConvertToTrimmedString(e.NewValues["lastname"]); var newEmail = Utils.ConvertToTrimmedString(e.NewValues["email"]); if (newUsername == null || newName == null || newLastName == null || newEmail == null) { throw new Exception("Complete all fields!"); } newUsername = newUsername.ToLower(); newEmail = newEmail.ToLower(); if (!MailUtils.EmailAddressValid(newEmail)) { throw new Exception("Email is not valid!"); } UserManagement.UserRegister(newUsername, newName, newLastName, newEmail); }
public AppUser(string userName) { this.UserName = (userName != null) ? userName.ToUpper().Trim() : null; this.Exist = false; if (this.UserName != null && UserExist(userName)) { this.Exist = true; string query = @"SELECT [Name], [LastName], [Email] FROM [aspnet_Users] WHERE [LoweredUserName] = @username;"; var parameters = new Dictionary <string, object>() { { "username", userName.ToLower().Trim() } }; var result = DatabaseUtils.ExecuteSelectQuery(query, parameters, DatabaseUtils.ConnectionTarget.Services); if (result != null) { this.Email = Convert.ToString(result.Rows[0]["Email"]); this.Email = (MailUtils.EmailAddressValid(this.Email)) ? this.Email.ToLower().Trim() : null; this.FirstName = Convert.ToString(result.Rows[0]["Name"]); this.FirstName = (this.FirstName != null) ? this.FirstName.Trim() : null; this.LastName = Convert.ToString(result.Rows[0]["LastName"]); this.LastName = (this.LastName != null) ? this.LastName.Trim() : null; this.FullName = this.FirstName + " " + this.LastName; this.FullName = (!string.IsNullOrWhiteSpace(this.FullName)) ? this.FullName.Trim() : null; } } }
public static string GetUserMail(string userName) { if (string.IsNullOrWhiteSpace(userName)) { return(null); } string query = @"SELECT [Email] FROM [aspnet_Users] WHERE [LoweredUserName] = @username;"; var parameters = new Dictionary <string, object>() { { "username", userName.ToLower().Trim() } }; var result = Convert.ToString(DatabaseUtils.ExecuteScalarSelectQuery(query, parameters, DatabaseUtils.ConnectionTarget.Services)); return((MailUtils.EmailAddressValid(result)) ? result.ToLower().Trim() : null); }
protected void gvUsers_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { var newUsername = Utils.ConvertToTrimmedString(e.NewValues["username"]); var oldUsername = Utils.ConvertToTrimmedString(e.OldValues["username"]); var newName = Utils.ConvertToTrimmedString(e.NewValues["name"]); var newLastName = Utils.ConvertToTrimmedString(e.NewValues["lastname"]); var newEmail = Utils.ConvertToTrimmedString(e.NewValues["email"]); if (oldUsername == null) { throw new Exception("System error!"); } if (newUsername == null || newName == null || newLastName == null || newEmail == null) { throw new Exception("Complete all fields!"); } oldUsername = oldUsername.ToLower(); newUsername = newUsername.ToLower(); newEmail = newEmail.ToLower(); if (newUsername != oldUsername) { throw new Exception("Username cannot be changed!"); } if (!MailUtils.EmailAddressValid(newEmail)) { throw new Exception("Email is not valid!"); } UserManagement.UserUpdate(newUsername, newName, newLastName, newEmail); }