예제 #1
0
            public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
            {
                context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
                using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, ESPL.AUTHENTICATION.OWINTOKEN.Models.Constants.DomainName))
                {
                    //Validate user credentials with AD
                    if (pc.ValidateCredentials(context.UserName, context.Password))
                    {
                        int authorizedUserID = 0;
                        //Authorize user if site url is provided in Scope of context
                        if (context.Scope != null && !string.IsNullOrEmpty(context.Scope[0]))
                        {
                            //Get User ID of given user from the site if the user is authorized to access site
                            authorizedUserID = AuthorizeUser.GetUserIDFromSPSite(context.UserName, ESPL.AUTHENTICATION.OWINTOKEN.Models.Constants.QualifiedDomainName,
                                                                                 context.Scope[0]);
                            //check authorization id. If user id is zero "0" then the given user is not authorized to access the site
                            if (authorizedUserID == 0)
                            {
                                context.SetError("unauthorized_user", "User is not authorized to access site");
                                return;
                            }
                        }

                        //Get user information from AD
                        UserPrincipal UserInfoFromAD = UserPrincipal.FindByIdentity(pc, context.UserName.ToString());

                        var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                        identity.AddClaim(new Claim("LoginName", Convert.ToString(context.UserName)));
                        if (UserInfoFromAD.GivenName == null)
                        {
                            identity.AddClaim(new Claim("FirstName", ""));
                        }
                        else
                        {
                            identity.AddClaim(new Claim("FirstName", Convert.ToString(UserInfoFromAD.GivenName)));
                        }
                        if (UserInfoFromAD.MiddleName == null)
                        {
                            identity.AddClaim(new Claim("MiddleName", ""));
                        }
                        else
                        {
                            identity.AddClaim(new Claim("MiddleName", Convert.ToString(UserInfoFromAD.MiddleName)));
                        }
                        if (UserInfoFromAD.Surname == null)
                        {
                            identity.AddClaim(new Claim("LastName", ""));
                        }
                        else
                        {
                            identity.AddClaim(new Claim("LastName", Convert.ToString(UserInfoFromAD.Surname)));
                        }
                        if (UserInfoFromAD.EmailAddress == null)
                        {
                            identity.AddClaim(new Claim("EmailAddress", ""));
                        }
                        else
                        {
                            identity.AddClaim(new Claim("EmailAddress", Convert.ToString(UserInfoFromAD.EmailAddress)));
                        }
                        if (UserInfoFromAD.VoiceTelephoneNumber == null)
                        {
                            identity.AddClaim(new Claim("Telephone", ""));
                        }
                        else
                        {
                            identity.AddClaim(new Claim("Telephone", Convert.ToString(UserInfoFromAD.VoiceTelephoneNumber)));
                        }
                        if (UserInfoFromAD.EmployeeId == null)
                        {
                            identity.AddClaim(new Claim("EmployeeID", ""));
                        }
                        else
                        {
                            identity.AddClaim(new Claim("EmployeeID", Convert.ToString(UserInfoFromAD.EmployeeId)));
                        }
                        identity.AddClaim(new Claim("UserName", Convert.ToString(UserInfoFromAD.Name)));
                        if (authorizedUserID == 0)
                        {
                            identity.AddClaim(new Claim("UserID", ""));
                        }
                        else
                        {
                            identity.AddClaim(new Claim("UserID", Convert.ToString(authorizedUserID)));
                        }
                        identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
                        context.Validated(identity);
                    }
                    else
                    {
                        context.SetError("inactive_user", "User is not valid custom message");
                        return;
                    }
                }
            }
예제 #2
0
        public ActionResult GetData(int?page, int?pageSize, string key, int?sort, string usedState)
        {
            try
            {
                var objRef           = new object[5];
                int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
                if (currentPageIndex < 0)
                {
                    currentPageIndex = 0;
                }
                pageSize = pageSize.HasValue ? pageSize : rowInPage;
                string sWhere = (AuthorizeUser.IsHost() || AuthorizeUser.IsAction(Ultity.Constant.ViewEditAll)) ? " 1=1 " : " a.CreatedBy =" + WebSecurity.CurrentUserId;
                if (!string.IsNullOrEmpty(key))
                {
                    key            = key.Trim();
                    ViewBag.Search = key;
                    sWhere        += "and  ( a.Name like N'%" + key + "%' or dbo.ConvertToNoSigned(a.Name) like  dbo.ConvertToNoSigned(N'%" + key + "%')) ";
                }

                if (!string.IsNullOrEmpty(usedState))
                {
                    if (!usedState.Equals(Ultity.Constant.All.ToString()))
                    {
                        ViewBag.UsedState = Ultity.TFunction.GetAllUsedStateSelected(CommonHelper.Convert.ConvertToInt32(usedState));
                        sWhere            = string.IsNullOrEmpty(sWhere) ? " a.UsedState=" + usedState + "" : (sWhere + " AND a.UsedState=" + usedState + " ");
                    }
                }
                string sSort = "a.Orders DESC";
                if (sort.HasValue)
                {
                    switch (sort.Value)
                    {
                    case 0:
                        sSort            = "a.Name ASC";
                        ViewBag.SortName = "1";
                        break;

                    case 1:
                        sSort            = "a.Name DESC";
                        ViewBag.SortName = "2";
                        break;

                    case 2:
                        ViewBag.SortName = "0";
                        sSort            = "a.Orders ASC";
                        break;
                    }
                }
                else
                {
                    ViewBag.SortName = "0";
                }
                objRef[0] = sWhere;
                objRef[1] = sSort;
                objRef[2] = currentPageIndex;
                objRef[3] = pageSize;
                objRef[4] = 0;
                var modelList = _sysAction.List(ref objRef);
                int totalRow  = CommonHelper.Convert.ConvertToInt32(objRef[4]);

                //Check after deleted last item in page . Redirect page close have value smaller
                if (Request.IsAjaxRequest())
                {
                    return(Json(new { status = "success", Message = Ultity.Constant.Ajax_Success, Data = modelList, TotalPage = totalRow, CurrentPage = currentPageIndex, PageSize = pageSize }));
                }
            }
            catch (Exception exception)
            {
                Ultity.TFunction.WriteToLog(exception);
                return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail }));
            }
            return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail }));
        }
예제 #3
0
        private ActionResult ProposalPaymentInternal(string QuoteNo, string AppUserName = null, string CloseWindow = "false")
        {
            PaymentModel objPaymentModel = new PaymentModel();

            objPaymentModel.QuoteNo = CrossCutting.CrossCutting_EncryptDecrypt.Decrypt(QuoteNo);

            #region Check user authorization
            AuthorizeUser authorizeUser = new AuthorizeUser();
            if (!string.IsNullOrEmpty(AppUserName))
            {
                authorizeUser.UserName = objPaymentModel.UserName = AppUserName;
            }
            else
            {
                authorizeUser.UserName = objPaymentModel.UserName = Username;
            }
            authorizeUser.QuoteNo = objPaymentModel.QuoteNo;
            authorizeUser         = new AIA.Life.Business.Common.CommonBusiness().CheckAuthorisation(authorizeUser);
            if (!string.IsNullOrEmpty(authorizeUser.Error.ErrorMessage))
            {
                return(RedirectToAction("AuthorizeError", "Error", new { errorMessage = authorizeUser.Error.ErrorMessage }));
            }
            #endregion

            objPaymentModel.CloseWindow = CloseWindow;
            TempData["CloseWindow"]     = CloseWindow;
            objPaymentModel             = objPaymentBusiness.FetchProposals(objPaymentModel);
            if (objPaymentModel.lstPaymentItems.Count > 0)
            {
                int planID = Convert.ToInt32(objPaymentModel.lstPaymentItems[0].PlanId);
                var obj    = Context.tblMasProductPlans.Where(a => a.PlanId == planID).FirstOrDefault();
                if (objPaymentModel.lstPaymentItems[0].PrefferedMode == "12")
                {
                    switch (obj.PlanCode)
                    {
                    case "SBB":
                    {
                        if (objPaymentModel.lstPaymentItems[0].Premium < 12000)
                        {
                            objPaymentModel.lstPaymentItems[0].Premium = objPaymentModel.lstPaymentItems[0].Premium * 2;
                        }
                        break;
                    }

                    case "SBF":
                    {
                        objPaymentModel.lstPaymentItems[0].Premium = objPaymentModel.lstPaymentItems[0].Premium * 3;
                        break;
                    }

                    case "PPG":
                    {
                        objPaymentModel.lstPaymentItems[0].Premium = objPaymentModel.lstPaymentItems[0].Premium * 3;
                        break;
                    }

                    case "PPH":
                    {
                        if (objPaymentModel.lstPaymentItems[0].Premium < 12000)
                        {
                            objPaymentModel.lstPaymentItems[0].Premium = objPaymentModel.lstPaymentItems[0].Premium * 2;
                        }
                        break;
                    }

                    case "EPB":
                    {
                        if (objPaymentModel.lstPaymentItems[0].Premium < 12000)
                        {
                            objPaymentModel.lstPaymentItems[0].Premium = objPaymentModel.lstPaymentItems[0].Premium * 2;
                        }
                        break;
                    }
                    }
                }
            }
            return(View("~/Views/Payment/ProposalPayment.cshtml", objPaymentModel));
        }
예제 #4
0
        public ActionResult GetData(string fromDate, string toDate, int userId, bool chkKhoaHoc, bool chkDeThi, string ddlClass, string ddlExam)
        {
            DateTime dtFrom, dtTo;
            var      lstResult = new List <ReportClassModel>();

            #region +Validate
            if (string.IsNullOrEmpty(fromDate) || string.IsNullOrEmpty(toDate))
            {
                return(Json(new { status = THelper.Ajax_Return.ErrSystem }));
            }
            try
            {
                dtFrom = DateTime.ParseExact(fromDate, "dd/MM/yyyy HH:mm", null);
                dtTo   = DateTime.ParseExact(toDate, "dd/MM/yyyy HH:mm", null);
            }
            catch (Exception e)
            {
                return(Json(new { status = THelper.Ajax_Return.ErrSystem }));
            }
            #endregion

            #region +Handler
            if (chkKhoaHoc)
            {
                string sWhere = "1=1  and a.CreatedDate>='" + dtFrom.ToString("MM/dd/yyy HH:mm") + "' and a.CreatedDate <='" + dtTo.ToString("MM/dd/yyy HH:mm") + "'";
                sWhere = (userId == 0 && AuthorizeUser.IsHost()) ?  sWhere: (sWhere + "and a.CreatedBy=" + (userId == 0 ? WebSecurity.CurrentUserId : userId) + "");
                sWhere = (ddlClass == "0") ? sWhere : (sWhere + "and a.IdGuid='" + ddlClass + "'");
                string sql = "Select a.*,(select count(*) from Cms_ClassStudent where ClassGuid=a.IdGuid)as TongHS from Cms_Class a ";
                sql += " where " + sWhere;
                var lst = SqlHelper.ExecuteList <Cms_Class>(SqlConnection, CommandType.Text, sql);
                lst.ForEach(x =>
                {
                    lstResult.Add(new ReportClassModel
                    {
                        Time    = Convert.ToDateTime(x.CreatedDate),
                        Loai    = "Khóa học",
                        Ten     = x.Name,
                        SoLuong = x.TongHS
                    });
                });
            }
            if (chkDeThi)
            {
                string sWhere = "1=1 and a.CreatedDate>='" + dtFrom.ToString("MM/dd/yyy HH:mm") + "' and a.CreatedDate <='" + dtTo.ToString("MM/dd/yyy HH:mm") + "'";
                sWhere = (userId == 0 && AuthorizeUser.IsHost()) ? sWhere : (sWhere + "and a.CreatedBy=" + (userId == 0?WebSecurity.CurrentUserId:userId) + "");
                sWhere = (ddlExam == "0") ? sWhere : (sWhere + "and a.IdGuid='" + ddlExam + "'");
                var lst = new SysAdminAction <Ex_Exam>().List(sWhere, "a.CreatedDate desc", 0, 100);
                lst.ForEach(x =>
                {
                    lstResult.Add(new ReportClassModel
                    {
                        Time    = Convert.ToDateTime(x.CreatedDate),
                        Loai    = "Đề thi",
                        Ten     = x.Name,
                        SoLuong = x.TotalStudent
                    });
                });
            }
            #endregion
            return(Json(new { status = THelper.Ajax_Return.Ok, value = lstResult }));
        }
예제 #5
0
        public ActionResult Edit(Ex_Exam sysModel)
        {
            try
            {
                #region Redirect Request

                int succcess = 0;
                if (sysModel.Id > 0)
                {
                    var objTemporary = new SysAdminAction <Ex_Exam>().GetById(sysModel.Id);
                    if (AuthorizeUser.IsAction(Ultity.Constant.Edit) || AuthorizeUser.IsAction(Ultity.Constant.ViewEditAll))
                    {
                        sysModel.IdGuid       = Guid.NewGuid().ToString();
                        sysModel.CreatedBy    = objTemporary.CreatedBy;
                        sysModel.ModifiedDate = DateTime.Now;
                        sysModel.ModifiedBy   = WebSecurity.CurrentUserId;
                        sysModel.CreatedDate  = objTemporary.CreatedDate;
                        //sysModel.Name = objTemporary.Name;
                        if (!AuthorizeUser.IsHost())
                        {
                            sysModel.UsedState = objTemporary.UsedState;
                        }
                        succcess = _sysAction.Update(sysModel);
                    }
                    else
                    {
                        succcess = 1;
                    }
                }
                else
                {
                    if (AuthorizeUser.IsAction(Ultity.Constant.Add) || AuthorizeUser.IsAction(Ultity.Constant.ViewEditAll))
                    {
                        sysModel.IdGuid       = Guid.NewGuid().ToString();
                        sysModel.CreatedBy    = WebSecurity.CurrentUserId;
                        sysModel.ModifiedBy   = null;
                        sysModel.UsedState    = Ultity.Constant.NotAccept;
                        sysModel.CreatedDate  = DateTime.Now;
                        sysModel.ModifiedDate = null;
                        succcess = _sysAction.Insert(sysModel);
                    }
                    else
                    {
                        succcess = 1;
                    }
                }

                if (succcess > 0)
                {
                    return(Json(new { status = "success", Message = Ultity.Constant.Ajax_Success }));
                }
                return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail }));

                #endregion Redirect Request
            }
            catch (Exception exception)
            {
                Ultity.TFunction.WriteToLog(exception);
            }

            return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail }));
        }
예제 #6
0
        public ActionResult Delete(string id)
        {
            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    if (Request.IsAjaxRequest())
                    {
                        string sWhere = " Id IN (" + id.Trim() + ") ";
                        string sSet   = "UsedState = " + Ultity.Constant.Request_Delete;

                        if (!AuthorizeUser.IsHost())
                        {
                            new SysAdminAction <SysMenu>().Updates(sSet, sWhere);
                            return(Json(new { status = "success", Message = Ultity.Constant.Change_Delete_Success }));
                        }
                        else
                        {
                            #region Nhieu Id thi se xu ly tunh Id 1. Neu ton tai trong Bang khac thi chi dc Update Status ,Con neu k co thi xoa luon

                            if (id.Contains(","))
                            {
                                string[] tempId = id.Split(',');
                                foreach (var i in tempId)
                                {
                                    var menuLienQuan = new SysGroupMenuAction().List("a.MenuId=" + i, string.Empty, 0, 1);
                                    if (menuLienQuan.Count > 0)
                                    {
                                        return(Json(new { status = "warning", Message = Ultity.Constant.Delete_Success_Err }));
                                    }
                                    new SysAdminAction <SysMenu>().Deletes(" Id=" + i);
                                }
                            }

                            #endregion Nhieu Id thi se xu ly tunh Id 1. Neu ton tai trong Bang khac thi chi dc Update Status ,Con neu k co thi xoa luon

                            #region Xu ly 1 Id

                            else
                            {
                                var menuLienQuan = new SysGroupMenuAction().List("a.MenuId=" + id, string.Empty, 0, 1);
                                if (menuLienQuan.Count > 0)
                                {
                                    return(Json(new { status = "warning", Message = Ultity.Constant.Delete_Success_Err }));
                                }
                                new SysAdminAction <SysMenu>().Deletes(sWhere);
                            }

                            #endregion Xu ly 1 Id
                            return(Json(new { status = "success", Message = Ultity.Constant.Delete_Success }));
                        }
                        //Trigger auto to delete table related
                    }
                }
                return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail }));
            }
            catch (Exception exception)
            {
                return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail }));
            }
        }