public string Update(UserViewModel model) { var user = new ApplicationUser { UserName = model.UserName.ToLower(), FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Role = model.Role, Position = model.Position, Org = model.Org, GeoCode = model.GeoCode, ReceiveEmailAlert = model.ReceiveEmailAlert }; string message = string.Empty; if (model.Action == Constant.UserAdmin.Operation.Add) { var storedUser = _userAdminRepository.GetActiveUser(user.UserName); if (storedUser != null && string.IsNullOrEmpty(storedUser.UserName)) { return("An user already exist with the same Username ('" + user.UserName + "')."); } storedUser = _userAdminRepository.GetUserByEmail(user.Email); if (storedUser != null && string.IsNullOrEmpty(storedUser.UserName)) { return("An user already exist with the same Email ('" + user.Email + "')."); } var encryptedPassword = user.PasswordHash = _userManager.PasswordHasher.HashPassword("123456"); user.PasswordHash = encryptedPassword; message = _userAdminRepository.AddUser("", user); SendUserAddedMail(user, Request.Url.AbsoluteUri.Replace("UserOperation/Update", string.Empty)); } else if (model.Action == Constant.UserAdmin.Operation.Edit) { var storedUser = _userAdminRepository.GetActiveUser(user.UserName); if (storedUser == null) { return(user.UserName + " User Does Not Exist"); } user.FirstName = model.FirstName; user.LastName = model.LastName; user.Role = model.Role; user.Position = model.Position; user.GeoCode = model.GeoCode; user.Org = model.Org; user.ReceiveEmailAlert = model.ReceiveEmailAlert; user.IsActive = storedUser.IsActive; message = _userAdminRepository.EditUser(storedUser.Id, user); SendUserEditedMail(user, Request.Url.AbsoluteUri.Replace("UserOperation/Update", string.Empty)); } return(message); }
public ApplicationUser GetUser(string userName, string password) { if (string.IsNullOrEmpty(userName)) { return(null); } var user = _userAdminRepository.GetActiveUser(userName); bool isValidUser = IsValidUser(userName, password, user); if (isValidUser) { return(user); } return(null); }
public string Index(string userName, bool isReset = false) { var message = string.Empty; if (string.IsNullOrEmpty(userName)) { return("Username can not be empty"); } var user = _userAdminRepository.GetActiveUser(userName); if (user.UserName == null) { return("Username does not exist."); } if (!EMail.IsEmail(user.Email)) { message = "User does not have a valid mail address."; } else { string url = default(string); TextReader privateKey = new StreamReader(Server.MapPath("~/App_Data/BIPrivateKey.xml")); TextReader publicKey = new StreamReader(Server.MapPath("~/App_Data/IMSPublicKey.xml")); var encryption = new Encryption(); var encryptedText = encryption.Encrypt(privateKey.ReadToEnd(), publicKey.ReadToEnd(), user.UserName + "_^_" + DateTime.Now.ToUniversalTime()); var path = Request.IsLocal ? "" : "/"; url = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + path + "ForgotPassword/ValidateMail?parameters=" + encryptedText; SendForgotPasswordMail(user, url); message = "Updated"; if (isReset) { message = "Password reset successfully"; } } return(message); }