public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { List <DataLibrary.Models.AccountModel> accountModel = SearchAccount( model.EmailAddress, model.Password ); bool matchingFound = accountModel.Count > 0; if (matchingFound) { DataLibrary.Models.AccountModel dbModel = accountModel.First(); // Account Type Indicator if (dbModel.Admin) { Session["UserType"] = "A"; } else if (dbModel.Tenant) { Session["UserType"] = "T"; } else { Session["UserType"] = "P"; Session["PropertyCode"] = dbModel.PropertyCode; } Session["Email"] = dbModel.EmailAddress; // if (dbModel.TwoFactor) { //Session["UserID"] = dbModel.Id; Session["Phone"] = dbModel.PhoneNumber; return(RedirectToAction("VerifyAccount")); } else { //Session["UserID"] = dbModel.Id; Session["User"] = dbModel; return(RedirectToAction("ContentPage")); } } else { ViewBag.ErrorMessage = "Login Failed"; return(View()); } } else { ViewBag.ErrorMessage = "Login Failed"; return(View()); } }
public ActionResult ViewProfile() { ViewBag.Message = "Accounts List"; AccountModel profile = new AccountModel(); //var data = LoadAccounts().FirstOrDefault(); DataLibrary.Models.AccountModel data = (DataLibrary.Models.AccountModel)Session["User"]; profile.FirstName = data.FirstName; profile.LastName = data.LastName; profile.EmailAddress = data.EmailAddress; profile.Tenant = data.Tenant; profile.PropertyCode = data.PropertyCode; return(View(profile)); }
public ActionResult ContentPage() { //this is where all session vars are now set if (Session["User"] != null) { DataLibrary.Models.AccountModel dbModel = (DataLibrary.Models.AccountModel)Session["User"]; Session["ChatName"] = dbModel.FirstName + " " + dbModel.LastName; Session["Admin"] = dbModel.Admin; if (dbModel.Tenant) { Session["TenantID"] = dbModel.Id; DataLibrary.Models.AccountModel propertyManagerModel = SearchPropertyManager(dbModel.PropertyCode); Session["PropertyID"] = propertyManagerModel.Id; } else { Session["PropertyID"] = dbModel.Id; } } return(View()); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { List <DataLibrary.Models.AccountModel> accountModel = SearchAccount( model.EmailAddress, model.Password ); bool matchingFound = accountModel.Count > 0; if (matchingFound) { DataLibrary.Models.AccountModel dbModel = accountModel.First(); if (dbModel.TwoFactor) { Session["UserID"] = dbModel.Id; Session["Phone"] = dbModel.PhoneNumber; return(RedirectToAction("VerifyAccount")); } else { Session["User"] = dbModel; Session["UserID"] = dbModel.Id; return(RedirectToAction("ContentPage")); } } else { ViewBag.ErrorMessage = "Login Failed"; return(View()); } } else { ViewBag.ErrorMessage = "Login Failed"; return(View()); } }
public ActionResult Register(AccountModel model) { DataLibrary.Models.AccountModel propertyManager = new DataLibrary.Models.AccountModel(); if (ModelState.IsValid) { if (model.Tenant) { if (model.PropertyCode == null) { ViewBag.ErrorMessage = "Please supply property code, when registering as a tenant!"; return(View()); } propertyManager = SearchPropertyManager(model.PropertyCode); if (propertyManager == null) { ViewBag.ErrorMessage = "That property code is not a valid property code"; return(View()); } } else { Random random = new Random(); int value = random.Next(1000); string text = value.ToString("000"); model.PropertyCode = (model.FirstName[0] + model.LastName + text).ToLower(); } int recordsCreated = CreateAccount( model.FirstName, model.LastName, model.EmailAddress, model.Password, model.Tenant, model.PropertyCode); var senderEmail = new MailAddress("*****@*****.**"); var receiverEmail = new MailAddress(model.EmailAddress); var password = "******"; var sub = "Welcome to the Maple Building Management App"; string body = ""; if (model.Tenant) { body = "Good day, " + model.FirstName + "!" + "\n\nWe are glad to have you with us!" + "\n\nYou are now registered as a tenant under property managed by " + propertyManager.FirstName + " " + propertyManager.LastName + ". " + "Please access the Maple Building Management web application through here: https://maple-building-management20200215053058.azurewebsites.net/ " + "\n\nSincerely,\n\nMaple Building Management Admin"; } else { body = "Good day, " + model.FirstName + "!" + "\n\nYou are now registered as a property manager with us! We are glad to have you onboard. " + "We aim to be the premier solution for your building management needs." + "\n\nYour property code is " + model.PropertyCode + "\n\nPlease keep a copy of this code with you. This code should be given to your tenants so they can access this application and help you " + "manage the property you are renting to them! Please access the Maple Building Management web application through here: " + "https://maple-building-management20200215053058.azurewebsites.net/ " + "\n\nSincerely,\n\nMaple Building Management Admin"; } var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(senderEmail.Address, password) }; using (var mess = new MailMessage(senderEmail, receiverEmail) { Subject = sub, Body = body }) { smtp.Send(mess); } return(View("SuccessfulRegister", model)); } return(View()); }