示例#1
0
        //[MethodImpl(MethodImplOptions.Synchronized)]
        //[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        /// <summary>
        /// Entry Point of Framework
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public ActionResult Index(FormCollection form)
        {
            //if (!User.Identity.IsAuthenticated)
            //{
            //    // Required to allow javascript redirection through to browser
            //    this.Response.TrySkipIisCustomErrors = true;
            //    this.Response.Status = "401 Unauthorized";
            //    this.Response.StatusCode = 401;
            //    // note that the following line is .NET 4.5 or later only
            //    // otherwise you have to suppress the return URL etc manually!
            //    this.Response.SuppressFormsAuthenticationRedirect = true;
            //    // If we got this far, something failed

            //}


            var url = CloudLogin.IsAllowedToLogin(Request.Url.ToString());

            if (!string.IsNullOrEmpty(url))
            {
                return(RedirectPermanent(url));
            }

            VAdvantage.DataBase.DBConn.SetConnectionString();//Init database conection
            LoginModel model = null;

            if (User.Identity.IsAuthenticated)
            {
                try
                {
                    //var conf = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
                    //  SessionStateSection section = (SessionStateSection) conf.GetSection("system.web/sessionState");
                    // int timeout = (int) section.Timeout.TotalMinutes;
                    Session.Timeout = 20; // ideal timout
                }
                catch
                {
                }


                //AccountController a = new AccountController();
                //a.LogOff();
                FormsIdentity ident = User.Identity as FormsIdentity;
                Ctx           ctx   = null;
                if (ident != null)
                {
                    FormsAuthenticationTicket ticket = ident.Ticket;
                    string       loginContextString  = ticket.UserData;// get login context string from Form Ticket
                    LoginContext lCtx = JsonHelper.Deserialize(loginContextString, typeof(LoginContext)) as LoginContext;
                    IDataReader  dr   = null;



                    //create class from string
                    string key = "";
                    if (Session["ctx"] != null)
                    {
                        ctx = Session["ctx"] as Ctx;

                        //Update Old Session
                        MSession session = MSession.Get(ctx, false);
                        if (session != null)
                        {
                            session.Logout();
                        }

                        key = ctx.GetSecureKey();

                        //if (Session.Timeout < 2)
                        //{
                        SessionEventHandler.SessionEnd(ctx);
                        Session.Timeout = 17;
                        //}
                        Session["ctx"] = null;
                    }
                    ctx = new Ctx(lCtx.ctxMap); //cretae new context
                    if (key != "")
                    {
                        ctx.SetSecureKey(key);
                    }
                    Session["ctx"] = ctx;

                    //get login Language object on server
                    var loginLang = ctx.GetAD_Language();

                    Language l = Language.GetLanguage(ctx.GetAD_Language()); //Language.GetLoginLanguage();
                    l = VAdvantage.Utility.Env.VerifyLanguage(ctx, l);

                    ctx.SetContext(VAdvantage.Utility.Env.LANGUAGE, l.GetAD_Language());
                    ctx.SetContext(VAdvantage.Utility.Env.ISRIGHTTOLEFT, VAdvantage.Utility.Env.IsRightToLeft(loginLang) ? "Y" : "N");
                    new VAdvantage.Login.LoginProcess(ctx).LoadSysConfig();


                    ViewBag.culture   = ctx.GetAD_Language();
                    ViewBag.direction = ctx.GetIsRightToLeft() ? "rtl" : "ltr";

                    //Change Authentication
                    model                           = new LoginModel();
                    model.Login1Model               = new Login1Model();
                    model.Login2Model               = new Login2Model();
                    model.Login1Model.UserName      = User.Identity.Name;
                    model.Login1Model.LoginLanguage = ctx.GetAD_Language();

                    model.Login2Model.Role      = ctx.GetAD_Role_ID().ToString();
                    model.Login2Model.Client    = ctx.GetAD_Client_ID().ToString();
                    model.Login2Model.Org       = ctx.GetAD_Org_ID().ToString();
                    model.Login2Model.Warehouse = ctx.GetAD_Warehouse_ID().ToString();


                    var RoleList      = new List <KeyNamePair>();
                    var ClientList    = new List <KeyNamePair>();
                    var OrgList       = new List <KeyNamePair>();
                    var WareHouseList = new List <KeyNamePair>();

                    LoginHelper.Login(model, out RoleList);

                    //string diableMenu = ctx.GetContext("#DisableMenu");
                    Helpers.MenuHelper mnuHelper = new Helpers.MenuHelper(ctx); // inilitilize menu class

                    bool disableMenu = MRole.GetDefault(ctx).IsDisableMenu();
                    ctx.SetIsBasicDB(mnuHelper.GetIsBasicDB());


                    // If Home page not linked OR home page Linked BUT Menu is not disabled , then show home page.
                    // If Home is linked as well as menu is disabled then don't load Default Home Page Settings
                    if (MRole.GetDefault(ctx).GetHomePage_ID() == 0 || (MRole.GetDefault(ctx).GetHomePage_ID() > 0 && !disableMenu))
                    {
                        HomeModels hm = new HomeModels();
                        objHomeHelp     = new HomeHelper();
                        hm              = objHomeHelp.getLoginUserInfo(ctx, 32, 32);
                        ViewBag.UserPic = hm.UsrImage;
                    }

                    if (!disableMenu) // if menu is not disabled, only then load menu.
                    {
                        //get current user info
                        ViewBag.Menu        = mnuHelper.GetMenuTree();    // create tree
                        Session["barNodes"] = ViewBag.Menu.GetBarNodes(); /* add is session to get it in favourite call */

                        ViewBag.TreeHtml = mnuHelper.GetMenuTreeUI(ViewBag.Menu.GetRootNode(), @Url.Content("~/"));
                    }

                    ViewBag.disableMenu = disableMenu;

                    mnuHelper.dispose();

                    //  LoginHelper.GetClients(id)

                    ClientList    = LoginHelper.GetClients(ctx.GetAD_Role_ID());                                          // .Add(new KeyNamePair(ctx.GetAD_Client_ID(), ctx.GetAD_Client_Name()));
                    OrgList       = LoginHelper.GetOrgs(ctx.GetAD_Role_ID(), ctx.GetAD_User_ID(), ctx.GetAD_Client_ID()); // .Add(new KeyNamePair(ctx.GetAD_Org_ID(), ctx.GetAD_Org_Name()));
                    WareHouseList = LoginHelper.GetWarehouse(ctx.GetAD_Org_ID());                                         // .Add(new KeyNamePair(ctx.GetAD_Warehouse_ID(), ctx.GetContext("#M_Warehouse_Name")));


                    ViewBag.RoleList      = RoleList;
                    ViewBag.ClientList    = ClientList;
                    ViewBag.OrgList       = OrgList;
                    ViewBag.WarehouseList = WareHouseList;
                    lock (_lock)    // Locked bundle Object and session Creation to handle concurrent requests.
                    {
                        //Cretae new Sessin
                        MSession sessionNew = MSession.Get(ctx, true, GetVisitorIPAddress(true));


                        var lst = VAdvantage.ModuleBundles.GetStyleBundles(); //Get All Style Bundle
                        foreach (var b in lst)
                        {
                            if (!BundleTable.Bundles.Contains(b))
                            {
                                BundleTable.Bundles.Add(b); //Add in Mvc Bundle Table
                            }
                        }

                        var lstRTLStyle = VAdvantage.ModuleBundles.GetRTLStyleBundles(); //Get All Script Bundle

                        foreach (var b in lstRTLStyle)
                        {
                            if (!BundleTable.Bundles.Contains(b))
                            {
                                BundleTable.Bundles.Add(b); //Add in Mvc Bundlw Table
                            }
                        }

                        var lstScript = VAdvantage.ModuleBundles.GetScriptBundles(); //Get All Script Bundle

                        foreach (var b in lstScript)
                        {
                            if (!BundleTable.Bundles.Contains(b))
                            {
                                BundleTable.Bundles.Add(b); //Add in Mvc Bundlw Table
                            }
                        }

                        ViewBag.LibSuffix   = "";
                        ViewBag.FrameSuffix = "_v1";
                        int libFound = 0;
                        foreach (Bundle b in BundleTable.Bundles)
                        {
                            if (b.Path.Contains("ViennaBase") && b.Path.Contains("_v") && ViewBag.LibSuffix == "")
                            {
                                ViewBag.LibSuffix = Util.GetValueOfInt(ctx.GetContext("#FRONTEND_LIB_VERSION")) > 2
                                                      ? "_v3" : "_v2";
                                libFound++;
                            }

                            if (b.Path.Contains("VIS") && b.Path.Contains("_v"))
                            {
                                ViewBag.FrameSuffix = Util.GetValueOfInt(ctx.GetContext("#FRAMEWORK_VERSION")) > 1
                                                      ? "_v2" : "_v1";
                                libFound++;
                            }
                            if (libFound >= 2)
                            {
                                break;
                            }
                        }
                        //check system setting// set to skipped lib
                    }
                }
            }

            else
            {
                model             = new LoginModel();
                model.Login1Model = new Login1Model();
                //model.Login1Model.UserName = "******";
                //model.Login1Model.Password = "******";
                model.Login1Model.LoginLanguage = "en_US";
                model.Login2Model = new Login2Model();

                ViewBag.RoleList      = new List <KeyNamePair>();
                ViewBag.OrgList       = new List <KeyNamePair>();
                ViewBag.WarehouseList = new List <KeyNamePair>();
                ViewBag.ClientList    = new List <KeyNamePair>();

                ViewBag.Languages = Language.GetLanguages();

                Session["ctx"]    = null;
                ViewBag.direction = "ltr";

                ViewBag.LibSuffix = "";
                foreach (Bundle b in BundleTable.Bundles)
                {
                    if (b.Path.Contains("ViennaBase") && b.Path.Contains("_v"))
                    {
                        ViewBag.LibSuffix = "_v2";
                        break;
                    }
                }
            }
            return(View(model));
        }
示例#2
0
        //[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        public ActionResult Index(FormCollection form)
        {
            LoginModel model = null;

            if (User.Identity.IsAuthenticated)
            {
                VAdvantage.DataBase.DBConn.SetConnectionString();//Init database conection


                //AccountController a = new AccountController();
                //a.LogOff();
                FormsIdentity ident = User.Identity as FormsIdentity;
                Ctx           ctx   = null;
                if (ident != null)
                {
                    FormsAuthenticationTicket ticket = ident.Ticket;
                    string       loginContextString  = ticket.UserData;// get login context string from Form Ticket
                    LoginContext lCtx = JsonHelper.Deserialize(loginContextString, typeof(LoginContext)) as LoginContext;



                    //create class from string
                    string key = "";
                    if (Session["ctx"] != null)
                    {
                        ctx            = Session["ctx"] as Ctx;
                        key            = ctx.GetSecureKey();
                        Session["ctx"] = null;
                    }
                    ctx = new Ctx(lCtx.ctxMap); //cretae new context
                    if (key != "")
                    {
                        ctx.SetSecureKey(key);
                    }
                    Session["ctx"] = ctx;

                    //get login Language object on server
                    var loginLang = ctx.GetAD_Language();

                    Language l = Language.GetLanguage(ctx.GetAD_Language()); //Language.GetLoginLanguage();
                    l = VAdvantage.Utility.Env.VerifyLanguage(ctx, l);

                    ctx.SetContext(VAdvantage.Utility.Env.LANGUAGE, l.GetAD_Language());
                    ctx.SetContext(VAdvantage.Utility.Env.ISRIGHTTOLEFT, VAdvantage.Utility.Env.IsRightToLeft(loginLang) ? "Y" : "N");

                    //get current user info
                    HomeModels hm = new HomeModels();
                    objHomeHelp     = new HomeHelper();
                    hm              = objHomeHelp.getLoginUserInfo(ctx, 32, 32);
                    ViewBag.UserPic = hm.UsrImage;

                    Helpers.MenuHelper mnuHelper = new Helpers.MenuHelper(ctx); // inilitilize menu class

                    ViewBag.Menu        = mnuHelper.GetMenuTree();              // create tree
                    Session["barNodes"] = ViewBag.Menu.GetBarNodes();           /* add is session to get it in favourite call */

                    ViewBag.TreeHtml = mnuHelper.GetMenuTreeUI(ViewBag.Menu.GetRootNode(), @Url.Content("~/"));
                    // create tree html

                    ViewBag.culture   = ctx.GetAD_Language();
                    ViewBag.direction = ctx.GetIsRightToLeft() ? "rtl" : "ltr";
                    ctx.SetIsBasicDB(mnuHelper.GetIsBasicDB());

                    mnuHelper.dispose();



                    //Change Authentication
                    model                           = new LoginModel();
                    model.Login1Model               = new Login1Model();
                    model.Login2Model               = new Login2Model();
                    model.Login1Model.UserName      = User.Identity.Name;
                    model.Login1Model.LoginLanguage = ctx.GetAD_Language();

                    model.Login2Model.Role      = ctx.GetAD_Role_ID().ToString();
                    model.Login2Model.Client    = ctx.GetAD_Client_ID().ToString();
                    model.Login2Model.Org       = ctx.GetAD_Org_ID().ToString();
                    model.Login2Model.Warehouse = ctx.GetAD_Warehouse_ID().ToString();


                    var RoleList      = new List <KeyNamePair>();
                    var ClientList    = new List <KeyNamePair>();
                    var OrgList       = new List <KeyNamePair>();
                    var WareHouseList = new List <KeyNamePair>();

                    LoginHelper.Login(model, out RoleList);

                    //  LoginHelper.GetClients(id)

                    ClientList    = LoginHelper.GetClients(ctx.GetAD_Role_ID());                                          // .Add(new KeyNamePair(ctx.GetAD_Client_ID(), ctx.GetAD_Client_Name()));
                    OrgList       = LoginHelper.GetOrgs(ctx.GetAD_Role_ID(), ctx.GetAD_User_ID(), ctx.GetAD_Client_ID()); // .Add(new KeyNamePair(ctx.GetAD_Org_ID(), ctx.GetAD_Org_Name()));
                    WareHouseList = LoginHelper.GetWarehouse(ctx.GetAD_Org_ID());                                         // .Add(new KeyNamePair(ctx.GetAD_Warehouse_ID(), ctx.GetContext("#M_Warehouse_Name")));


                    ViewBag.RoleList      = RoleList;
                    ViewBag.ClientList    = ClientList;
                    ViewBag.OrgList       = OrgList;
                    ViewBag.WarehouseList = WareHouseList;
                    MSession session = MSession.Get(ctx, true);
                }
            }

            else
            {
                model             = new LoginModel();
                model.Login1Model = new Login1Model();
                //model.Login1Model.UserName = "******";
                //model.Login1Model.Password = "******";
                model.Login1Model.LoginLanguage = "en_US";
                model.Login2Model = new Login2Model();

                ViewBag.RoleList      = new List <KeyNamePair>();
                ViewBag.OrgList       = new List <KeyNamePair>();
                ViewBag.WarehouseList = new List <KeyNamePair>();
                ViewBag.ClientList    = new List <KeyNamePair>();
                Session["ctx"]        = null;
                ViewBag.direction     = "ltr";
            }
            return(View(model));
        }