コード例 #1
0
        private LoginResult GetLoginLevel(string userName, string pwd, CLToolContext context, out User user)
        {
            user = null;
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(pwd))
            {
                return(LoginResult.Error);
            }
            if (!ValidateCredentials(userName, pwd))
            {
                return(LoginResult.Error);
            }
            user = context.User.Include(u => u.UserAbility).FirstOrDefault(u => u.Username == userName);
            if (user == null)
            {
                return(LoginResult.NoPermission); //no permission
            }
            if (!user.Active)
            {
                return(LoginResult.NotActive);
            }

            var accountType = user.Type;

            if (!Enum.IsDefined(typeof(LoginResult), accountType))
            {
                return(LoginResult.Error);
            }
            return((LoginResult)Enum.Parse(typeof(LoginResult), accountType));
        }
コード例 #2
0
 //private IMemoryCache _cache;
 public RequestListingController(CLToolContext context, IConfiguration config, ICustomerAdapter indusAdapter)
 {
     _context = context;
     _config  = config;
     _indus   = indusAdapter;
     //_cache = memoryCache;
 }
コード例 #3
0
 //Sometimes when server is restarted and all session is clear
 //But user cookie is still authenticated, GetDevision will fail
 //This scenerio is not likely to happen in PROD but causes annoyances in DEV
 //So call this in DEV instead
 public static string ForceGetDevision(HttpContext httpContext, CLToolContext context)
 {
     if (!httpContext.Session.TryGetValue(UserDivisionKey, out var arr))
     {
         SetDivison(httpContext, context);
         return(ForceGetDevision(httpContext, context)); //try again
     }
     return(arr.ConvertToString());
 }
コード例 #4
0
        public static void SetDivison(HttpContext httpContext, CLToolContext context)
        {
            var claim = httpContext.User.FindFirst(ClaimTypes.Name);

            if (claim == null)
            {
                throw new InvalidOperationException("Cant find user's claim despite authenticated context");
            }
            var user = context.User.FirstOrDefault(u => u.Username == claim.Value);

            if (user == null)
            {
                throw new InvalidOperationException("No user found in database despite authenticated context");
            }
            SetDivison(httpContext, user);
        }
コード例 #5
0
        public static async Task <AdmViewModel> CreateAdmViewModel(CLToolContext context, int pageNum)
        {
            int getPage      = pageNum < 1 ? 1 : pageNum;
            int excludedRows = (getPage - 1) * RequestListingViewModel.ItemPerPage;
            var query        = context.User.Include(u => u.UserAbility);
            var model        = new AdmViewModel
            {
                Users = await query.OrderBy(u => u.Username)
                        .Skip(excludedRows)
                        .Take(RequestListingViewModel.ItemPerPage).ToListAsync(),
                OnPage    = pageNum,
                Divisions = await context.Division.Select(a => a.DivisionName).ToListAsync()
            };

            model.UpdatePagination(await context.User.CountAsync());
            return(model);
        }
コード例 #6
0
 public AccountController(CLToolContext context, IConfiguration config)
 {
     _context = context;
     _config  = config;
 }
コード例 #7
0
ファイル: RequestQuery.cs プロジェクト: donkeizluv/CLTool
 public static IQueryable <Request> RequestsByDivision(CLToolContext context, string division)
 {
     return(context.Request.Where(r => r.UsernameNavigation.DivisionName == division));
 }
コード例 #8
0
ファイル: RequestQuery.cs プロジェクト: donkeizluv/CLTool
 public static IQueryable <Request> AllRequests(CLToolContext context)
 {
     return(context.Request);
 }
コード例 #9
0
ファイル: RequestQuery.cs プロジェクト: donkeizluv/CLTool
 public static IQueryable <Request> RequestsByUser(CLToolContext context, string userName)
 {
     return(context.Request.Where(r => r.Username == userName));
 }
コード例 #10
0
        //Unhandle exception wont crash app
        //No point using async here...
        public void Execute(IJobExecutionContext context)
        {
            //logger.Info("Execute job....");
            try
            {
                var schedulerContext = context.Scheduler.Context;
                var conStr           = (string)schedulerContext.Get(EnviromentHelper.ConnectionStringKey);
                if (string.IsNullOrEmpty(conStr))
                {
                    throw new ArgumentException("Invalid connection string");
                }
                var url = (string)schedulerContext.Get(EnviromentHelper.ApiUrlKey);
                if (string.IsNullOrEmpty(url))
                {
                    throw new ArgumentException("Invalid API URL");
                }
                using (var dbContext = new CLToolContext(conStr))
                {
                    var newRequests = dbContext.Request
                                      .Where(w => w.Response.Count == 0);

                    //Debug.Print(newRequests.Count().ToString());
                    if (newRequests.Count() == 0)
                    {
                        //logger.Info("Nothing new...back to sleep Zzzz");
                        return;
                    }
                    logger.Info("New requests count: " + newRequests.Count().ToString());
                    newRequests = newRequests.Include(customer => customer.CustomerInfo)
                                  .Include(username => username.UsernameNavigation)
                                  .ThenInclude(division => division.DivisionNameNavigation);
                    //ToList to close read connection
                    foreach (var request in newRequests.ToList())
                    {
                        //Update rq send time
                        request.RequestSendTime = DateTime.Now;
                        ////Must have customer info at this point
                        var hdssRq = RequestWrapper.ToHDSSRequest(request, request.CustomerInfo.Single());
                        //Log raw rq
                        logger.Info("Request:");
                        logger.Info(JsonConvert.SerializeObject(hdssRq));
                        //var test = JsonConvert.SerializeObject(hdssRq);
                        //If network fail, rq wont get update with response & guid
                        var  result     = HDB.Program.PostToHDBank(url, hdssRq);
                        var  response   = RequestWrapper.DeserializeResponse(result);
                        bool skipVerify = false;
                        //00: success
                        //01: có tài khoản cũ rồi nhưng tên sai so với tên đã lưu tại hdb
                        //09: trả về tài khoản cũ
                        //03: tạo tài khoản thất bại, tham số input truyền qua không hợp lệ
                        //05: invalid sig
                        switch (response.ResponseCode)
                        {
                        case "00":
                            //Continue to check sig & save response
                            break;

                        case "09":
                            //Continue to check sig & save response
                            break;

                        case "01":
                            //Doesnt have sig in response => skip verify & store response to check later
                            skipVerify = true;
                            break;

                        case "03":
                            throw new InvalidOperationException($"Server response 03. Invalid format: {response.ResponseMessage}");

                        case "05":
                            throw new InvalidOperationException("Invalid signature 05. Check keys then restart app");

                        default:
                            throw new InvalidOperationException($"Unknown response code {response.ResponseCode}");
                        }

                        if (!skipVerify)
                        {
                            if (!HdbRSA.Verify(response.VerificationHash, response.Signature))
                            {
                                throw new UnauthorizedAccessException($"Verification failed for request: {request.RequestId}");
                            }
                            logger.Info("Verify OK!");
                        }
                        //Log raw response
                        logger.Info("Response:");
                        logger.Info(result);
                        //Update GUID, sig
                        request.Guid      = hdssRq.requestId;
                        request.Signature = hdssRq.signature;
                        //Add response to this request
                        request.Response.Add(response);
                        //try save each sucessful API calls
                        //MultipleActiveResultSets=true;
                        //To allow multiple operations in single connection
                        dbContext.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                EnviromentHelper.LogException(ex, logger);
                logger.Fatal("************** Unhandle exception in Scheduler => Stop scheduler **************");
                var jobEx = new JobExecutionException(ex);
                //Stop all trigger
                jobEx.UnscheduleAllTriggers      = true;
                EnviromentHelper.IsSchedulerDown = true;
                //Apply effect
                throw jobEx;
            }
        }
コード例 #11
0
ファイル: ReportController.cs プロジェクト: donkeizluv/CLTool
 public ReportController(CLToolContext context, IConfiguration config)
 {
     _context = context;
     _config  = config;
 }
コード例 #12
0
 public HomeController(CLToolContext context, IConfiguration config, IMemoryCache memoryCache)
 {
     _context = context;
     _config  = config;
     _cache   = memoryCache;
 }