public virtual bool SetLandlord(User landlord) { if (_landlord.UserType == UserType.landlord) { _landlord = landlord; return true; } return false; }
public void OneTimeSetup() { _agent1 = new Agent(); _agent2 = new Agent(); var office1 = new Office(_agent1); var office2 = new Office(_agent2); _adminUser = new User(null, UserType.admin); _managerUserAgent1 = new User(_agent1, UserType.manager); _employeeUserAgent1 = new User(_agent1, UserType.employee); _tenantUserAgent1 = new User(_agent1, UserType.tenant); _propertyAgent1 = new RentalProperty(office1); _propertyAgent2 = new RentalProperty(office2); _authorisationService = new AuthorisationService(); }
public ActionResult Register(AddAgentModel model) { if (!ModelState.IsValid) { return View(); } // Ok, we have a valid Agent, Main office and first user //if there's a logo, upload it and grab the url... string savedFileName = ""; string fileName = ""; foreach (string file in Request.Files) { var hpf = Request.Files[file] ; if (hpf.ContentLength == 0) continue; fileName = Path.GetFileName(string.Format("{0}{1}",hpf.FileName , DateTime.Now.ToString())); savedFileName = Path.Combine( AppDomain.CurrentDomain.BaseDirectory + "/Content/img/agentLogos/", fileName); hpf.SaveAs(savedFileName); } var agent = new Agent { Name = model.Name, PictureUrl = fileName }; agent.AddPhoneNumber(new PhoneNumber { Description = "Head office number", Name = "Head office number", Number = model.PhoneNumber }); var office = new Office(agent) { AddressLine1 = model.AddressLine1, AddressLine2 = model.AddressLine2, Postcode = model.Postcode, Name = model.OfficeName, HouseNumber = model.HouseNumber, Town = model.Town }; agent.AddOffice(office); // Check the email address has not already been used in the system... var emailAddressInUse = _userRepository.FindOne(new UserByEmailSpecification(model.EmailAddress)); if (emailAddressInUse != null) { // this email address is already registered ModelState.AddModelError("EmailAddress", "This email address is already registered in the system. Please choose a different email address for this agent account."); return View(); } var mainUser = new User(agent, UserType.manager) { Email = model.EmailAddress, FirstName = model.FirstName, LastName = model.LastName }; var result = _authenticationService.UpdatePassword(mainUser, model.Password); switch (result) { case Domain.Services.UpdatePasswordResult.notLongEnough: ModelState.AddModelError("Password", "Password must be at least 5 charaters long"); return View(); case Domain.Services.UpdatePasswordResult.reservedWord: ModelState.AddModelError("Password", "Password is too weak, please try another phrase"); return View(); case Domain.Services.UpdatePasswordResult.unknown: throw new Exception("unknown password update error..."); } // The password was succesful and their hash has been set. // save the new agent and the user and log them in... _agentRepository.Save(agent); _userRepository.Save(mainUser); var loginResult = _authenticationService.Login(model.EmailAddress, model.Password); // the log in result really should be successful - chuck exception if not if (loginResult != Domain.Services.LoginResult.successful) { throw new Exception("User registered successfully, but something went wrong authenticating them???"); } FormsAuthentication.SetAuthCookie(model.EmailAddress, false); this.SetLoggedInUser(mainUser); return RedirectToAction("RedirectLoggedInUserOnwards", "Authentication"); }
public void SetLoggedInUser(User user) { Session["LoggedInUser"] = user; }