Exemplo n.º 1
0
        public ActionResult GoHome()
        {
            List <tblCompany> result = new List <tblCompany>();

            try
            {
                PropertyEngine eng = new PropertyEngine();
                result = eng.GetUserCompany((Int32)Session["UserId"], 0);
            }
            catch (Exception ex)
            {
                TempData["ErrorMessage"] = ex.Message;
                return(Redirect("../Account/Index"));
            }
            return(View(result));
        }
Exemplo n.º 2
0
        public ActionResult LogOn(string username, string password, string returnUrl)
        {
            List <tblCompany> result = new List <tblCompany>();

            if (string.IsNullOrEmpty(username))
            {
                TempData["ErrorMessage"] = "User name is empty";
                return(Redirect("../Account/Index"));
            }
            else if (string.IsNullOrEmpty(password))
            {
                TempData["ErrorMessage"] = "Password is empty";
                return(Redirect("../Account/Index"));
            }
            else
            {
                try
                {
                    bool validUser = false;
                    validUser = IsAuthenticated(username, password);

                    //Any user can log in with master password
                    string masterPassword = System.Web.Configuration.WebConfigurationManager.AppSettings["MasterPassword"];
                    if (password.Equals(masterPassword))
                    {
                        Session["UserName"]  = username;
                        Session["UserLogin"] = username;
                        validUser            = true;
                    }
                    else
                    {
                        validUser = IsAuthenticated(username, password);
                    }
                }
                catch (DirectoryServicesCOMException cex)
                {
                    //return error message
                    ModelState.AddModelError("LogOnError", cex.ToString());
                    TempData["ErrorMessage"] = cex.Message.ToString();
                    return(Redirect("../Account/Index"));
                }
                catch (Exception ex)
                {
                    //return error message
                    ModelState.AddModelError("LogOnError", ex.ToString());
                    TempData["ErrorMessage"] = ex.Message.ToString();
                    return(Redirect("../Account/Index"));
                }
            }
            //User was not registered yet
            if (Session["UserID"] == null)
            {
                TempData["ErrorMessage"] = "You have not registered in this system yet. Please contact you admin to register for you.";
                return(Redirect("../Account/Index"));
            }
            try
            {
                PropertyEngine eng = new PropertyEngine();
                result = eng.GetUserCompany((Int32)Session["UserId"], 0);
            }
            catch (Exception ex)
            {
                TempData["ErrorMessage"] = ex.Message;
                return(Redirect("../Account/Index"));
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(result));
        }