private void PreSave(long userId, ref User toSave, Enumerations.ActionMode action, string userRoles = "") { if (action == Enumerations.ActionMode.Add) { var defaultPassword = BlCode.LoadSingle(userId, "_System", "DefaultPassword").Value1; toSave.Password = Cryptography.ComputeToHash(defaultPassword); toSave.MustChangePassword = true; toSave.EntryDate = BlCommon.GetServerDateTime(); toSave.LastPasswordUpdate = toSave.EntryDate; //toSave.Branch = BlBranch.LoadSingle(userId, toSave.Branch.Id); } else if (action == Enumerations.ActionMode.Edit) { } toSave.EnteringUserId = userId; toSave.Entity = BlEntity.LoadSingle(userId, toSave.Pin); if (CheckEmpty.String(userRoles) != "") { if (toSave.Roles == null) { toSave.Roles = new List <Role>(); } toSave.Roles.Clear(); foreach (var roleId in userRoles.Split(',')) { toSave.Roles.Add(BlRole.LoadSingle(userId, Convert.ToInt64(roleId))); } } }
private static void PreSave(long userId, ref Entity toSave, Enumerations.ActionMode action) { if (action == Enumerations.ActionMode.Add) { toSave.EntryDate = BlCommon.GetServerDateTime(); } toSave.UserId = userId; }
private static void UpdateTicketValidity(long userId) { var defaultTimeOut = Convert.ToInt32(BlCode.LoadSingle(userId, "_System", "DefaultTimeOut").Value1); //BlLogError.LogError("BlUser.UpdateTicketValidity", "Key: " + Module + "_DateStamp_" + userId.ToUiString() +", Value: " + BlCommon.GetServerDateTime()); //BlLogError.LogError("BlUser.UpdateTicketValidity", "Key: " + Module + "_ValidTill_" + userId.ToUiString() + ", Value: " + BlCommon.GetServerDateTime().AddMinutes(defaultTimeOut)); //Increment ticket cached lifetime CacheHelper.Add(Module + "_DateStamp_" + userId.ToUiString(), BlCommon.GetServerDateTime(), defaultTimeOut); CacheHelper.Add(Module + "_ValidTill_" + userId.ToUiString(), BlCommon.GetServerDateTime().AddMinutes(defaultTimeOut), defaultTimeOut); }
public UserVm ProfileSave(long userId, UserVm toEdit) { using (var tran = new TransactionScope()) { var user = LoadSingle(toEdit.User.Id, true); if (toEdit.ChangePassword) { if (!Cryptography.ComputeToHash(toEdit.OldPassword).SequenceEqual(user.Password)) { throw new BusinessException("WrongOldPassword"); } if (!Cryptography.ComputeToHash(toEdit.NewPassword).SequenceEqual(Cryptography.ComputeToHash(toEdit.ConfirmPassword))) { throw new BusinessException("NewPasswordDoesNotmatchConfirmation"); } user.LastPasswordUpdate = BlCommon.GetServerDateTime(); if (user.PasswordHistory != "") { var oldPasswordList = CheckEmpty.String(user.PasswordHistory).Split(','); foreach (var pass in oldPasswordList) { if (Cryptography.ComputeToHash(toEdit.NewPassword).SequenceEqual(Convert.FromBase64String(pass))) { throw new BusinessException("NewPasswordFrequentlyUsed"); } } } user.PasswordHistory += user.PasswordHistory == "" ? "" : ","; user.PasswordHistory += Convert.ToBase64String(user.Password); var historyLength = BlCode.LoadSingle(userId, "_System", "PasswordHistroyLength").Value1; if (user.PasswordHistory.Split(',').Length > Convert.ToInt32(historyLength)) { var newPasswordHistroy = user.PasswordHistory.Split(',').ToList(); newPasswordHistroy.RemoveAt(0); user.PasswordHistory = string.Join(",", newPasswordHistroy); } user.Password = Cryptography.ComputeToHash(toEdit.NewPassword); toEdit.ChangePassword = false; } user.UserName = toEdit.User.UserName; user.LanguageId = Convert.ToInt16(toEdit.User.LanguageId); user.PageSize = Convert.ToInt16(toEdit.User.PageSize); Edit(userId, user); //Force cash refresh for module entry CacheHelper.Clear(Module + "_" + user.Id.ToUiString()); BlLog.Log(userId, Module, "Profile change", "UserProfileModified", new object[] { user.UserName }); tran.Complete(); return(toEdit); } }
private static void PreSave(long userId, ref Document toSave, Enumerations.ActionMode action) { if (action == Enumerations.ActionMode.Add) { //Save physical file under specific location var file = toSave.File; toSave.Path = SavePhysicalFile(userId, ref file, toSave.Name, toSave.Reference); toSave.EntryDate = BlCommon.GetServerDateTime(); } toSave.UserId = userId; }
public Log Create(long userId, Log toAdd) { using (var tran = new TransactionScope()) { toAdd.UserId = userId; toAdd.BranchId = BlUser.LoadSingle(toAdd.UserId).BranchId; toAdd.EntryDate = BlCommon.GetServerDateTime(); var toRet = _repository.Create(toAdd); tran.Complete(); return(toRet); } }
public Address Create(long userId, Address toAdd) { using (var tran = new TransactionScope()) { toAdd.EntryDate = BlCommon.GetServerDateTime(); toAdd.UserId = userId; toAdd.Sequence = GetPinNextSequence(userId, toAdd.Entity.Pin); var toRet = _repository.Create(toAdd); BlLog.Log(userId, Module, "Create address", "AddressCreated", new object[] { toAdd.Sequence, toAdd.Entity.Pin, BlEntity.FormatFullName(toAdd.Entity) }); tran.Complete(); return(toRet); } }
public Employee Create(long userId, Employee toAdd) { using (var tran = new TransactionScope()) { toAdd.UserId = userId; toAdd.EntryDate = BlCommon.GetServerDateTime(); var toRet = _repository.Create(toAdd); BlLog.Log(userId, Module, "Create employee", "EmployeeCreated", new object[] { toAdd.Entity.Pin, BlEntity.FormatFullName(toAdd.Entity) }); tran.Complete(); return(toRet); } }
private static void PreSave(long userId, ref Comment toSave, Enumerations.ActionMode action) { if (action == Enumerations.ActionMode.Add) { toSave.EntryDate = BlCommon.GetServerDateTime(); } else { var oldComment = LoadSingle(userId, toSave.Id); oldComment.Text = toSave.Text; toSave = oldComment; } toSave.UserId = userId; }
public Address Edit(long userId, Address toEdit) { using (var tran = new TransactionScope()) { if (toEdit.EntryDate == DateTime.MinValue) { toEdit.EntryDate = BlCommon.GetServerDateTime(); } var toRet = _repository.Edit(toEdit); BlLog.Log(userId, Module, "Edit address", "AddressModified", new object[] { toEdit.Sequence, toEdit.Entity.Pin, BlEntity.FormatFullName(toEdit.Entity) }); tran.Complete(); return(toRet); } }
private void PreSave(long userId, ref Permission toSave, Enumerations.ActionMode action, string roles = "") { if (action == Enumerations.ActionMode.Add) { toSave.Module = BlModule.LoadSingle(userId, toSave.Module.Id); toSave.EntryDate = BlCommon.GetServerDateTime(); } toSave.UserId = userId; if (CheckEmpty.String(roles) != "") { toSave.Roles.Clear(); foreach (var roleId in roles.Split(',')) { toSave.Roles.Add(BlRole.LoadSingle(userId, Convert.ToInt64(roleId))); } } }
public Help LoadSingle(long userId, string page, string ctrl) { var userIsEditor = BlPermission.CanDo(userId, Module, "HelpCreator"); var predicate = PredicateBuilder.True <Help>(); predicate = predicate.And(p => p.Page == page); predicate = predicate.And(p => p.Ctrl == ctrl); var toRet = LoadSearch(userId, predicate).SingleOrDefault(); //If entry does not exist then create it if (toRet == null && userIsEditor) { using (var tran = new TransactionScope(TransactionScopeOption.RequiresNew)) { var toCreate = new Help { Page = page, Ctrl = ctrl, EntryDate = BlCommon.GetServerDateTime(), UserId = userId, Title = "", Text = "", DisplayOrder = "ZZ" }; var blHelp = new BlHelp(); toRet = blHelp.Create(userId, toCreate); tran.Complete(); } } //If entry is empty and user not editor then get parent if (toRet.Text == "" && ctrl != "" && !userIsEditor) { predicate = PredicateBuilder.True <Help>(); predicate = predicate.And(p => p.Page == page); predicate = predicate.And(p => p.Ctrl == ""); toRet = LoadSearch(userId, predicate).SingleOrDefault(); } return(toRet); }
private static void PreSave(long userId, ref Employee toSave, Enumerations.ActionMode action) { if (action == Enumerations.ActionMode.Add) { toSave.EntryDate = BlCommon.GetServerDateTime(); toSave.Entity.EntryDate = toSave.EntryDate; toSave.Entity.UserId = toSave.UserId; toSave.Entity.Status = toSave.Status; } else if (action == Enumerations.ActionMode.Edit) { //toSave.Entity = BlEntity.LoadSingle(userId, toSave.Entity.Pin); if (toSave.Entity.Status == "S") { //TODO:Check no goods are related to this employee } } toSave.Entity.NameIndex = NameIndex.GetNameIndex(userId, toSave.Entity.FirstName, toSave.Entity.FamilyName, toSave.Entity.FatherName); toSave.Entity.NameIndex += NameIndex.GetNameIndex(userId, toSave.Entity.ArFirstName, toSave.Entity.ArFamilyName, toSave.Entity.ArFatherName); BlArDict.SetArabicDict(userId, toSave.Entity.FirstName, toSave.Entity.ArFirstName); BlArDict.SetArabicDict(userId, toSave.Entity.FatherName, toSave.Entity.ArFatherName); BlArDict.SetArabicDict(userId, toSave.Entity.FamilyName, toSave.Entity.ArFamilyName); }
private static string BuildMenuItem(User user, Menu menuItem, bool forEdit) { if (forEdit) { return(string.Format("<input type='radio' name='chkMenu' id='chkMenu' value='{0}'/>{1}", menuItem.Id, BlDescription.GetDescription(Enumerations.DescriptionResources.Language, menuItem.DescriptionCode, user.LanguageId, true))); } if (menuItem.Module == null && menuItem.Parent == null) { return(string.Format("<a href='#' {1}>{0} <span class='caret'></a>", BlDescription.GetDescription(Enumerations.DescriptionResources.Language, menuItem.DescriptionCode, user.LanguageId, true), menuItem.Details)); } if (menuItem.Module == null) { return(string.Format("<a href='#' {1}>{0} </a>", BlDescription.GetDescription(Enumerations.DescriptionResources.Language, menuItem.DescriptionCode, user.LanguageId, true), menuItem.Details)); } return(string.Format("<a href='../{1}' target='content'>{2}</a>", Constants.GetWebAppRootUrl(), CheckEmpty.String(menuItem.Module.Path) + "?ts=" + DateUtilities.GetDateStamp(BlCommon.GetServerDateTime(), true), BlDescription.GetDescription(Enumerations.DescriptionResources.Language, menuItem.DescriptionCode, user.LanguageId, true))); }
public long?Authorize(string token, string requestUri = "") { try { var userId = Cryptography.Decrypt(token, true); if (Convert.ToInt64(userId) == 0) { throw new BusinessException("InvalidTicket", "lblUser"); } //Validate ticket user var user = LoadSingle(Convert.ToInt64(userId)); if (user == null) { throw new BusinessException("InvalidTicket", "lblUser"); } //Validate ticket user status if (user.IsBlocked) { throw new BusinessException("UserInactive"); } //Validate ticket datestamp DateTime dateStamp; if (!CacheHelper.Get(Module + "_DateStamp_" + userId, out dateStamp)) { //BlLogError.LogError("BlUser.Authorize", "Datestamp empty"); throw new BusinessException("InvalidTicket", "lblDate"); } if (dateStamp > BlCommon.GetServerDateTime()) { //BlLogError.LogError("BlUser.Authorize", "datestamp less than current date"); throw new BusinessException("InvalidTicket", "lblDate"); } //Validate ticket validtill DateTime validTill; if (!CacheHelper.Get(Module + "_ValidTill_" + userId, out validTill)) { //BlLogError.LogError("BlUser.Authorize", "Valid till is empty"); throw new BusinessException("InvalidTicket", "lblDate"); } if (validTill < BlCommon.GetServerDateTime()) { //BlLogError.LogError("BlUser.Authorize", "Valid till less than current date"); throw new BusinessException("InvalidTicket", "lblDate"); } UpdateTicketValidity(user.Id); return(user.Id); } catch (Exception) { if (requestUri.ToUpper().Contains("LOGOUT")) { return(1); } } return(null); }