///////////////////////////////////////////////////////////////// /// <summary> /// Is the page the page authorized /// </summary> ///////////////////////////////////////////////////////////////// public bool IsAuthorized(SYSTEMUSER systemUser) { // no roles for this page - no need to authenticate if (this.Roles.Count == 0) { return(true); } // user is logged in, and page has * role if (systemUser != null && (this.Roles.Count == 1) && this.Roles[0] == "*") { return(true); } // check if user has specific role if (roles != null && systemUser != null) { if (systemUser.ADMINISTRATOR == 1) { return(true); } } return(false); }
/// <summary> /// Login using just the ID (internal use only) /// </summary> /// <param name="id">user id</param> /// <returns>success or failure</returns> public bool Login(int id) { using (var ctx = new Entities()) { var user = ctx.SYSTEMUSERs.FirstOrDefault(u => u.DELETED == 0 && u.ID == id); if (user == null) { return(false); } user.LASTLOGGEDON = DateTime.Now; // audit Audit.Log(ctx, AuditType.Login, "Security", user.ID); ctx.SaveChanges(); // save to session LoggedInUser = user; return(true); } }
private bool CopyFromForm() { using (var ctx = new Entities()) { try { var userCheck = ctx.SYSTEMUSERs.FirstOrDefault( u => u.EMAIL == txtEmailAddress.Text && u.ID != btnFormButtons.EntityID); if (userCheck != null) { ShowMessage(MessageType.Error, "This email address is already registered"); return(false); } if (btnFormButtons.EntityID.HasValue) { var id = btnFormButtons.EntityID; var dataSource = ctx.SYSTEMUSERs.FirstOrDefault(u => u.ID == id); PopulateEntity(ref dataSource); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("User Edited. ID: {0}", dataSource.ID), LoggedInUser.ID); } else { var dataSource = new SYSTEMUSER { CREATEDON = DateTime.Now, DELETED = 0, LASTLOGGEDON = DateTime.Now }; PopulateEntity(ref dataSource); ctx.AddToSYSTEMUSERs(dataSource); Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName, string.Format("User Added. Email: {0}", dataSource.EMAIL), LoggedInUser.ID); } ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save User", ex); ShowMessage(MessageType.Error, "There was an error saving this record"); } } return(false); }
private void PopulateEntity(ref SYSTEMUSER entity) { entity.EMAIL = txtEmailAddress.Text; if (!string.IsNullOrEmpty(txtPassword.Text)) { entity.PASSWORD = txtPassword.Text; } entity.NAME = txtName.Text; entity.ORGANISATION = txtOrganisation.Text; entity.AREAOFRESEARCH = txtAreaOfResearch.Text; entity.URL = txtURL.Text; entity.TWITTER = txtTwitter.Text; entity.FACEBOOK = txtFacebook.Text; entity.LINKEDIN = txtLinkedIn.Text; }
///////////////////////////////////////////////////////////////// /// <summary> /// Send email that report is complete /// </summary> ///////////////////////////////////////////////////////////////// public static void SendReportCompelted(SYSTEMUSER user, int reportid) { var template = GetTemplate("template.txt"); var from = ConfigurationSettings.AppSettings["DefaultFrom"]; const string subject = "Report Completed"; // send message if (template != string.Empty) { var reportURL = string.Format("{0}/reports/result.aspx?ID={1}", ConfigurationSettings.AppSettings["WebURL"], reportid); // replacement template = template.Replace("[link]", reportURL); template = template.Replace("[name]", user.NAME); } if (!string.IsNullOrEmpty(user.EMAIL)) { Communication.SendEmail(from, user.EMAIL, subject, template); } }
private bool CopyFromForm() { using (var ctx = new Entities()) { if (txtPassword.Text != txtPasswordConfirm.Text) { ShowMessage(MessageType.Error, "Passwords do not match"); return(false); } var user = ctx.SYSTEMUSERs.FirstOrDefault(u => u.DELETED == 0 && u.EMAIL == txtEmailAddress.Text); if (user != null) { ShowMessage(MessageType.Error, "This email address is already registered"); return(false); } var dataSource = new SYSTEMUSER { EMAIL = txtEmailAddress.Text, PASSWORD = txtPassword.Text, NAME = txtName.Text, ORGANISATION = txtOrganisation.Text, AREAOFRESEARCH = txtAreaOfResearch.Text, CREATEDON = DateTime.Now, DELETED = 0, LASTLOGGEDON = DateTime.Now }; ctx.AddToSYSTEMUSERs(dataSource); Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName, string.Format("New User Registered. Email: {0}", dataSource.EMAIL), dataSource.ID); ctx.SaveChanges(); return(true); } }
/// <summary> /// Clear the current user /// </summary> public void Logout() { LoggedInUser = null; }