Ejemplo n.º 1
0
 public UserIdentity(UserInfo info)
 {
     this.userName = info.UserName;
     this.fullName = info.FullName;
     this._profile = info;
     this.authenticated = true;
 }
Ejemplo n.º 2
0
        public bool ApproveRequest(int id, Cats.Models.Security.UserInfo userInfo)
        {
            var req = _unitOfWork.RegionalRequestRepository.FindById(id);

            req.Status     = (int)RegionalRequestStatus.Approved;
            req.ApprovedBy = userInfo.UserProfileID;
            _unitOfWork.Save();
            return(true);
        }
Ejemplo n.º 3
0
 // TODO: Remember to refactor code!!!
 public UserIdentity(int userId, UserAccountService service, UserInfo userInfo, string store, string application)
 {
     //Assign the incoming user name to the current one and clear the roles collection
     var user = service.GetUserDetail(userId);
     this.userName = user.UserName;
     this._profile = userInfo;
     this.roles.Clear();
     authenticated = true;
     /* Retrive the list of all authorized Tasks and Operations from NetSqlAzMan database
      * and persist it with the roles arraylist collection
      */
     roles.AddRange(service.GetUserPermissions(userInfo.UserName, "CATS", application));
 }
Ejemplo n.º 4
0
        public ActionResult Edit(UserPreferenceEditModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _userAccountService.GetUserDetail(HttpContext.User.Identity.Name);
                var users = UserAccountHelper.GetUser(HttpContext.User.Identity.Name);
                user.DefaultTheme = model.ThemePreference;
                user.DatePreference = model.DateFormatPreference;
                user.Keyboard = model.KeyboardLanguage;
                user.LanguageCode = model.Languages;
                user.PreferedWeightMeasurment = model.WeightPrefernce;

                // Edit user preference
                _userAccountService.UpdateUser(user);
                TempData["PreferenceUpdateSuccessMsg"] = "Success: General preference updated";

                var userInfo = new UserInfo
                                   {
                                       UserName = user.UserName,
                                       FirstName = user.FirstName,
                                       LastName = user.LastName,
                                       ActiveInd = user.ActiveInd,
                                       CaseTeam = user.CaseTeam,
                                       DatePreference = user.DatePreference,
                                       DefaultTheme = user.DefaultTheme,
                                       Email = user.Email,
                                       FailedAttempts = user.FailedAttempts,
                                       GrandFatherName = user.GrandFatherName,
                                       Keyboard = user.Keyboard,
                                       LanguageCode = user.LanguageCode,
                                       LockedInInd = user.LockedInInd,
                                       LogOutDate = user.LogOutDate,
                                       LogginDate = user.LogginDate,
                                       NumberOfLogins = user.NumberOfLogins,
                                       PreferedWeightMeasurment = user.PreferedWeightMeasurment.Trim()
                                   };
                Session["USER_INFO"] = userInfo;

            }
            else
            {
                TempData["PreferenceUpdateErrorMsg"] = "Error: General preference not updated";
            }
            return RedirectToAction("Preference", "Home");
        }
Ejemplo n.º 5
0
        public string ResetPassword(string userName)
        {
            var info = new UserInfo();

            // Generate a random password
            var random = new Random();
            var randomPassword = GenerateString(random, 8);

            // Reset the current user's password attribute to the new one
            var user = _unitOfWork.UserProfileRepository.FindBy(u => u.UserName == userName).SingleOrDefault();
            if (user != null)
            {
                info = _unitOfWork.UserInfoRepository.FindBy(u => u.UserProfileID == user.UserProfileID).SingleOrDefault();
                user.Password = HashPassword(randomPassword);
                try
                {
                    _unitOfWork.Save();

                    // TODO: Consider sending the new password through email for the user!
                    // SendPasswordToMail(userName, user.Email);

                }
                catch (Exception e)
                {
                    //throw new ApplicationException(string.Format("Unable to reset password for {0}. \n Error detail: \n {1} ", info.FullName, e.Message), e);
                    throw new unabletoResetPasswordException(info.UserName);
                }
            }
            return randomPassword;
        }
Ejemplo n.º 6
0
 public string ResetPassword(UserInfo userInfo)
 {
     return ResetPassword(userInfo.UserName);
 }
Ejemplo n.º 7
0
 public bool Authenticate(UserInfo info)
 {
     return Authenticate(info.UserName, info.Password);
 }
Ejemplo n.º 8
0
        public void Init()
        {
            var transportOrderService = new Mock<ITransportOrderService>();
            var workflowStatusService = new Mock<IWorkflowStatusService>();
            var dispatchAllocationService = new Mock<IDispatchAllocationService>();
            var distributionService = new Mock<IDeliveryService>();
            var dispatchService = new Mock<IDispatchService>();
            var deliveryDetailService = new Mock<IDeliveryDetailService>();
            var notificationService = new Mock<INotificationService>();
            var userAccountService = new Mock<IUserAccountService>();
            var commodityService = new Mock<Cats.Services.EarlyWarning.ICommodityService>();
            var unitService = new Mock<Cats.Services.EarlyWarning.IUnitService>();
            var transactionService = new Mock<Cats.Services.Transaction.ITransactionService>();
            var transaction = new List<Cats.Models.Transaction>()
                                      {
                                          new Cats.Models.Transaction()
                                              {

                                              }
                                      };
            transactionService.Setup(t => t.GetAllTransaction()).Returns(transaction);
            var commodities = new List<Cats.Models.Commodity>()
                                      {
                                          new Cats.Models.Commodity()
                                              {
                                                  CommodityID = 1,
                                                  CommodityTypeID = 1,
                                                  Name = "commodity1",
                                              }
                                      };
            commodityService.Setup(t => t.GetAllCommodity()).Returns(commodities);
            var units = new List<Cats.Models.Unit>()
                                      {
                                          new Cats.Models.Unit()
                                              {
                                                  UnitID = 1,
                                                  Name = "unit1"
                                              }
                                      };
            unitService.Setup(t => t.GetAllUnit()).Returns(units);
            var transportOrders = new List<TransportOrder>()
                                      {
                                          new TransportOrder()
                                              {
                                                  TransporterID = 1,
                                                  BidDocumentNo = "11",
                                                  TransportOrderID = 1,
                                                  TransportOrderNo = "TRO-1",
                                                  StatusID=1,
                                                  Transporter = new Cats.Models.Transporter() {Name = "T2", TransporterID = 1}
                                              }
                                      };
            var workflowstatuses = new List<WorkflowStatus>()
                                       {
                                           new WorkflowStatus()
                                               {
                                                   StatusID = 1,
                                                   Description = "Draft",
                                                   WorkflowID = 1
                                               }
                                       };
            var dispatches = new List<DispatchViewModel>()
                                 {
                                     new DispatchViewModel()
                                         {
                                             RequisitionNo = "REQ-001",
                                             BidNumber = "001",
                                             TransporterID = 1,
                                             ProgramID = 1,
                                             Month = 1,
                                             Round = 1,
                                             QuantityPerUnit = 1,
                                             UnitID = 1,
                                             QuantityInUnit = 1,
                                             Quantity = 1,
                                             ProjectNumber = "001",
                                             ProjectCodeID = 1,
                                             ShippingInstructionID = 1,
                                             SINumber = "001",
                                             UserProfileID = 1,
                                             PlateNo_Prime = "001",
                                             PlateNo_Trailer = "002",
                                             GRNReceived = false,
                                             Transporter = "T2",
                                             Year = 2013,
                                             FDPID = 1,
                                             CommodityID = 1,
                                             FDP = "1",
                                             HubID = 1,
                                             DispatchID = Guid.NewGuid(),
                                             DeliveryID = Guid.NewGuid(),
                                             DispatchDate = DateTime.Today,
                                             CreatedDate = DateTime.Today,
                                             DispatchAllocationID = Guid.NewGuid(),

                                         }
                                 };
            var distributions = new List<Delivery>()
                                    {
                                        new Delivery()
                                            {
                                                DeliveryDate = DateTime.Today,
                                                DeliveryBy ="Ban",
                                                DonorID = 1,
                                                FDPID=1,
                                                HubID=1,
                                                InvoiceNo="002",
                                                TransporterID=1,
                                                ReceivedDate = DateTime.Today,
                                                ReceivingNumber="002",
                                                DispatchID=Guid.NewGuid(),
                                                DeliveryID = Guid.NewGuid(),
                                                DocumentReceivedDate = DateTime.Today

                                            }
                                    };
            var user = new UserInfo() { UserProfileID = 1, DatePreference = "GC" };
            transportOrderService.Setup(
                t =>
                t.Get(It.IsAny<Expression<Func<TransportOrder, bool>>>(),
                      It.IsAny<Func<IQueryable<TransportOrder>, IOrderedQueryable<TransportOrder>>>(),
                      It.IsAny<string>())).Returns(transportOrders);
            workflowStatusService.Setup(t => t.GetStatus(It.IsAny<WORKFLOW>())).Returns(workflowstatuses);
            dispatchAllocationService.Setup(t => t.GetTransportOrderDispatches(It.IsAny<int>())).Returns(dispatches);
            distributionService.Setup(t => t.FindBy(It.IsAny<Expression<Func<Delivery, bool>>>())).Returns(
                distributions);
            userAccountService.Setup(t => t.GetUserInfo(It.IsAny<string>())).Returns(user);

            var fakeContext = new Mock<HttpContextBase>();
            var identity = new GenericIdentity("User");
            var principal = new GenericPrincipal(identity, null);
            fakeContext.Setup(t => t.User).Returns(principal);

            var controllerContext = new Mock<ControllerContext>();
            controllerContext.Setup(t => t.HttpContext).Returns(fakeContext.Object);

            var actionTypesService = new Mock<IActionTypesService>();
            actionTypesService.Setup(m => m.GetAllActionType()).Returns(new List<ActionTypes>
                {
                    new ActionTypes() {ActionId = 1, Name = "ActionName", Description = "ActionDescription"}
                });

            var businessProcessService = new Mock<IBusinessProcessService>();
            var applicationSettingService = new Mock<IApplicationSettingService>();
            var transporterPaymentRequest = new Mock<ITransporterPaymentRequestService>();
            _distributionController =
               new DeliveryController(
                   transportOrderService.Object,
                   workflowStatusService.Object,
                   dispatchAllocationService.Object,
                   distributionService.Object,
                   dispatchService.Object,
                   deliveryDetailService.Object,
                   notificationService.Object, actionTypesService.Object,
                   userAccountService.Object, commodityService.Object, unitService.Object, transactionService.Object,
                   businessProcessService.Object,applicationSettingService.Object,transporterPaymentRequest.Object
               );
            _distributionController.ControllerContext = controllerContext.Object;
        }
Ejemplo n.º 9
0
        private static UserInfo GetUserInfo(string userName)
        {
            // Initialize the user object with the incoming user name to avoid 'Use of uninitialized variable exception'
            UserInfo user = new UserInfo { UserName = userName };
            try
            {
                // Check to see if we already have the user profile loaded in the session.
                if (null != HttpContext.Current.Session["USER_INFO"])
                {
                    user = (UserInfo)HttpContext.Current.Session["USER_INFO"];
                }
                else
                {
                    // Fetch a copy from the database if we don't have a session variable already loaded in memory
                    var service = (IUserAccountService)DependencyResolver.Current.GetService(typeof(IUserAccountService));
                    user = service.GetUserInfo(userName);
                }
            }
            catch (Exception ex)
            {
                //TODO: Log error here
                Logger.Log(ex);
            }

            return user;
        }
Ejemplo n.º 10
0
 public bool RejectRequest(int id, UserInfo userInfo)
 {
     var req = _unitOfWork.RegionalRequestRepository.FindById(id);
     req.Status = (int)RegionalRequestStatus.Reject;
     req.ApprovedBy = userInfo.UserProfileID;
     _unitOfWork.Save();
     return true;
 }