Example #1
0
        public ActionResult CambiarMiPassword([Bind(Include = "userd_id,old_pass,new_pass")] CambiarPasswordViewModel pCambiarPasswordViewModel, string returnUrl)
        {
            int    tipo_error           = 0;
            UserBL oUserBL              = new UserBL();
            CurrentUserViewModel result = oUserBL.ValidarUsuario(AuthorizeUserAttribute.UsuarioLogeado().user_email, Helper.Encripta(pCambiarPasswordViewModel.old_pass), ref tipo_error);

            if (tipo_error == -3)
            {
                return(Json(new
                {
                    message_error = "La contraseƱa anterior no es correcta.",
                    status = "0",
                }));
            }
            else
            {
                pCambiarPasswordViewModel.new_pass = Helper.Encripta(pCambiarPasswordViewModel.new_pass);
                pCambiarPasswordViewModel.userd_id = AuthorizeUserAttribute.UsuarioLogeado().user_id;
                oUserBL.CambiarPassword(pCambiarPasswordViewModel);
                return(Json(new
                {
                    // this is what datatables wants sending back
                    status = "1",
                }));
            }
        }
Example #2
0
        public async void LogIn_ExistentUser_ReturnUser()
        {
            // Arrange
            var requestModel = new LoginViewModel
            {
                Email    = "testEmail",
                Password = "******"
            };

            var responseModel = new CurrentUserViewModel
            {
                Email    = "testEmail",
                FullName = "TestFullName",
                Password = "******"
            };

            _moqArrange.UserRepositoryMock.Setup(e => e.Find(It.IsAny <Func <User, bool> >())).Returns(() =>
                                                                                                       new List <User> {
                new User {
                    Email = requestModel.Email, Password = requestModel.Password, FullName = "TestFullName"
                }
            });

            // Act
            var result = await _service.Login(requestModel,
                                              new DefaultHttpContext { RequestServices = _moqArrange.ServiceProviderMock.Object });

            // Assert
            Assert.NotNull(result);
            Assert.Equal(responseModel.Email, result.Email);
            Assert.Equal(responseModel.Password, result.Password);
            Assert.Equal(responseModel.FullName, result.FullName);
        }
Example #3
0
        /// <summary>
        /// Get current user
        /// </summary>
        /// <remarks>Get the currently logged in user</remarks>
        /// <response code="200">OK</response>
        public virtual IActionResult UsersCurrentGetAsync()
        {
            // get the current user id
            int?id = GetCurrentUserId();

            if (id != null)
            {
                User currentUser = _context.Users
                                   .Include(x => x.District)
                                   .Include(x => x.GroupMemberships)
                                   .ThenInclude(y => y.Group)
                                   .Include(x => x.UserRoles)
                                   .ThenInclude(y => y.Role)
                                   .ThenInclude(z => z.RolePermissions)
                                   .ThenInclude(z => z.Permission)
                                   .First(x => x.Id == id);

                CurrentUserViewModel result = currentUser.ToCurrentUserViewModel();

                // get the name for the current logged in user
                result.GivenName = User.FindFirst(ClaimTypes.GivenName).Value;
                result.Surname   = User.FindFirst(ClaimTypes.Surname).Value;

                return(new ObjectResult(new HetsResponse(result)));
            }

            // no record found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
        public CurrentUserViewModel GetClient(string currentUserId)
        {
            ApplicationUser      user      = this.Context.Users.Find(currentUserId);
            CurrentUserViewModel userModel = Mapper.Map <ApplicationUser, CurrentUserViewModel>(user);

            return(userModel);
        }
Example #5
0
        public static int ObtenerNroNoNotificados()
        {
            CurrentUserViewModel user            = (CurrentUserViewModel)HttpContext.Current.Session[ConfigurationManager.AppSettings["session.usuario.actual"]];
            NotificationBL       oNotificationBL = new NotificationBL();

            return(oNotificationBL.ObtenerNroNoNotificados(user.user_id));
        }
Example #6
0
        public MainMenuViewModel(Model.User currentUser, string controllerName)
            : base()
        {
            CurrentUser = new CurrentUserViewModel(currentUser);

            this.Controller = controllerName;
        }
Example #7
0
 /// <summary>
 /// Create new instance
 /// </summary>
 /// <param name="currentUser">Current user</param>
 /// <param name="userId">Id of the user rights belong to</param>
 /// <param name="rights">List of UserObjectRights to show</param>
 public UserObjectRightIndexViewModel(Model.User currentUser, int userId, IEnumerable <Model.UserObjectRight> rights)
 {
     CurrentUser = new CurrentUserViewModel(currentUser);
     UserId      = userId;
     Rights      = new List <UserObjectRightIndexViewItem>(
         from r in rights select new UserObjectRightIndexViewItem(r)
         );
 }
Example #8
0
        /// <summary>
        /// Construct the viewmodel
        /// </summary>
        /// <param name="currentUser">Current user</param>
        /// <param name="licenseList">List of License entities</param>
        public LicenseIndexViewModel(Model.User currentUser, IEnumerable <Model.License> licenseList)
        {
            CurrentUser = new CurrentUserViewModel(currentUser);

            Licenses = new List <LicenseIndexViewItem>(
                licenseList.Select(x => new LicenseIndexViewItem(x, x.OwningCustomer, x.Sku, x.Domains))
                );
        }
Example #9
0
        /// <summary>
        /// Construct the viewmodel
        /// </summary>
        /// <param name="currentUser">Current user</param>
        /// <param name="customerList">List of Customer entities</param>
        public CustomerIndexViewModel(Model.User currentUser, IEnumerable <Model.Customer> customerList)
            : base()
        {
            CurrentUser = new CurrentUserViewModel(currentUser);

            Customers = new List <CustomerIndexViewItem>(
                customerList.Select(x => new CustomerIndexViewItem(x, x.Country))
                );
        }
Example #10
0
 public FiltersViewModel(IMergingService mergingService,
                         ProjectMembersSetsViewModel projectMembersSetsViewModel,
                         CurrentUserViewModel currentUserViewModel)
 {
     _projectMembersSetsViewModel         = projectMembersSetsViewModel;
     _areFiltersEnabled                   = mergingService.IsMergingCompleted;
     mergingService.MergingCompleted     += OnProjectPathChanged;
     currentUserViewModel.CurrentUserSet += CurrentUserViewModelOnCurrentUserSet;
     _currentUser = currentUserViewModel.CurrentUser;
 }
 protected override void Initialize(RequestContext requestContext)
 {
     base.Initialize(requestContext);
     CurrentUser                      = UserHelper.GetCurrentUser(HttpContext.User.Identity.Name);
     ViewBag.BrowserVersion           = Request.Browser.Version;
     ViewBag.BrowserPlatform          = Request.Browser.Platform;
     ViewBag.BrowserEcmaScriptVersion = Request.Browser.EcmaScriptVersion;
     ViewBag.Browser                  = Request.Browser.Browser;
     ViewBag.OldBrowser               = Request.Browser.MajorVersion <= 9 && (Request.Browser.Browser.Equals("InternetExplorer") || Request.Browser.Browser.Equals("IE"));
 }
Example #12
0
        /// <summary>
        /// Construct the viewmodel
        /// </summary>
        /// <param name="vendorList">List of vendor entities</param>
        public VendorIndexViewModel(Model.User currentUser, List <Model.Vendor> vendorList)
            : this()
        {
            CurrentUser = new CurrentUserViewModel(currentUser);

            Vendors = new List <VendorIndexViewItem>();
            foreach (Model.Vendor entity in vendorList)
            {
                Vendors.Add(new VendorIndexViewItem(entity, entity.Country));
            }
        }
Example #13
0
        public IViewComponentResult Invoke()
        {
            var studentViewModel = new CurrentUserViewModel()
            {
                LoggedInUser = _studentRepository.LoggedInUser,
                UserPoints   = _studentRepository.UserPoints,
                UserRank     = _studentRepository.UserRank,
                UserRole     = _studentRepository.UserRole
            };

            return(View(studentViewModel));
        }
        public virtual ActionResult AdministrationPanel()
        {
            var user = RavenSession.GetCurrentUser();

            var vm = new CurrentUserViewModel();

            if (user != null)
            {
                vm.FullName = user.FullName;
            }
            return(View(vm));
        }
Example #15
0
        public IActionResult _Header()
        {
            var user  = HttpContext.Session.GetString("UserId");
            var name  = _Services.GetUserNameById(int.Parse(user));
            var model = new CurrentUserViewModel
            {
                Name          = name,
                UserAccess    = _Services.UserAccess(int.Parse(user)),
                Notifications = _Services.Notifications(int.Parse(user)),
            };

            return(PartialView("_Header", model));
        }
Example #16
0
        public ActionResult PorachkaClient()
        {
            string currentUserId = User.Identity.GetUserId();
            //if (!User.Identity.IsAuthenticated)
            //{
            //    return RedirectToAction("Login", "Account");
            //}
            //else
            //{
            CurrentUserViewModel currentUser = this.service.GetClient(currentUserId);

            return(PartialView("_Client", currentUser));
            // }
        }
Example #17
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var cus = context.HttpContext.RequestServices.GetRequiredService <ICurrentUserService>();

            CurrentUserViewModel u = await cus.GetCurrentUserAsync(CancellationToken.None);

            if (u == null)
            {
                context.Result = new UnauthorizedResult();
            }
            else
            {
                await base.OnActionExecutionAsync(context, next);
            }
        }
Example #18
0
        public CurrentUserViewModel ValidarUsuario(string usuario, string contrasena, ref int tipo_error)
        {
            CurrentUserViewModel result = null;

            var cont = Set.Where(a => a.user_email == usuario).Count();

            if (cont > 0)
            {
                result = Set.Where(a => a.user_email == usuario).Select(a =>
                                                                        new CurrentUserViewModel
                {
                    user_id         = a.id,
                    name            = a.contact_name, // contact_name
                    pass            = a.user_pass,
                    user_email      = a.user_email,
                    status_id       = a.user_status_id,
                    investigator_id = a.investigators.Select(i => i.investigator_id).Take(1).FirstOrDefault(),
                    permissions     = a.roles.role_permissions.Select(p => p.permissions.id_permission).ToList(),
                    avatar          = a.avatar,
                    role_id         = a.user_role_id,
                    first_time      = a.user_date_last_login.HasValue?0:1,
                    manual_url      = a.roles.manual_file,
                }
                                                                        ).Take(1).FirstOrDefault();

                if (result.pass != contrasena)
                {
                    tipo_error = -3;
                }
                else
                {
                    if (result.status_id != 1)
                    {
                        tipo_error = -2;
                    }
                    else
                    {
                        tipo_error = 0;
                    }
                }
            }
            else
            {
                tipo_error = -1;
            }

            return(result);
        }
Example #19
0
        public async Task <CurrentUserViewModel> GetById(string id)
        {
            var user = await _userManager.FindByIdAsync(id);

            var role = await _userManager.GetRolesAsync(user);

            CurrentUserViewModel userVm = new CurrentUserViewModel
            {
                Id       = Guid.Parse(id),
                Name     = user.Name,
                UserName = user.UserName,
                Role     = role[0]
            };

            return(userVm);
        }
Example #20
0
        public static bool VerificarPerfil(params Permission[] permissions)
        {
            foreach (var permission in permissions)
            {
                if (HttpContext.Current.Session[ConfigurationManager.AppSettings["session.usuario.actual"]] != null)
                {
                    CurrentUserViewModel usuario = (CurrentUserViewModel)HttpContext.Current.Session[ConfigurationManager.AppSettings["session.usuario.actual"]];

                    if (usuario.permissions.Contains((int)permission))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #21
0
        //[AuthorizeUser(Permissions = new AuthorizeUserAttribute.Permission[] { AuthorizeUserAttribute.Permission.list_programs })]
        public JsonResult ObtenerLista(DataTableAjaxPostModel ofilters)//DataTableAjaxPostModel model
        {
            NotificationBL oNotificationBL = new NotificationBL();
            //ProgramFiltersViewModel ofilters = new ProgramFiltersViewModel();
            CurrentUserViewModel user = (CurrentUserViewModel)Session[ConfigurationManager.AppSettings["session.usuario.actual"]];
            GridModel <NotificationViewModel> grid = oNotificationBL.ObtenerLista(ofilters, user.user_id);

            return(Json(new
            {
                // this is what datatables wants sending back
                draw = ofilters.draw,
                recordsTotal = grid.total,
                recordsFiltered = grid.recordsFiltered,
                data = grid.rows
            }));
        }
Example #22
0
        /// <summary>
        /// Convert User to CurrentUserViewModel
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static CurrentUserViewModel ToCurrentUserViewModel(this User model)
        {
            var dto = new CurrentUserViewModel();

            if (model != null)
            {
                dto.Email            = model.Email;
                dto.GivenName        = model.GivenName;
                dto.Surname          = model.Surname;
                dto.Id               = model.Id;
                dto.District         = model.District;
                dto.GroupMemberships = model.GroupMemberships;
                dto.UserRoles        = model.UserRoles;
            }
            return(dto);
        }
        /// <summary>
        ///
        /// </summary>
        /// <remarks>Get the currently logged in user</remarks>
        /// <response code="200">OK</response>

        public virtual IActionResult UsersCurrentGetAsync()
        {
            var result = new CurrentUserViewModel();

            // get the name for the current logged in user
            result.GivenName               = "Test";
            result.Surname                 = "User";
            result.FullName                = result.GivenName + " " + result.Surname;
            result.OverdueInspections      = 1;
            result.DueNextMonthInspections = 2;
            result.DistrictName            = "Victoria";
            result.ScheduledInspections    = 3;

            // get the number of inspections available for the current logged in user

            return(new ObjectResult(result));
        }
Example #24
0
        public IActionResult _SideBar()
        {
            var user  = HttpContext.Session.GetString("UserId");
            var name  = _Services.GetAccountById(int.Parse(user)).FirstName;
            var model = new CurrentUserViewModel
            {
                Name       = name,
                UserAccess = _Services.UserAccess(int.Parse(user)),
            };
            var id = int.Parse(HttpContext.Session.GetString("UserId"));

            model.IsAdmin    = _Services._IsAdmin(id);
            model.IsRater    = _Services._IsRater(id);
            model.IsApprover = _Services._IsApprover(id);
            model.IsEmployee = _Services._IsEmployee(id);
            return(PartialView("_SideBar", model));
        }
Example #25
0
        public ActionResult TopNavigation()
        {
            var currentUser = new CurrentUserViewModel
            {
                ID          = CurrentUser.Id,
                FullName    = CurrentUser.FullName,
                AccountName = CurrentUser.AccountName
            };

            var currentDBDeptID = Guid.Empty;
            var authenticatedUserDepartmentCookie = Request.Cookies["AuthenticatedUserDepartment"];

            if (authenticatedUserDepartmentCookie != null)
            {
                currentDBDeptID = new Guid(authenticatedUserDepartmentCookie.Value);
            }


            var authenticatedUserDepartments = _userDepartmentServices
                                               .GetCachedUserDepartmentsByUser(currentUser.ID);

            ViewBag.AuthenticatedUserDepartments = authenticatedUserDepartments;
            if (currentDBDeptID != Guid.Empty)
            {
                ViewBag.AuthenticatedUserDepartment =
                    authenticatedUserDepartments.FirstOrDefault(x => x.DeptID == currentDBDeptID);
                if (ViewBag.AuthenticatedUserDepartment == null)
                {
                    ViewBag.AuthenticatedUserDepartment = authenticatedUserDepartments.FirstOrDefault();
                }
            }
            else
            {
                if (authenticatedUserDepartments != null)
                {
                    ViewBag.AuthenticatedUserDepartment = authenticatedUserDepartments.FirstOrDefault();
                }
                else
                {
                    ViewBag.AuthenticatedUserDepartment = null;
                }
            }


            return(PartialView(currentUser));
        }
Example #26
0
        public IHttpActionResult GetCurrentUser()
        {
            try
            {
                var userPrincipal = new ClaimsPrincipal(User);

                var accountName = userPrincipal.Claims.FirstOrDefault(f => f.Type == ClaimTypes.Name).Value;
                accountName = accountName.ToLower().Replace("willmottdixon\\", string.Empty);

                var user = _user.GetUserByAdAccount(accountName);
                if (user == null) //User does not Admin have permissions
                {
                    user = _user.GetAdDetailsByAccountName(accountName);
                    var userViewModel = new CurrentUserViewModel
                    {
                        EmailAddress = user.Email,
                        Forename     = user.Forename,
                        Surname      = user.Surname,
                        DisplayName  = user.DisplayName,
                        IsAdmin      = false,
                        Username     = user.UserName
                    };

                    return(Ok(userViewModel));
                }

                var userRoles      = _user.GetUserRoles(user.Id).ToList();
                var adminViewModel = new CurrentUserViewModel
                {
                    Id           = user.Id,
                    EmailAddress = user.Email,
                    Forename     = user.Forename,
                    Surname      = user.Surname,
                    DisplayName  = (_user.GetAdDetailsByAccountName(accountName) ?? new ApplicationUser()).DisplayName,
                    IsAdmin      = userRoles.Any(a => a.Equals(Roles.Administrator, StringComparison.CurrentCultureIgnoreCase)),
                    Roles        = userRoles,
                    Username     = user.UserName
                };

                return(Ok(adminViewModel));
            }
            catch (Exception ex)
            {
                return(WebApiErrorHandler.Throw(ex));
            }
        }
Example #27
0
        /// <summary>
        /// Convert User to CurrentUserViewModel
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static CurrentUserViewModel ToCurrentUserViewModel(this User model)
        {
            var dto = new CurrentUserViewModel();

            if (model != null)
            {
                dto.Email     = model.Email;
                dto.GivenName = model.GivenName;
                dto.Surname   = model.Surname;
                dto.Id        = model.Id;
                dto.District  = model.District;
                dto.SmAuthorizationDirectory = model.SmAuthorizationDirectory;
                dto.SmUserId  = model.SmUserId;
                dto.UserRoles = model.UserRoles;
            }
            return(dto);
        }
Example #28
0
        public ActionResult CurrentUser()
        {
            var claimsPrincipal = ClaimsPrincipal.Current;
            var currentUser     = new CurrentUserViewModel()
            {
                IsAuthenticated = claimsPrincipal != null && claimsPrincipal.Identity != null && claimsPrincipal.Identity.IsAuthenticated
            };

            if (currentUser.IsAuthenticated)
            {
                currentUser.Name = claimsPrincipal.Identity.Name;

                currentUser.FirstName = claimsPrincipal.Claims.Where(c => c.Type == FirstNameClaimType).Select(c => c.Value).FirstOrDefault();
                currentUser.LastName  = claimsPrincipal.Claims.Where(c => c.Type == LastNameClaimType).Select(c => c.Value).FirstOrDefault();
            }

            return(PartialView(currentUser));
        }
Example #29
0
        public ActionResult Editar([Bind(Include = "investigator_id,user_id,first_name,second_name,last_name,second_last_name,gender_id,mobile_phone," +
                                                   "birthdate_text,user_email,user_pass,document_type_id,doc_nro,nationality_id,contract_name,phone,address,user_pass2,institution_id," +
                                                   "investigation_group_id,program_id,interest_areas,address_country_id,department_id,address_municipality_id,commissions,educational_institution_id,education_level_id,CVLAC")]  InvestigatorViewModel pViewModel)
        {
            // TODO: Add insert logic here

            if (pViewModel == null)
            {
                return(HttpNotFound());
            }
            UserBL oUserBL = new UserBL();

            pViewModel.user_id_modified = AuthorizeUserAttribute.UsuarioLogeado().user_id;
            pViewModel.user_name        = pViewModel.first_name + " " + pViewModel.second_name + " " + pViewModel.last_name + " " + pViewModel.second_last_name;

            pViewModel.user_name    = pViewModel.user_name.Replace("  ", " ").Replace("  ", " ");
            pViewModel.contact_name = pViewModel.user_name;
            pViewModel.birthdate    = DateTime.ParseExact(pViewModel.birthdate_text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            pViewModel.avatar       = null;
            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var extension = Path.GetExtension(file.FileName);
                    var fileName  = Guid.NewGuid().ToString() + "." + extension;


                    pViewModel.avatar = "/Avatars/" + fileName;
                    var path = Path.Combine(Server.MapPath("~/Avatars/"), fileName);
                    file.SaveAs(path);
                }
            }

            oUserBL.ModificarInvestigator(pViewModel);
            CurrentUserViewModel result = oUserBL.GetCurrentUser(pViewModel.user_id.Value);

            result.name_abbre = Helper.Substring(result.name, 20);
            Session[System.Configuration.ConfigurationManager.AppSettings["session.usuario.actual"]] = result;


            return(Redirect("/Account/Editar/" + pViewModel.investigator_id));
        }
Example #30
0
        private bool verificarPermisoPorPerfil(CurrentUserViewModel usuario)
        {
            if (Permissions.Count() == 0)
            {
                return(true);
            }
            foreach (Permission item in Permissions)
            {
                if (usuario.permissions.Contains((int)item))
                {
                    return(true);
                }
            }


            motivoNoAutorizado = eMotivoNoAutorizado.PerfilNoAutorizado;

            return(false);
        }