Beispiel #1
0
        public void verifyThatAfterCorrectingPropertiesAndUserValidNoErrorMessagesExist()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();
            Assert.AreEqual(1, target.Users.Count, "Should have addded the user");

            //Test User - Fail
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsFalse(target.IsAuthenticated, "User should be invalid");
            Assert.IsFalse(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should be an error message");

            //Test User - Pass
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsTrue(target.IsAuthenticated, "User should be valid");
            Assert.IsTrue(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should not be an error message");
        }
Beispiel #2
0
        public async Task <IActionResult> UserManager(string keySearch, int page = 1, int pageSize = 5)
        {
            if (string.IsNullOrWhiteSpace(keySearch))
            {
                keySearch = string.Empty;
            }
            //var user = await userManager.GetUserAsync(User);
            List <User> users = new List <User>();

            users = userService.AllUser(keySearch);
            //
            List <UserBasicViewModel> listUser = new List <UserBasicViewModel>();

            foreach (var u in users)
            {
                // Get roles of user
                List <string> roles = new List <string>(await userManager.GetRolesAsync(u));

                UserBasicViewModel user = new UserBasicViewModel()
                {
                    ID          = u.Id,
                    HoTen       = u.HoTen,
                    Email       = u.Email,
                    PhoneNumber = u.PhoneNumber,
                    Roles       = roles,
                    State       = u.State
                };
                listUser.Add(user);
            }
            UserManagerViewModel model = new UserManagerViewModel(listUser, page, pageSize, keySearch);

            return(View(model));
        }
Beispiel #3
0
        public IActionResult Index(UserManagerViewModel model)
        {
            ViewData["Message"]    = "Your registration page!.";
            ViewBag.SuccessMessage = null;
            if (ModelState.IsValid)
            {
                try
                {
                    // Find your Account Sid and Auth Token at twilio.com/user/account
                    var acctSid = Configuration["Twilio:AccountSid"];
                    var authT   = Configuration["Twilio:AuthToken"];

                    TwilioClient.Init(acctSid, authT);

                    var to      = new PhoneNumber("+1" + model.PhoneNumber);
                    var message = MessageResource.Create(
                        to,
                        from: new PhoneNumber(Configuration["Twilio:ToNumber"]), //  From number, must be an SMS-enabled Twilio number ( This will send sms from ur "To" numbers ).
                        body: $"Hello {model.Name} {model.Text}");


                    ViewBag.SuccessMessage = "Registered Successfully !!";
                }
                catch (Exception ex)
                {
                    Console.WriteLine($" Registration Failure : {ex.Message} ");
                }
            }
            ModelState.Clear();
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public void verifyUsernameIsInvalid()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();
            Assert.AreEqual(1, target.Users.Count, "Should have addded the user");

            //User is clear
            Assert.IsTrue(String.IsNullOrEmpty(target.Username));
            Assert.IsTrue(String.IsNullOrEmpty(target.Password));
            Assert.IsTrue(String.IsNullOrEmpty(target.Realname));

            //Test User
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsFalse(target.IsAuthenticated, "User should be invalid");
            Assert.IsFalse(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should be an error message");
        }
Beispiel #5
0
        public HttpResponseMessage GetUser(string id)
        {
            var user = new UserManagerViewModel();

            user = _userManagerViewService.GetUser(id);
            return(Request.CreateResponse(HttpStatusCode.OK, user, MediaTypeHeaderValue.Parse("application/json")));
        }
        public ActionResult Index(UserManagerViewModel usersViewModel)
        {
            UserRepository userRepository = new UserRepository();

            userRepository.ModifyUsers(usersViewModel.Users);
            return(RedirectToAction("Index"));
        }
        // GET: User
        public ActionResult Index()
        {
            UserManagerViewModel userViewModel = new UserManagerViewModel();

            userViewModel.Users = new UserRepository().GetAllUsers();
            return(View(userViewModel));
        }
Beispiel #8
0
        public async Task <IActionResult> Index()
        {
            var allUsers = await _userManager.Users.ToListAsync();

            var vm = new List <UserManagerViewModel>();

            foreach (ApplicationUser user in allUsers)
            {
                string userId = user.Id;

                var thisvm = new UserManagerViewModel();
                thisvm.UserId     = user.Id;
                thisvm.UserName   = user.UserName;
                thisvm.Email      = user.Email;
                thisvm.IsBanned   = user.IsBanned;
                thisvm.SignUpDate = user.SignUpDate;
                thisvm.UserPortfolioItemMainComments = _repo.GetAllPortfolioItemMainComments(userId);
                thisvm.UserPortfolioItemSubComments  = _repo.GetAllPortfolioItemSubComments(userId);
                thisvm.UserPostMainComments          = _repo.GetAllPostMainComments(userId);
                thisvm.UserPostSubComments           = _repo.GetAllPostSubComments(userId);

                vm.Add(thisvm);
            }
            return(View(vm));
        }
Beispiel #9
0
        /// <summary>
        /// Generates the user manager page
        /// </summary>
        /// <returns>
        /// Returns the user manager view
        /// </returns>
        public ActionResult ManageUsers()
        {
            var Model = new UserManagerViewModel();

            Model.users = UserManager.Users.ToList();
            Model.roles = RoleManager.Roles.ToList();
            return(View(Model));
        }
Beispiel #10
0
 public BatchRecord(ICarPortAppService carPortAppService, MainWindowViewModel mainWindowViewModel, UserManagerViewModel userManagerViewModel, CarPortListDto carPortListDto)
 {
     InitializeComponent();
     _carPortListDto       = carPortListDto;
     _carPortAppService    = carPortAppService;
     _mainWindowViewModel  = mainWindowViewModel;
     _userManagerViewModel = userManagerViewModel;
 }
Beispiel #11
0
        public HttpResponseMessage GetUsers()
        {
            var context     = _contextService.GetContext();
            var userManager = new UserManagerViewModel();

            userManager = _userManagerViewService.GetUsers(context);
            return(Request.CreateResponse(HttpStatusCode.OK, userManager, MediaTypeHeaderValue.Parse("application/json")));
        }
Beispiel #12
0
        public UserManagementWindow()
        {
            InitializeComponent();

            _ConsoleViewModel.InitializeViewModelData();
            _UserManagerViewModel = new UserManagerViewModel(_ConsoleViewModel.HolderData.RegisteredEmployees);

            this.DataContext = _UserManagerViewModel;
        }
Beispiel #13
0
 public CarportInfo(ICarPortAppService carPortAppService, MainWindowViewModel mainWindowViewModel, UserManagerViewModel userManagerViewModel, CarPortListDto carPortListDto)
 {
     InitializeComponent();
     _carPortListDto                 = carPortListDto;
     _carPortAppService              = carPortAppService;
     _mainWindowViewModel            = mainWindowViewModel;
     _userManagerViewModel           = userManagerViewModel;
     _carPortTimeExTenstionViewModel = new CarPortTimeExTenstionViewModel();
 }
Beispiel #14
0
        public void checkNotifyPropertyChangedUserName()
        {
            User user = new User();
            UserManagerViewModel target = new UserManagerViewModel(user, null, null);
            bool eventWasRaised         = false;

            target.PropertyChanged += (sender, e) => eventWasRaised = e.PropertyName == "Username";
            target.Username         = "******";
            Assert.IsTrue(eventWasRaised, "Event for username change should have been raised");
        }
 public CarPortTimeExtension(ICarPortAppService carPortAppService, MainWindowViewModel mainWindowViewModel, UserManagerViewModel userManagerViewModel, CarPortListDto carPortListDto)
 {
     InitializeComponent();
     _carPortAppService              = carPortAppService;
     _mainWindowViewModel            = mainWindowViewModel;
     _userManagerViewModel           = userManagerViewModel;
     _carPortTimeExTenstionViewModel = new CarPortTimeExTenstionViewModel();
     _carPortTimeExTenstionViewModel.CarPortListDto = carPortListDto;
     DataContext = _carPortTimeExTenstionViewModel;
     _rechargeRecordAppService = IocManager.Resolve <IRechargeRecordAppService>();
 }
Beispiel #16
0
        public ActionResult UserManager()
        {
            UserManagerViewModel m = new UserManagerViewModel();

            m.users       = _dbhelper.GetUsers().ToList();
            m.currentuser = _dbhelper.GetUserById(new WritaUser()
            {
                Id = User.Identity.Name
            });
            m.posts = _dbhelper.GetAllPosts().ToList();
            return(View("~/Views/Admin/UserManager.cshtml", "~/Views/Admin/_Adminlayout.cshtml", m));
        }
Beispiel #17
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            MainWindow window = new MainWindow();

            User           user      = new User();
            UserRepository repo      = new UserRepository();
            PasswordHasher hasher    = new HmacSha512Hasher();
            var            viewModel = new UserManagerViewModel(user, repo, hasher);

            window.DataContext = viewModel;
            window.Show();
        }
        public async Task <IActionResult> Edit(string id)
        {
            ApplicationUser user = await userManager.FindByIdAsync(id);

            if (user != null)
            {
                UserManagerViewModel model = new UserManagerViewModel {
                    Email = user.Email, Id = user.Id, AllRoles = roleManager.Roles.ToList(), Roles = await userManager.GetRolesAsync(user)
                };
                return(View(model));
            }
            return(NotFound());
        }
Beispiel #19
0
 public AddCarNumber(UserManagerViewModel userManagerViewModel, ICarNumbersAppService carNumbersAppService)
 {
     InitializeComponent();
     _userManagerViewModel = userManagerViewModel;
     carNumbersListDto     = new CarNumbersListDto();
     _carNumbersAppService = carNumbersAppService;
     if (_userManagerViewModel.SelectDto != null)
     {
         carNumbersListDto.Phone   = _userManagerViewModel.SelectDto.Phone;
         carNumbersListDto.Contact = _userManagerViewModel.SelectDto.Contact;
         carNumbersListDto.Remark  = _userManagerViewModel.SelectDto.Remark;
     }
 }
Beispiel #20
0
        public void addUserThroughCommandAddUser()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUserCommand.Execute(null);
            Assert.AreEqual(1, target.Users.Count, "Should have addded the user");
        }
Beispiel #21
0
        public ActionResult Save(UserManagerViewModel newUserData)
        {
            if (!ModelState.IsValid)
            {
                return(View("UserManagerForm", newUserData));
            }


            var applicationUser = _userManager.FindById(newUserData.Id);

            if (applicationUser == null)
            {
                return(View("UserManagerForm", newUserData));
            }


            _userManager.RemoveFromRoles(applicationUser.Id, _userManager.GetRoles(applicationUser.Id).ToArray());

            if (newUserData.UserRoleIds != null)
            {
                var userRoleNames = newUserData.UserRoleIds
                                    .Select(r => _roleManager.FindById(r).Name)
                                    .ToArray();

                foreach (var roleName in userRoleNames)
                {
                    if (!_roleManager.RoleExists(roleName))
                    {
                        return(View("UserManagerForm", newUserData));
                    }
                }

                _userManager.AddToRoles(applicationUser.Id, userRoleNames);
            }

            _userManager.Update(applicationUser);


            var currentApplicationUser = _userManager.FindById(User.Identity.GetUserId());
            var authenticationManager  = System.Web.HttpContext.Current.GetOwinContext().Authentication;

            authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
            var identity = _userManager.CreateIdentity(currentApplicationUser, DefaultAuthenticationTypes.ApplicationCookie);

            authenticationManager.SignIn(new AuthenticationProperties {
                IsPersistent = false
            }, identity);

            return(RedirectToAction("Index"));
        }
Beispiel #22
0
        public void addingNewUserUserHashingFunction()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();

            Assert.IsTrue(hasherAlgorithm.VerifyHash("teste", target.Users[0].Password, "mige"));
        }
Beispiel #23
0
        public void verifyThatAfterAddingUserUIisCleared()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();

            Assert.IsTrue(String.IsNullOrEmpty(target.Username));
            Assert.IsTrue(String.IsNullOrEmpty(target.Password));
            Assert.IsTrue(String.IsNullOrEmpty(target.Realname));
        }
Beispiel #24
0
        public async Task <IActionResult> Index()
        {
            var admins = (await _userManager
                          .GetUsersInRoleAsync("Administrator"))
                         .ToArray();

            var everyone = await _userManager.Users
                           .ToArrayAsync();

            var model = new UserManagerViewModel
            {
                Administrators = admins,
                Everyone       = everyone
            };

            return(View(model));
        }
Beispiel #25
0
        public void verifyThatAddingUserWithErrorsFails()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            string error = (target as IDataErrorInfo)["Username"];

            Assert.IsFalse(String.IsNullOrEmpty(error), "Should have received error message");

            target.AddUser();
            Assert.AreEqual(0, target.Users.Count, "Should have not addded the user");
        }
Beispiel #26
0
 public UserManager(MainWindowViewModel mainWindowViewModel,
                    ICarUsersAppService carUsersAppService,
                    IParkAreasAppService parkAreasAppService,
                    ICarUserGroupAppService carUserGroupAppService,
                    ICarNumbersAppService carNumbersAppService,
                    ICarPortAppService carPortAppService
                    )
 {
     InitializeComponent();
     _mainWindowViewModel    = mainWindowViewModel;
     _carUsersAppService     = carUsersAppService;
     _parkAreasAppService    = parkAreasAppService;
     _carUserGroupAppService = carUserGroupAppService;
     _carNumbersAppService   = carNumbersAppService;
     _carPortAppService      = carPortAppService;
     _managerViewModel       = new UserManagerViewModel();
     DataContext             = _managerViewModel;
 }
Beispiel #27
0
        public async Task <IActionResult> UserManager()
        {
            var users = _userManager.Users.ToList();
            var model = new UserManagerViewModel();

            foreach (var user in users)
            {
                var roles = await _userManager.GetRolesAsync(user);

                var item = new UserRoleViewModel {
                    Roles = roles, User = user
                };

                model.Users.Add(item);
            }

            return(View(model));
        }
Beispiel #28
0
        public App()
        {
            LogonViewModel               = new LogonViewModel();
            MainPageViewModel            = new MainPageViewModel();
            LogonUserViewModel           = new LogonUserViewModel();
            UserManagerViewModel         = new UserManagerViewModel();
            FileTypeManagerViewModel     = new FileTypeManagerViewModel();
            TaxPayerTypeManagerViewModel = new TaxPayerTypeManagerViewModel();
            TaxPayerManagerViewModel     = new TaxPayerManagerViewModel();
            DocumentManagerViewModel     = new DocumentManagerViewModel();

            this.Startup            += this.Application_Startup;
            this.UnhandledException += this.Application_UnhandledException;
            this.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(App_CheckAndDownloadUpdateCompleted);
            InitializeComponent();
            WebContext webContext = new WebContext();

            webContext.Authentication = new FormsAuthentication();
            this.ApplicationLifetimeObjects.Add(webContext);
        }
Beispiel #29
0
        // GET: UserManager/Edit
        public ActionResult Edit(string userId)
        {
            var user = _context.Users
                       .SingleOrDefault(u => u.Id == userId);

            if (user == null)
            {
                return(HttpNotFound());
            }


            var userManagerViewModel = new UserManagerViewModel()
            {
                Id          = user.Id,
                Email       = user.Email,
                UserRoleIds = GetRolesByUserId(user.Id).Select(r => r.Id).ToList(),
                Roles       = _roles
            };

            return(View("UserManagerForm", userManagerViewModel));
        }
Beispiel #30
0
        public UserManagerViewModel GetUser(string idUser)
        {
            var result = new UserManagerViewModel();

            Guid userId;

            if (Guid.TryParse(idUser, out userId))
            {
                //user
                var userModel = _userManagerService.GetUser(userId);
                var user      = new UserViewModel();

                user.ID           = userModel.ID;
                user.Username     = userModel.Username;
                user.FirstName    = userModel.FirstName;
                user.LastName     = userModel.LastName;
                user.Email        = userModel.Email;
                user.CustomerName = userModel.CustomerName;
                user.RoleCode     = (int)userModel.Role;
                user.RoleName     = userModel.Role.GetDescription();
                user.LanguageId   = userModel.Language.ID;
                user.LanguageName = userModel.Language.Name;
                user.Enabled      = userModel.Enabled;
                user.Machines     = userModel.Machines.Select(s => new UserMachineViewModel {
                    Id = s.Id, Serial = s.Serial
                }).ToList();
                user.TimeZone = userModel.TimeZone;
                result.user   = user;

                //machines for customer
                result.machines = GetMachinesByCustomer(userModel.CustomerName);

                return(result);
            }
            else
            {
                return(null);
            }
        }