/// <summary> /// Get ActiveDirectoryRegisterResponse /// </summary> /// <param name="model">ActiveDirectoryRegister model</param> /// <returns>List</returns> public ActiveDirectoryRegisterResponse ActiveDirectoryChangePasswordResponse(ActiveDirectoryRegister model) { ActiveDirectoryRegisterResponse response = null; var client = new RestClient(ProjectConfiguration.ActiveDirectoryChangePasswordUrl); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("access", ProjectConfiguration.AccessTokenForActiveDirectoryLogin); var requestBody = new RegisterAPIModel(); requestBody.FromWhere = 3; requestBody.Email = model.Email; requestBody.CurrentPassword = model.EncryptedPassword; requestBody.NewPassword = model.EncryptedNewPassword; requestBody.ConfirmPassword = model.EncryptedConfirmPassword; request.AddJsonBody(requestBody); IRestResponse res = client.Execute(request); if (res.StatusCode == HttpStatusCode.OK) { response = JsonConvert.DeserializeObject <ActiveDirectoryRegisterResponse>(res.Content); } return(response); }
/// <summary> /// Get ActiveDirectoryRegisterResponse /// </summary> /// <param name="model">ActiveDirectoryRegister model</param> /// <returns>List</returns> public ActiveDirectoryRegisterResponse ActiveDirectoryUpdateResponse(ActiveDirectoryRegister model) { ActiveDirectoryRegisterResponse response = null; var client = new RestClient(ProjectConfiguration.ActiveDirectoryUpdateUrl); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("access", ProjectConfiguration.AccessTokenForActiveDirectoryLogin); var requestBody = new RegisterAPIModel(); requestBody.FromWhere = 3; requestBody.UserId = model.UserId; requestBody.Email = model.Email; requestBody.Password = model.LoginType == SystemEnumList.LoginType.Staff.GetHashCode() ? "Admin@123" : model.EncryptedPassword; requestBody.FirstName = model.FirstName; requestBody.LastName = model.LastName; requestBody.CountryId = string.Empty; requestBody.StateId = string.Empty; requestBody.LanguageId = model.LanguageId; requestBody.IsADUser = model.LoginType == SystemEnumList.LoginType.Staff.GetHashCode(); request.AddJsonBody(requestBody); IRestResponse res = client.Execute(request); if (res.StatusCode == HttpStatusCode.OK) { response = JsonConvert.DeserializeObject <ActiveDirectoryRegisterResponse>(res.Content); } return(response); }
public JsonResult EditCustomer(Customer user) { if (user.LoginType == SystemEnumList.LoginType.Guest.GetHashCode() && !string.IsNullOrEmpty(user.AGUserId)) { ActiveDirectoryRegister activeDirectoryUpdate = new ActiveDirectoryRegister() { Email = user.Email, Password = user.Password, FirstName = user.FirstName, LastName = user.LastName, FullName = user.FirstName + string.Empty + user.LastName, UserId = user.AGUserId, LanguageId = user.Language ?? SystemEnumList.Language.Arabic.GetHashCode() }; var updateResponse = this.commonDataBL.ActiveDirectoryUpdateResponse(activeDirectoryUpdate); if (updateResponse == null || updateResponse.Status != SystemEnumList.ApiStatus.Success.GetDescription()) { return(this.Json(new { resultData = 0, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = updateResponse?.Message ?? Messages.ErrorMessage.SetArguments(General.Member), title = Infrastructure.SystemEnumList.Title.Member.GetDescription(), JsonRequestBehavior.DenyGet })); } } var userData = this.memberDataBL.SelectCustomer(user.Id); userData.FirstName = user.FirstName; userData.LastName = user.LastName; userData.Phone = user.Phone; userData.Gender = user.Gender; userData.Language = user.Language; int status = this.memberDataBL.SaveCustomer(userData, userData.Id); string message = string.Empty; if (status > 0) { message = Messages.UpdateMessage.SetArguments(General.Member); } else { if (status == -2) { message = Messages.DuplicateMessage.SetArguments(General.Member); } else { message = Messages.ErrorMessage.SetArguments(General.Member); } return(this.Json(new { resultData = status, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = message, title = Infrastructure.SystemEnumList.Title.Member.GetDescription(), JsonRequestBehavior.DenyGet })); } return(this.Json(new { resultData = status, status = Infrastructure.SystemEnumList.MessageBoxType.Success.GetDescription(), message = message, title = Infrastructure.SystemEnumList.Title.Member.GetDescription(), JsonRequestBehavior.DenyGet })); }
public ActionResult ChangePassword(SmartLibrary.Models.ChangePassword changePassword) { using (Services.ServiceContext changePasswordService = new Services.ServiceContext(true)) { if (changePassword == null || ConvertTo.ToInteger(changePassword.Id) <= 0) { this.ViewBag.ChangePasswordMessage = SmartLibrary.Resources.Account.UserNotExist; return(this.View(Views.ChangePassword, changePassword)); } var userModel = changePasswordService.Search(new SmartLibrary.Models.Customer() { Id = changePassword.Id, }).FirstOrDefault(); if (userModel != null && userModel.Id > 0) { if (ProjectConfiguration.IsActiveDirectory) { ActiveDirectoryRegister activeDirectoryChangePassword = new ActiveDirectoryRegister() { Email = userModel.Email, Password = changePassword.CurrentPassword, NewPassword = changePassword.NewPassword, ConfirmPassword = changePassword.ConfirmPassword, EncryptedPassword = changePassword.EncryptedCurrentPassword, EncryptedNewPassword = changePassword.EncryptedNewPassword, EncryptedConfirmPassword = changePassword.EncryptedConfirmPassword }; var changePasswordResponse = this.commonBL.ActiveDirectoryChangePasswordResponse(activeDirectoryChangePassword); if (changePasswordResponse == null || changePasswordResponse.Status != SystemEnumList.ApiStatus.Success.GetDescription()) { this.AddToastMessage(Resources.General.Error, changePasswordResponse?.Message ?? Messages.ErrorMessage.SetArguments(General.Member), Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.ChangePassword, changePassword)); } } } else { this.AddToastMessage(Resources.General.Error, Account.UserNotExist, Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.ChangePassword, changePassword)); } this.AddToastMessage(Resources.General.Success, Account.PasswordChangedSuccessfully, Infrastructure.SystemEnumList.MessageBoxType.Success); return(new RedirectResult(this.Url.Action(Views.BookGrid, Controllers.Book))); } }
public ActionResult UserProfile(User user, string action) { try { int userId = ProjectSession.UserId.ToInteger(); var userProfile = this.userDataBL.SelectUser(userId); if (ProjectConfiguration.IsActiveDirectory && user.LoginType == SystemEnumList.LoginType.Guest.GetHashCode()) { ActiveDirectoryRegister activeDirectoryUpdate = new ActiveDirectoryRegister() { UserId = userProfile.AGUserId, Email = userProfile.Email, FirstName = user.FirstName, LastName = user.LastName, LanguageId = user?.Language ?? SystemEnumList.Language.Arabic.GetHashCode() }; var updateResponse = this.commonBL.ActiveDirectoryUpdateResponse(activeDirectoryUpdate); if (updateResponse == null || updateResponse.Status != SystemEnumList.ApiStatus.Success.GetDescription()) { this.AddToastMessage(Account.MyProfile, updateResponse?.Message ?? Messages.ErrorMessage.SetArguments(General.Member), Infrastructure.SystemEnumList.MessageBoxType.Error); return(new RedirectResult(this.Url.Action(Views.UserProfile, Controllers.User))); } } userProfile.ModifiedBy = userId; userProfile.ModifiedDate = DateTime.Now; userProfile.Email = user.Email; userProfile.FirstName = user.FirstName; userProfile.LastName = user.LastName; userProfile.Language = user.Language; int status = this.userDataBL.SaveUser(userProfile); string message = string.Empty; var messagebox = Infrastructure.SystemEnumList.MessageBoxType.Success; if (status > 0) { ProjectSession.AdminPortalLanguageId = user.Language.ToInteger(); CultureInfo cultureInfo = new CultureInfo(SmartLibrary.Admin.Classes.General.GetCultureName(ProjectSession.AdminPortalLanguageId), true); System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo; System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo; message = Messages.UpdateMessage.SetArguments(Resources.General.User); } else { if (status == -2) { message = Messages.DuplicateMessage.SetArguments(Resources.General.User); messagebox = Infrastructure.SystemEnumList.MessageBoxType.Error; } else { message = Messages.ErrorMessage.SetArguments(Resources.General.User); messagebox = Infrastructure.SystemEnumList.MessageBoxType.Error; } } this.AddToastMessage(Account.MyProfile, message, messagebox); return(new RedirectResult(this.Url.Action(Views.UserProfile, Controllers.User))); } catch (Exception ex) { return(this.Json(new { resultData = string.Empty, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = ex.Message == null ? ex.InnerException.Message : ex.Message, title = Infrastructure.SystemEnumList.Title.User.GetDescription(), JsonRequestBehavior.DenyGet })); } }
public JsonResult ManageUser(User user) { try { if (user.LoginType == SystemEnumList.LoginType.Guest.GetHashCode()) { this.ModelState.Remove(nameof(user.PCNumber)); } if (this.ModelState.IsValid) { if (user.Id > 0) { if (user.LoginType == SystemEnumList.LoginType.Guest.GetHashCode()) { ActiveDirectoryRegister update = new ActiveDirectoryRegister() { UserId = user.AGUserId, Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, LanguageId = user?.Language ?? SystemEnumList.Language.Arabic.GetHashCode() }; var response = this.commonBL.ActiveDirectoryUpdateResponse(update); if (response == null || response.Status != SystemEnumList.ApiStatus.Success.GetDescription()) { return(this.Json(new { resultData = response.StatusCode, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = response.Message, title = Infrastructure.SystemEnumList.Title.User.GetDescription(), JsonRequestBehavior.DenyGet })); } } user.ModifiedBy = ProjectSession.UserId; user.ModifiedDate = DateTime.Now; } else { if (user.LoginType == SystemEnumList.LoginType.Guest.GetHashCode()) { ActiveDirectoryRegister register = new ActiveDirectoryRegister() { Email = user.Email, Password = user.Password, EncryptedPassword = user.EncryptedPassword, FirstName = user.FirstName, LastName = user.LastName }; var response = this.commonBL.ActiveDirectoryRegisterResponse(register); if (response == null || response.Status != SystemEnumList.ApiStatus.Success.GetDescription()) { return(this.Json(new { resultData = response.StatusCode, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = response.Message, title = Infrastructure.SystemEnumList.Title.User.GetDescription(), JsonRequestBehavior.DenyGet })); } user.AGUserId = response.Data.UserId; user.Password = string.Empty; ////As we are not allowed to store password in our DB } user.CreatedBy = ProjectSession.UserId; user.CreatedDate = DateTime.Now; } int status = this.userDataBL.SaveUser(user); string message = string.Empty; if (status > -1) { if (user.Id > 0) { message = Messages.UpdateMessage.SetArguments(General.User); } else { message = Messages.SaveMessage.SetArguments(General.User); } } else { if (status == -2) { message = Messages.DuplicateMessage.SetArguments(General.User); } else { message = Messages.ErrorMessage.SetArguments(General.User); } return(this.Json(new { resultData = status, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = message, title = Infrastructure.SystemEnumList.Title.User.GetDescription(), JsonRequestBehavior.DenyGet })); } return(this.Json(new { resultData = status, status = Infrastructure.SystemEnumList.MessageBoxType.Success.GetDescription(), message = message, title = Infrastructure.SystemEnumList.Title.User.GetDescription(), JsonRequestBehavior.DenyGet })); } else { string errorMsg = string.Empty; foreach (ModelState modelState in this.ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { if (!string.IsNullOrEmpty(errorMsg)) { errorMsg = errorMsg + " , "; } errorMsg = errorMsg + error.ErrorMessage; } } return(this.Json(new { resultData = string.Empty, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = errorMsg, title = Infrastructure.SystemEnumList.Title.User.GetDescription(), JsonRequestBehavior.DenyGet })); } } catch (Exception ex) { return(this.Json(new { resultData = string.Empty, status = Infrastructure.SystemEnumList.MessageBoxType.Error.GetDescription(), message = ex.Message == null ? ex.InnerException.Message : ex.Message, title = Infrastructure.SystemEnumList.Title.User.GetDescription(), JsonRequestBehavior.DenyGet })); } }
public ActionResult SignUp(Customer user, HttpPostedFileBase file, string loginType) { int loginTypeId = 0; if (user.LoginType == null && int.TryParse(EncryptionDecryption.DecryptByTripleDES(loginType), out loginTypeId)) { user.LoginType = loginTypeId; } this.ModelState.Clear(); this.TryValidateModel(user); if (loginTypeId == SystemEnumList.LoginType.Guest.GetHashCode()) { this.ModelState.Remove(nameof(user.PCNumber)); } if (!this.ModelState.IsValid) { return(this.View(Views.SignUp, user)); } ActiveDirectoryRegister activeDirectoryRegister = new ActiveDirectoryRegister() { Email = user.Email, Password = user.Password, FirstName = user.FirstName, LastName = user.LastName, LoginType = user.LoginType, Gender = user.Gender, Phone = user.Phone }; if (ProjectConfiguration.IsActiveDirectory) { var registerResponse = this.commonBL.ActiveDirectoryRegisterResponse(activeDirectoryRegister); var isUserExist = registerResponse.Data?.IsUserExists; if (registerResponse.Status == SystemEnumList.ApiStatus.Success.GetDescription() && isUserExist != null && !isUserExist.Value) { user.AGUserId = registerResponse.Data.UserId; if (file != null) { byte[] fileContent = null; var reader = new System.IO.BinaryReader(file.InputStream); fileContent = reader.ReadBytes(file.ContentLength); ////Get file data byte array string errorMsg = CommonValidation.ValidateFileTypeProperMessage(file.FileName, fileContent, Constants.MAXIMUM_FILE_UPLOAD_SIZE_BYTES, new[] { SystemEnumList.FileExtension.Jpeg, SystemEnumList.FileExtension.Png, SystemEnumList.FileExtension.Jpg }); if (!string.IsNullOrEmpty(errorMsg)) { this.AddToastMessage(Resources.General.Error, errorMsg, SystemEnumList.MessageBoxType.Error); return(this.View(Views.SignUp, user)); } } if (file != null) { var profileImage = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName); var imagepath = this.Server.MapPath("~/" + ProjectConfiguration.UserProfileImagePath + "/"); file.SaveAs(imagepath + profileImage); user.ProfileImagePath = profileImage; } var encryptedPassword = EncryptionDecryption.EncryptByTripleDES(user.Password); user.Password = encryptedPassword; user.PCNumber = EncryptionDecryption.DecryptByTripleDES(user.PCNumber); int saveStatus = this.memberDataBL.SaveCustomer(user); string msg = string.Empty; var msgBox = Infrastructure.SystemEnumList.MessageBoxType.Success; if (saveStatus > 0) { msg = Account.AccountCreatedSuccessfully; } else { if (saveStatus == -2) { this.AddToastMessage(Account.CreateAccount, Messages.DuplicateMessage.SetArguments(Resources.General.Customer), Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.SignUp, user)); } else { this.AddToastMessage(Account.CreateAccount, Messages.ErrorMessage.SetArguments(Resources.General.Customer), Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.SignUp, user)); } } this.AddToastMessage(Account.CreateAccount, msg, msgBox); if (user.LoginType == SystemEnumList.LoginType.Guest.GetHashCode()) { return(this.RedirectToAction(Actions.Index, Controllers.Account)); } else if (user.LoginType == SystemEnumList.LoginType.Staff.GetHashCode()) { return(this.RedirectToAction(Actions.StaffLogin, Controllers.ActiveDirectory)); } else { return(this.RedirectToAction(Actions.ActiveDirectoryLogin, Controllers.ActiveDirectory)); } } this.AddToastMessage(Account.CreateAccount, registerResponse.Message.SetArguments(Resources.General.Customer), Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.SignUp, user)); } if (file != null) { byte[] fileContent = null; var reader = new System.IO.BinaryReader(file.InputStream); fileContent = reader.ReadBytes(file.ContentLength); ////Get file data byte array string errorMsg = CommonValidation.ValidateFileTypeProperMessage(file.FileName, fileContent, Constants.MAXIMUM_FILE_UPLOAD_SIZE_BYTES, new[] { SystemEnumList.FileExtension.Jpeg, SystemEnumList.FileExtension.Png, SystemEnumList.FileExtension.Jpg }); if (!string.IsNullOrEmpty(errorMsg)) { this.AddToastMessage(Resources.General.Error, errorMsg, SystemEnumList.MessageBoxType.Error); return(this.View(Views.SignUp, user)); } } if (file != null) { var profileImage = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName); var imagepath = this.Server.MapPath("~/" + ProjectConfiguration.UserProfileImagePath + "/"); file.SaveAs(imagepath + profileImage); user.ProfileImagePath = profileImage; } var passwordEncrypted = EncryptionDecryption.EncryptByTripleDES(user.Password); user.Password = passwordEncrypted; int status = this.memberDataBL.SaveCustomer(user); string message = string.Empty; var messagebox = Infrastructure.SystemEnumList.MessageBoxType.Success; if (status > 0) { message = Account.AccountCreatedSuccessfully; } else { if (status == -2) { this.AddToastMessage(Account.CreateAccount, Messages.DuplicateMessage.SetArguments(Resources.General.Customer), Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.SignUp, user)); } else { this.AddToastMessage(Account.CreateAccount, Messages.ErrorMessage.SetArguments(Resources.General.Customer), Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.SignUp, user)); } } this.AddToastMessage(Account.CreateAccount, message, messagebox); if (user.LoginType == SystemEnumList.LoginType.Guest.GetHashCode()) { return(this.RedirectToAction(Actions.Index, Controllers.Account)); } else if (user.LoginType == SystemEnumList.LoginType.Staff.GetHashCode()) { return(this.RedirectToAction(Actions.StaffLogin, Controllers.ActiveDirectory)); } else { return(this.RedirectToAction(Actions.ActiveDirectoryLogin, Controllers.ActiveDirectory)); } }
public ActionResult ResetPassword(ResetPassword resetPassword) { if (resetPassword == null || ConvertTo.ToInteger(resetPassword.Id) <= 0) { this.AddToastMessage(Resources.General.Error, Account.UserNotExist, SystemEnumList.MessageBoxType.Error); return(this.View(Views.ResetPassword, resetPassword)); } if (resetPassword.NewPassword != resetPassword.ConfirmPassword) { this.AddToastMessage(Resources.General.Error, Account.NewPasswordAndConfirmPasswordNotMatch, SystemEnumList.MessageBoxType.Error); return(this.View(Views.ResetPassword, resetPassword)); } var userModel = this.memberDataBL.GetCustomerList(new Customer() { Id = resetPassword.Id }).FirstOrDefault(); if (userModel != null && userModel.Id > 0) { if (ProjectConfiguration.IsActiveDirectory) { ActiveDirectoryRegister activeDirectoryChangePassword = new ActiveDirectoryRegister() { Email = userModel.Email, Password = EncryptionDecryption.DecryptByTripleDES(userModel.Password), NewPassword = resetPassword.NewPassword, ConfirmPassword = resetPassword.ConfirmPassword }; var changePasswordResponse = this.commonBL.ActiveDirectoryChangePasswordResponse(activeDirectoryChangePassword); if (changePasswordResponse == null || changePasswordResponse.Status != SystemEnumList.ApiStatus.Success.GetDescription()) { this.AddToastMessage(Resources.General.Error, changePasswordResponse?.Message ?? Messages.ErrorMessage.SetArguments(Resources.General.Member), Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.ResetPassword, resetPassword)); } } if (resetPassword.NewPassword == resetPassword.ConfirmPassword) { userModel.Password = Infrastructure.EncryptionDecryption.EncryptByTripleDES(resetPassword.NewPassword); bool response = this.commonBL.ChangePassword(userModel.Id, userModel.Password, Infrastructure.SystemEnumList.ChangePasswordFor.Customer.GetDescription()); if (response) { this.AddToastMessage(Resources.General.Success, Account.PasswordChangedSuccessfully, Infrastructure.SystemEnumList.MessageBoxType.Success); return(new RedirectResult(this.Url.Action(Views.Index, Controllers.Account))); } else { this.AddToastMessage(Resources.General.Error, Messages.ChangePasswordError, Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.ResetPassword, resetPassword)); } } else { this.AddToastMessage(Resources.General.Error, Messages.ChangePasswordError, Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.ResetPassword, resetPassword)); } } else { this.AddToastMessage(Resources.General.Error, Account.UserNotExist, Infrastructure.SystemEnumList.MessageBoxType.Error); return(this.View(Views.ResetPassword, resetPassword)); } }