Example #1
0
        public async Task <IActionResult> LogOff()
        {
            var memberId = HttpContext.Session.GetString("memberId");

            if (memberId != null)
            {
                var smr = _scontext.SecurityMemberRoles.SingleOrDefault(smrr => smrr.MemberId == new Guid(memberId));
                smr.LoggedOutDate = DateTime.Now;
                _scontext.Update(smr);
                await _scontext.SaveChangesAsync();

                HttpContext.Session.Clear();
            }

            _logger.LogInformation(4, "User: "******" logged out.");
            return(RedirectToAction(nameof(HomeController.Index), "Home"));
        }
        public async Task <IActionResult> Suspend(string id, string status)
        {
            var mr = _scontext.SecurityMemberRoles.SingleOrDefault(mrr => mrr.MemberId == new Guid(id));

            if (mr != null)
            {
                mr.x_status   = status;
                mr.EditedDate = DateTime.Now;
                mr.EditedBy   = new Guid(HttpContext.Session.GetString("memberId"));
                _scontext.Update(mr);
                await _scontext.SaveChangesAsync();

                return(Json(new { result = "success" }));
            }
            else
            {
                return(Json(new { result = "fail" }));
            }
        }
        public async Task <IActionResult> ChangeRoleName(string roleId, string rolename)
        {
            var r = await _scontext.SecurityRoles.SingleOrDefaultAsync(rr => rr.RoleId == new Guid(roleId));

            if (r != null)
            {
                r.RoleName   = rolename.Trim();
                r.EditedBy   = new Guid(HttpContext.Session.GetString("memberId"));
                r.EditedDate = DateTime.Now;
                _scontext.Update(r);
                await _scontext.SaveChangesAsync();

                return(Json(new { result = "success", rolename = r.RoleName }));
            }
            else
            {
                return(Json(new { result = "fail" }));
            }
        }
Example #4
0
        public async Task <IActionResult> Login(string uname, string upwd)
        {
            upwd = Utils.EncodeMd5(upwd.Trim());
            var m = await _context.member.SingleOrDefaultAsync(mm => (mm.mem_username == uname.Trim()) && (mm.mem_password == upwd));

            if (m != null)
            {
                var smr = await _scontext.SecurityMemberRoles.SingleOrDefaultAsync(smrr => (smrr.MemberId == m.id) && (smrr.x_status != "N"));

                if (smr != null)
                {
                    HttpContext.Session.SetString("memberId", m.id.ToString());
                    HttpContext.Session.SetString("roleId", m.mem_role_id.ToString());
                    HttpContext.Session.SetString("username", m.mem_username);
                    HttpContext.Session.SetString("displayname", (m.fname + " " + m.lname).Trim());

                    var memberId    = HttpContext.Session.GetString("memberId");
                    var roleId      = HttpContext.Session.GetString("roleId");
                    var displayName = HttpContext.Session.GetString("displayname");

                    var rms = _scontext.SecurityRoleMenus.Where(rmss => rmss.RoleId == m.mem_role_id).OrderByDescending(rmss => rmss.MenuId).ToList();
                    if (rms != null)
                    {
                        string menuHtml = "<ul class='nav navbar-top-links navbar-left'>_menuleft_</ul><ul class='nav navbar-top-links navbar-right'>_menuright_</ul>";
                        string menuLeft = ""; string menuRight = "";
                        string link = ""; string menuTemp = ""; int prevLevel = 0;
                        foreach (SecurityRoleMenus rm in rms)
                        {
                            SecurityMenus menu = await _scontext.SecurityMenus.SingleOrDefaultAsync(me => me.MenuId == rm.MenuId);

                            if (menu != null)
                            {
                                if (menu.HaveChild == 1)
                                {
                                    menuTemp = "<li class='dropdown'><a class='dropdown-toggle' data-toggle='dropdown' href='#'>" + menu.MenuDisplay + "</a><ul class='dropdown-menu'>" + menuTemp + "</ul></li>";
                                    if (menu.Level == 1)
                                    {
                                        if (menu.IsRightAlign != 1)
                                        {
                                            menuLeft = menuTemp + menuLeft;
                                        }
                                        else
                                        {
                                            menuRight = menuTemp + menuRight;
                                        }
                                        menuTemp = "";
                                    }
                                }
                                else
                                {
                                    if (menu.Level != prevLevel)
                                    {
                                        if (menu.IsRightAlign != 1)
                                        {
                                            menuLeft = menuTemp + menuLeft;
                                        }
                                        else
                                        {
                                            menuRight = menuTemp + menuRight;
                                        }
                                        menuTemp = "";
                                    }

                                    if (menu.MenuUrl != null)
                                    {
                                        link = menu.MenuUrl;
                                    }
                                    else
                                    {
                                        link = Url.Action(menu.MenuAction, menu.MenuController);
                                    }
                                    if (menu.MenuName != "-")
                                    {
                                        if (menu.Level != 1)
                                        {
                                            menuTemp = "<li><a href='" + link + "'>" + menu.MenuDisplay.Replace(@"""", @"\""") + "</a></li>" + menuTemp;
                                        }
                                        else
                                        {
                                            menuTemp = "<li><a class='dropdown-toggle' href='" + link + "'>" + menu.MenuDisplay.Replace(@"""", @"\""") + "</a></li>" + menuTemp;
                                        }
                                    }
                                    else
                                    {
                                        menuTemp = "<li class='divider'></li>" + menuTemp;
                                    }
                                    if (menu.Level == 1)
                                    {
                                        if (menu.IsRightAlign != 1)
                                        {
                                            menuLeft = menuTemp + menuLeft;
                                        }
                                        else
                                        {
                                            menuRight = menuTemp + menuRight;
                                        }
                                        menuTemp = "";
                                    }
                                }
                                prevLevel = menu.Level;
                            }
                        }
                        menuRight = menuRight.Replace("_displayname_", "<span id='_displayname_'>" + displayName + "</span>");
                        menuHtml  = menuHtml.Replace("_menuright_", menuRight);
                        menuHtml  = menuHtml.Replace("_menuleft_", menuLeft);
                        HttpContext.Session.SetString("mainmenu", menuHtml);
                    }

                    smr.LoggedInDate = DateTime.Now;
                    _scontext.Update(smr);
                    await _scontext.SaveChangesAsync();

                    var returnUrl = "";
                    //if (roleId != "c5a644a2-97b0-40e5-aa4d-e2afe4cdf428") //Not Administrators role
                    //{
                    //    if (roleId != "17822a90-1029-454a-b4c7-f631c9ca6c7d") //Not Member
                    //    {
                    //        //returnUrl = Url.Action("Index", "members");
                    //        returnUrl = Url.Action("DetailsPersonal", "members");
                    //    }
                    //    else //Is Member
                    //    {
                    //        returnUrl = Url.Action("DetailsPersonal", "members");
                    //    }
                    //}
                    //else //Have Administrators role
                    //{
                    //    returnUrl = Url.Action("ManageMembers", "Security");
                    //}
                    returnUrl = Url.Action("Home", "Security");
                    return(Json(new { result = "success", url = returnUrl }));
                }
                else
                {
                    return(Json(new { result = "fail" }));
                }
            }
            else
            {
                return(Json(new { result = "fail" }));
            }
        }