/// <summary> /// Removes the application's session record from the database and suspends the status operations /// </summary> public void End() { // stop timer if (_heartbeatTimer != null) { _heartbeatTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); _heartbeatTimer.Dispose(); _heartbeatTimer = null; } DbCommand dbCmdDelete = GetDeleteSessionRecordCmd(); dbCmdDelete.Parameters[_daMgr.BuildParamName(Constants.AppCode)].Value = _appCode; dbCmdDelete.Parameters[_daMgr.BuildParamName(Constants.MultipleSessionCode)].Value = _appSessionCode; _daMgr.ExecuteNonQuery(dbCmdDelete, null, null); if (_daMgr.loggingMgr != null) { _daMgr.loggingMgr.WriteToLog(string.Format("AppId {0}; AppSession: {1} AppName: {2}; Version: {3}; Session Ended." , _appId , _appSessionCode , _appName , _appVersion) , EventLogEntryType.Information , enumEventPriority.Critical); } }
private void btnAddDepTask_Click(object sender, EventArgs e) { DependentTaskAdmin taskAdmin = new DependentTaskAdmin(_daMgr, tbTaskQueueCode.Text, null); DialogResult dr = taskAdmin.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { Int32 rowsChanged = _daMgr.ExecuteNonQuery(TaskProcessing.TaskProcessingQueue.GetDependencyDmlCmd( _daMgr , null , taskAdmin.EditedColumns , _userCode) , null , null); RefreshDependentTasks(); } }
/// <summary> /// Changes the given user's password to the new password and resets any account restrictions /// depending on given parameter. /// <para>The method assumes the caller has verified the spelling of the new password.</para> /// <para>The method also assumes the caller has verified the existing password if applicable.</para> /// </summary> /// <param name="daMgr">DataAccessMgr object</param> /// <param name="userId">Unique user identifier</param> /// <param name="newPassword">The new password (unhashed) plain text</param> /// <param name="resetSignonRestrictions">Indicates whether the accounts restrictions will be reset</param> public static void ChangePassword(DataAccessMgr daMgr , string userId , string newPassword , bool resetSignonRestrictions) { string salt = Cryptography.HashOperation.CreateRandomSalt(Cryptography.HashAlgorithmTypeEnum.SHA512HashAlgorithm); string hash = Cryptography.HashOperation.ComputeHash(Cryptography.HashAlgorithmTypeEnum.SHA512HashAlgorithm , newPassword , salt); DbTableDmlMgr dmlUpdate = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE , Constants.UserMaster); dmlUpdate.AddColumn(Constants.UserPassword , daMgr.BuildParamName(Constants.UserPassword)); dmlUpdate.AddColumn(Constants.PasswordSalt , daMgr.BuildParamName(Constants.PasswordSalt)); dmlUpdate.AddColumn(Constants.FailedSignonAttempts , daMgr.BuildParamName(Constants.FailedSignonAttempts)); dmlUpdate.AddColumn(Constants.ForcePasswordChange , daMgr.BuildParamName(Constants.ForcePasswordChange)); if (resetSignonRestrictions) { dmlUpdate.AddColumn(Constants.SignonRestricted , daMgr.BuildParamName(Constants.SignonRestricted)); } dmlUpdate.SetWhereCondition((j) => j.Column(Constants.UserId) == j.Parameter(dmlUpdate.MainTable.SchemaName , dmlUpdate.MainTable.TableName , Constants.UserId , daMgr.BuildParamName(Constants.UserId))); DbCommand cmdUpdate = daMgr.BuildUpdateDbCommand(dmlUpdate); cmdUpdate.Parameters[daMgr.BuildParamName(Constants.UserId)].Value = userId; cmdUpdate.Parameters[daMgr.BuildParamName(Constants.UserPassword)].Value = hash; cmdUpdate.Parameters[daMgr.BuildParamName(Constants.PasswordSalt)].Value = salt; if (resetSignonRestrictions) { cmdUpdate.Parameters[daMgr.BuildParamName(Constants.SignonRestricted)].Value = 0; } cmdUpdate.Parameters[daMgr.BuildParamName(Constants.FailedSignonAttempts)].Value = 0; cmdUpdate.Parameters[daMgr.BuildParamName(Constants.ForcePasswordChange)].Value = 0; daMgr.ExecuteNonQuery(cmdUpdate, null, null); }
public ActionResult EditProfile(EditProfileModel editProfile) { if (ModelState.IsValid) { if (!string.IsNullOrEmpty(editProfile.ChangedFields)) { DataAccessMgr daMgr = Global.GetDataAccessMgr(this.HttpContext); DbTableDmlMgr dmlUpdate = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE , DataManagement.Constants.Table_UserMaster); foreach (string column in dmlUpdate.MainTable.Columns.Keys) { if (editProfile.ChangedFields.Contains(column)) { dmlUpdate.AddColumn(column); } } dmlUpdate.AddColumn(SessionManagement.Constants.LastModifiedUserCode); dmlUpdate.AddColumn(SessionManagement.Constants.LastModifiedDateTime , Core.EnumDateTimeLocale.Default); dmlUpdate.SetWhereCondition(j => j.Column(DataManagement.Constants.UserId) == j.Parameter(dmlUpdate.MainTable.SchemaName , dmlUpdate.MainTable.TableName , DataManagement.Constants.UserId , daMgr.BuildParamName(DataManagement.Constants.UserId))); DbCommand cmdUpdate = daMgr.BuildUpdateDbCommand(dmlUpdate); UserSession userSessionMgr = (UserSession)Session[SessionManagement.Constants.UserSessionMgr]; cmdUpdate.Parameters[daMgr.BuildParamName(DataManagement.Constants.UserId)].Value = userSessionMgr.UserId; cmdUpdate.Parameters[daMgr.BuildParamName(SessionManagement.Constants.LastModifiedUserCode)].Value = userSessionMgr.UserCode; foreach (DbParameter param in cmdUpdate.Parameters) { if (param.Value == DBNull.Value) { param.Value = GetValueFromModelState(ModelState, param.ParameterName.Substring(1)); } } daMgr.ExecuteNonQuery(cmdUpdate, null, null); } else { ViewBag.NoDataChanged = true; } } return(View(editProfile)); }
/// <summary> /// Removes the session record for the given session code. /// </summary> /// <param name="daMgr">DataAccessMgr object</param> /// <param name="sessionCode">Unique session code</param> public static void Signoff(DataAccessMgr daMgr, Int64 sessionCode) { DbTableDmlMgr dmlDeleteMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE , Constants.UserSessions); dmlDeleteMgr.SetWhereCondition((j) => j.Column(Constants.SessionCode) == j.Parameter(dmlDeleteMgr.MainTable.SchemaName , dmlDeleteMgr.MainTable.TableName , Constants.SessionCode , daMgr.BuildParamName(Constants.SessionCode))); DbCommand cmdDeleteUserSession = daMgr.BuildDeleteDbCommand(dmlDeleteMgr); cmdDeleteUserSession.Parameters[daMgr.BuildParamName(Constants.SessionCode)].Value = sessionCode; daMgr.ExecuteNonQuery(cmdDeleteUserSession, null, null); }
/// <summary> /// Sets or resets an account restriction for the given user identifier /// </summary> /// <param name="daMgr">DataAccessMgr object</param> /// <param name="userId">Unique user identifier</param> /// <param name="removeRestriction">Indicates whether to set or reset the restriction</param> static void Restriction(DataAccessMgr daMgr, string userId, bool removeRestriction) { DbTableDmlMgr dmlUpdate = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE , Constants.UserMaster); dmlUpdate.AddColumn(Constants.SignonRestricted , daMgr.BuildParamName(Constants.SignonRestricted)); dmlUpdate.SetWhereCondition((j) => j.Column(Constants.UserId) == j.Parameter(dmlUpdate.MainTable.SchemaName , dmlUpdate.MainTable.TableName , Constants.UserId , daMgr.BuildParamName(Constants.UserId))); DbCommand cmdUpdate = daMgr.BuildUpdateDbCommand(dmlUpdate); cmdUpdate.Parameters[daMgr.BuildParamName(Constants.UserId)].Value = userId; cmdUpdate.Parameters[daMgr.BuildParamName(Constants.SignonRestricted)].Value = removeRestriction ? 0 : 1; daMgr.ExecuteNonQuery(cmdUpdate, null, null); }
/// <summary> /// Executes the given DbCommand and returns the result. /// If a DbException is raised and a logger class had been provided, /// the method will attempt to Log a debug text version of the dbCommand /// that is backend specific or just log the exception. /// In either case, the exception will be thrown. /// </summary> /// <param name="dbCommand">Database Command Object to execute.</param> /// <returns>Returns int return value.</returns> private int ExecuteNonQuery(DbCommand dbCommand) { return(_daMgr.ExecuteNonQuery(dbCommand, dbCommand.Transaction, null)); }
/// <summary> /// Removes all inactive session records from the database /// </summary> /// <param name="daMgr">DataAcessMgr object</param> public static void CleanupInactiveSessions(DataAccessMgr daMgr) { DbCommand dbCmd = daMgr.DbCmdCacheGetOrAdd("CleanupInactiveUserSessions", BuildCmdDelInActiveUserSessionsList); daMgr.ExecuteNonQuery(dbCmd, null, null); }
/// <summary> /// Method with change the settings of the SignonControl table to the given new settings only if they have not already been changed. /// <para>If </para> /// </summary> /// <param name="lastModifiedUser">The userCode of the user who last updated the record (or null if not changed)</param> /// <param name="lastModifiedDateTime">The DateTime of when the user last updated the record (or null if not changed)</param> /// <param name="newControlSettings">Signon Control Data Strcutre containing the new values.</param> /// <returns>Boolean indicating if record was changed or not.</returns> internal bool ChangeControl(int?lastModifiedByUserCode , DateTime?lastModifiedDateTime , SignonControlStructure newControlSettings) { DbTableDmlMgr dmlChange = _daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE , Constants.SignonControl); dmlChange.AddColumn(Constants.TimeoutSeconds); dmlChange.AddColumn(Constants.SignoffWarningMsg); dmlChange.AddColumn(Constants.ForceSignOff); dmlChange.AddColumn(Constants.RestrictSignon); dmlChange.AddColumn(Constants.StatusSeconds); dmlChange.AddColumn(Constants.RestrictSignonMsg); dmlChange.AddColumn(Constants.FailedAttemptLimit); dmlChange.SetWhereCondition((j) => j.Column(Constants.SignonControl) == j.Parameter(Constants.SignonControl)); DbCommandMgr dbCmdMgr = new DbCommandMgr(_daMgr); DbCommand cmdChangeOrig = _daMgr.BuildChangeDbCommand(dmlChange , Constants.LastModifiedUserCode , Constants.LastModifiedDateTime); cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.ControlCode)].Value = newControlSettings.SessionControlCode; cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.TimeoutSeconds)].Value = Convert.ToInt16(newControlSettings.TimeOutSeconds); cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.SignoffWarningMsg)].Value = newControlSettings.SignoffWarningMsg; cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.ForceSignOff)].Value = newControlSettings.ForceSignoff; cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.RestrictSignon)].Value = newControlSettings.RestrictSignon; cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.RestrictSignonMsg)].Value = newControlSettings.RestrictSignonMsg; cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.StatusSeconds)].Value = newControlSettings.StatusSeconds; cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.FailedAttemptLimit)].Value = newControlSettings.FailedAttemptLimit; if (lastModifiedByUserCode.HasValue) { cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.LastModifiedUserCode)].Value = lastModifiedByUserCode.Value; } if (lastModifiedDateTime.HasValue) { cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.LastModifiedDateTime)].Value = lastModifiedDateTime.Value; } if (newControlSettings.LastModifiedByUserCode.HasValue) { cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.LastModifiedUserCode, true)].Value = newControlSettings.LastModifiedByUserCode.Value; } cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.LastModifiedDateTime, true)].Value = newControlSettings.LastModifiedByDateTime.Value; int rowsAffected = _daMgr.ExecuteNonQuery(cmdChangeOrig, null, null); if (rowsAffected == 1) { _signonControl.FailedAttemptLimit = newControlSettings.FailedAttemptLimit; _signonControl.ForceSignoff = newControlSettings.ForceSignoff; _signonControl.RestrictSignon = newControlSettings.RestrictSignon; _signonControl.RestrictSignonMsg = newControlSettings.RestrictSignonMsg; _signonControl.SignoffWarningMsg = newControlSettings.SignoffWarningMsg; _signonControl.StatusSeconds = newControlSettings.StatusSeconds; _signonControl.TimeOutSeconds = newControlSettings.TimeOutSeconds; _signonControl.LastModifiedByUserCode = newControlSettings.LastModifiedByUserCode; _signonControl.LastModifiedByDateTime = newControlSettings.LastModifiedByDateTime; return(true); } else { return(false); } }