예제 #1
0
        public ActionResult LoginAuthentication(MaintenanceModel maintenance)
        {
            var username = maintenance.Username;
            var password = maintenance.Password;

            //if (User.Identity.IsAuthenticated)
            //{
            //    return RedirectToAction("Dashboard", "Home");
            //}
            //System.Web.Helpers.AntiForgery.Validate();
            try
            {
                DBConnection();

                DBMaintenance dBMaintenance = new DBMaintenance();
                maintenance = dBMaintenance.UserAuthentication(maintenance);
            }
            catch
            {
                ViewBag.LoginAuthentication = "Login";
                ViewBag.HeaderError         = string.Format("Unable  to connect to server.");
                ViewBag.MessageError        = string.Format("Check your server connection settings.");

                ViewBag.UserField = username;
                return(View());
            }

            if (maintenance != null)
            {
                if (maintenance.Status == "2")
                {
                    ViewBag.LoginAuthentication = "Login";
                    ViewBag.HeaderError         = string.Format("Account Issue.");
                    ViewBag.MessageError        = string.Format("Your account has been inactive.");

                    ViewBag.UserField = username;
                    return(View());
                }

                else if (maintenance.ResetPassword == 1)
                {
                    if (maintenance.Code.Trim() == password || maintenance.Password.Trim() == "P@ssw0rd")
                    {
                        ViewBag.LoginAuthentication = "ResetPassword";
                        AllModels models = new AllModels();
                        models.Maintenance = maintenance;
                        return(View(models));
                    }
                    else
                    {
                        ViewBag.LoginAuthentication = "Login";
                        ViewBag.HeaderWarning       = string.Format("Reset Password.");
                        ViewBag.MessageWarning      = string.Format("Please Enter Code.");

                        ViewBag.UserField = username;
                        return(View());
                    }
                }
                else
                {
                    if (maintenance.Code == password)
                    {
                        ViewBag.LoginAuthentication = "Login";
                        ViewBag.HeaderError         = string.Format("Login Failed.");
                        ViewBag.MessageError        = string.Format("Username or Password is incorrect.");

                        ViewBag.UserField = username;
                        return(View());
                    }
                    else
                    {
                        Session["UserID"]          = maintenance.UserID;
                        Session["Fullname"]        = maintenance.Fullname;
                        Session["UserRoleID"]      = maintenance.RoleID;
                        Session["UserRole"]        = maintenance.RoleName;
                        Session["Department"]      = maintenance.DepartmentID;
                        Session["GroupID"]         = maintenance.GroupID;
                        Session["DesignationID"]   = maintenance.DesignationID;
                        Session["GroupName"]       = maintenance.Group;
                        Session["DesignationName"] = maintenance.Designation;

                        FormsAuthentication.SetAuthCookie(Session["UserID"].ToString(), false); // render Session into Authentication Cookie

                        SqlDependency.Start(con);
                        SqlDependency.Start(con2);
                        SqlDependency.Start(con3);
                        NotificationComponent NC = new NotificationComponent();
                        NC.group = maintenance.GroupID;
                        NC.Notificaton(maintenance.GroupID);
                        NC.UpdateItemRequestNotificaton();
                        NC.NotificatonItem();
                        NC.NotificatonUpdateItem();
                        return(RedirectToAction("Dashboard", "Home"));
                    }
                }
            }
            else
            {
                ViewBag.LoginAuthentication = "Login";
                ViewBag.HeaderError         = string.Format("Login Failed.");
                ViewBag.MessageError        = string.Format("Username or Password is incorrect.");

                ViewBag.UserField = username;
                return(View());
            }
        }