protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); var context = new DREAMContext(); var initializeDomain = new CreateDatabaseIfNotExists<DREAMContext>(); var initializeMigrations = new MigrateDatabaseToLatestVersion<DREAMContext, Configuration>(); //initializeDomain.InitializeDatabase(context); //initializeMigrations.InitializeDatabase(context); //using (FSDirectory d = FSDirectory.Open(new DirectoryInfo(SearchIndex.DirPath))) //{ // SearchAutoComplete sac = new SearchAutoComplete(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/SearchAutocompleteIndex"); // sac.BuildAutoCompleteIndex(d, "Keywords"); //} Database.SetInitializer(new MigrateDatabaseToLatestVersion<DREAMContext, Configuration>()); #if DEBUG && FALSE Database.SetInitializer(new DREAM.Models.DREAMContextInitializer()); #endif }
public LogFilterModel() { DREAMContext db = new DREAMContext(); this.Logs = db.Logs.ToList(); this.page = 1; }
public void CreateUser() { using (DREAMContext db = new DREAMContext()) { Assert.AreEqual(1, db.PreviousPasswords.Where(p => p.UserID.Equals((Guid)user.ProviderUserKey)).Count()); } }
public static UserProfile GetFor(MembershipUser user) { using (DREAMContext db = new DREAMContext()) { return db.UserProfiles.Find((Guid)user.ProviderUserKey); } }
public LogFilterModel(int? request, String username, String actn, DateTime? before, DateTime? after, int page) { DREAMContext db = new DREAMContext(); this.Logs = db.Logs.ToList(); this.RequestID = request; this.UserName = username; this.Action = actn; this.Before = before; this.After = after; this.page = page; }
//Returns true if the password can be used by the user, //false if the password has been recently used by the user. public static bool CheckPassword(MembershipUser user, string password) { string hashAlgorithm = Membership.HashAlgorithmType; DateTime checkPasswordsAfter = DateTime.Now - new TimeSpan(253, 0, 0, 0); using(DREAMContext db = new DREAMContext()) { foreach(PreviousPassword prevPwd in db.PreviousPasswords.Where(p => p.UserID.Equals((Guid)user.ProviderUserKey) && p.Timestamp > checkPasswordsAfter)) { string passwordHash = prevPwd.EncodePassword(password, prevPwd.PasswordSalt); if(passwordHash == prevPwd.Password) return false; } } return true; }
public void tumourGroupEditLogicTest() { TumourGroup last = db.TumourGroups.ToArray().Last(); last.Code = "TSTEdit"; last.FullName = "TumourGroupAddLogicTestEdit"; ActionResult result = dDAdminController.Edit(last, "TumourGroup"); Assert.AreEqual("System.Web.Mvc.RedirectToRouteResult", result.GetType().FullName); DREAMContext db2 = new DREAMContext(); TumourGroup justChanged = db2.TumourGroups.Find(last.ID); Assert.IsTrue(justChanged.Code.Equals("TSTEdit") && justChanged.FullName.Equals("TumourGroupAddLogicTestEdit")); }
public void tumourGroupDeleteLogicTest() { TumourGroup last = db.TumourGroups.ToArray().Last(); bool original = last.Enabled; ActionResult result = dDAdminController.Delete(last.ID, "TumourGroup"); Assert.AreEqual("System.Web.Mvc.RedirectToRouteResult", result.GetType().FullName); DREAMContext db2 = new DREAMContext(); TumourGroup lastChanged = db2.TumourGroups.Find(last.ID); Assert.IsTrue(!original == lastChanged.Enabled); }
public void requesterTypeEditLogicTest() { RequesterType last = db.RequesterTypes.ToArray().Last(); last.Code = "TSTEdit"; last.FullName = "RequesterTypeAddLogicTestEdit"; ActionResult result = dDAdminController.Edit(last, "RequesterType"); Assert.AreEqual("System.Web.Mvc.RedirectToRouteResult", result.GetType().FullName); DREAMContext db2 = new DREAMContext(); RequesterType justChanged = db2.RequesterTypes.Find(last.ID); Assert.IsTrue(justChanged.Code.Equals("TSTEdit") && justChanged.FullName.Equals("RequesterTypeAddLogicTestEdit")); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password)) { using (DREAMContext db = new DREAMContext()) { MembershipUser user = Membership.GetUser(model.UserName); if (user.LastPasswordChangedDate < DateTime.Now.AddDays(-42)) { RouteValueDictionary routes = new RouteValueDictionary(); routes.Add("userName", model.UserName); routes.Add("success", true); routes.Add("statusMessage", "Your Password is greater than 42 days old. Please change your password to continue using the DREAM system."); return RedirectToAction("ChangePassword", "Users", routes); } } FormsAuthentication.RedirectFromLoginPage(model.UserName, model.RememberMe); return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }
// creates and save a PreviousPassword object for the given user's password data private void recordCurrentPassword(MembershipUser user) { Tuple<MembershipPasswordFormat, string, string> currentPasswordData = ExtractPasswordData(user); using(DREAMContext db = new DREAMContext()) { PreviousPassword prevPwd = new PreviousPassword { UserID = (Guid)user.ProviderUserKey, PasswordFormat = currentPasswordData.Item1, PasswordSalt = currentPasswordData.Item2, Password = currentPasswordData.Item3 }; db.PreviousPasswords.Add(prevPwd); db.SaveChanges(); } }
//Return the passwordResetRequest object for the given user //Sends an email to the user with a link to the PasswordResetRequest's page public static PasswordResetRequest GenerateFor(MembershipUser user) { PasswordResetRequest resetReq = null; using (DREAMContext db = new DREAMContext()) { resetReq = new PasswordResetRequest(); { resetReq.ID = PasswordResetRequest.GenerateNewID(); resetReq.UserID = (Guid)user.ProviderUserKey; } db.SaveChanges(); String newPassword = user.ResetPassword(); SendEmail("*****@*****.**", user.Email, "", "", "DREAM Password Reset", newPassword); return resetReq; } }
//Return the new ID generated //If the ID already exists, generate a new ID public static long GenerateNewID() { byte[] buffer = Guid.NewGuid().ToByteArray(); long id = BitConverter.ToInt64(buffer, 0); using (DREAMContext db = new DREAMContext()) { if (db.PasswordResetRequests.Where(p => p.ID == id).Count() != 0) { id = GenerateNewID(); } } return id; }