private static UserM LoadUserFromDatabase(DatabaseCall dbc) { UserM newUser = new UserM(); System.Data.DataSet ds = new System.Data.DataSet(); dbc.Fill(ds); if ((ds.Tables.Count <= 0) || (ds.Tables[0].Rows.Count <= 0)) { return(newUser); } newUser._userID = Convert.ToInt32(ds.Tables[0].Rows[0]["UserID"]); newUser._lastName = ds.Tables[0].Rows[0]["LastName"].ToString(); newUser._middleName = ds.Tables[0].Rows[0]["MiddleName"].ToString(); newUser._firstName = ds.Tables[0].Rows[0]["FirstName"].ToString(); newUser._emailAddress = ds.Tables[0].Rows[0]["Email"].ToString(); newUser._universityID = ds.Tables[0].Rows[0]["UniversityIdentifier"].ToString(); newUser._username = ds.Tables[0].Rows[0]["UserName"].ToString(); newUser._password = ds.Tables[0].Rows[0]["Password"].ToString(); newUser._lastUpdatedDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["LastUpdatedDate"].ToString()); newUser._lastUpdatedUserID = Convert.ToInt32(ds.Tables[0].Rows[0]["LastUpdatedUserID"]); newUser._changedPassword = Convert.ToBoolean(ds.Tables[0].Rows[0]["ChangedPassword"]); return(newUser); }
public void SendPasswordToUser() { // use Assignment Manager sysadmin email UserM amsaUser = UserM.Load(Constants.ASSIGNMENTMANAGER_SYSTEM_ADMIN_USERID); string sentByEmail = amsaUser.EmailAddress; string emailSubject = SharedSupport.GetLocalizedString("User_EmailSubject"); string[] replacements = new string[2] { this._username, this._password }; string emailBody = SharedSupport.GetLocalizedString("User_EmailBody", replacements); MessageM.SendMessage(sentByEmail, this._emailAddress, emailSubject, emailBody); }
public static void sendEmailMessageToCourse(string subject, string body, string link, int courseId) { if (!Convert.ToBoolean(SharedSupport.UsingSmtp)) { throw (new System.Exception(SharedSupport.GetLocalizedString("Global_NoSMTP"))); } try { // validation if (body.Equals(String.Empty)) { throw new ArgumentException(SharedSupport.GetLocalizedString("SendEmailMessage_InvalidBody")); } if (subject.Equals(String.Empty)) { throw new ArgumentException(SharedSupport.GetLocalizedString("SendEmailMessage_InvalidSubject")); } string mailTo = ""; System.Data.DataSet ds = new System.Data.DataSet(); //use generic Assignment Manager From string sentByEmail = string.Empty; UserList ul = UserList.GetListFromCourse(courseId); int[] userIDs = ul.UserIDList; for (int i = 0; i < userIDs.Length; i++) { UserM user = UserM.Load(userIDs[i]); mailTo += user.EmailAddress + ";"; } // use Assignment Manager sysadmin email UserM amsaUser = UserM.Load(Constants.ASSIGNMENTMANAGER_SYSTEM_ADMIN_USERID); sentByEmail = amsaUser.EmailAddress; // add the formatting and action link body += "\n" + "\n" + link; // send email SendMessage(sentByEmail, mailTo, subject, body); } catch (System.Exception ex) { SharedSupport.HandleError(ex); } }
public static UserM AuthenticateUser(string username, string password) { UserM user = UserM.LoadByUserName(username); //Compare the hashed version of the password stored in the db to the hashed version of the password entered. Byte[] passwd = SharedSupport.ConvertStringToByteArray(password.Trim()); byte[] hashValue = ((HashAlgorithm)CryptoConfig.CreateFromName(Constants.HashMethod)).ComputeHash(passwd); if (user.Password != BitConverter.ToString(hashValue)) { return(new UserM()); } else { return(user); } }
public void SendNotifications(object sender, System.Timers.ElapsedEventArgs args) { // disable the timer timer.Enabled = false; try { // use Assignment Manager sysadmin email UserM amsaUser = UserM.Load(Constants.ASSIGNMENTMANAGER_SYSTEM_ADMIN_USERID); string sentByEmail = amsaUser.EmailAddress; System.Data.DataSet dsAssignmentList = new System.Data.DataSet(); DatabaseCall dbc = new DatabaseCall("Notifications_GetAssignmentList", DBCallType.Select); dbc.Fill(dsAssignmentList); if (dsAssignmentList.Tables[0].Rows.Count <= 0) { return; } for (int j = 0; j < dsAssignmentList.Tables[0].Rows.Count; j++) { int assignmentID = Convert.ToInt32(dsAssignmentList.Tables[0].Rows[j]["AssignmentID"]); // send the notifications try { ////////////////////////////////////////////////////////////////////// /// Past Due Notifications ////////////////////////////////////////////////////////////////////// System.Data.DataSet ds = new System.Data.DataSet(); dbc = new DatabaseCall("Notifications_BrowsePastDueNotifications", DBCallType.Select); dbc.AddParameter("AssignmentID", assignmentID); dbc.Fill(ds); if (ds.Tables[0].Rows.Count <= 0) { continue; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["AssignmentID"] != DBNull.Value) { string assignName = ds.Tables[0].Rows[i]["ShortName"].ToString(); DateTime dueDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["DueDate"]); string[] AssignmentInfo = new string[] { assignName, string.Format("{0:d}", dueDate) }; string pastDueSubject = SharedSupport.GetLocalizedString("Notification_PastDueSubject", AssignmentInfo); string pastDueBody = SharedSupport.GetLocalizedString("Notification_PastDueBody", AssignmentInfo); string reminderSubject = SharedSupport.GetLocalizedString("Notification_ReminderSubject", AssignmentInfo); string reminderBody = SharedSupport.GetLocalizedString("Notification_ReminderBody", AssignmentInfo); TimeSpan difference = dueDate - DateTime.Today; if (Convert.ToBoolean(ds.Tables[0].Rows[i]["SendPastDue"]) && (difference.Days == -1 * Convert.ToInt32(ds.Tables[0].Rows[i]["PastDueWarningDays"]))) { UserM user = UserM.Load(Convert.ToInt32(ds.Tables[0].Rows[i]["UserID"])); MessageM.SendMessage(sentByEmail, user.EmailAddress, pastDueSubject, pastDueBody); } if (Convert.ToBoolean(ds.Tables[0].Rows[i]["SendReminders"]) && (difference.Days == Convert.ToInt32(ds.Tables[0].Rows[i]["ReminderWarningDays"]))) { UserM user = UserM.Load(Convert.ToInt32(ds.Tables[0].Rows[i]["UserID"])); MessageM.SendMessage(sentByEmail, user.EmailAddress, reminderSubject, reminderBody); } } } } catch (System.Exception ex) { SharedSupport.HandleError(ex); } } } catch (System.Exception ex) { SharedSupport.HandleError(ex); } finally { // reset the interval for the next event timer.Interval = millisecondsToMidnight(); // re-enable the timer timer.Enabled = true; } }