Пример #1
0
        public ActionResult Add()
        {
            List <role> roles = new List <role>();

            roles.Add(new role(1, "user"));
            roles.Add(new role(2, "admin"));
            adminViewModel model = new adminViewModel(roles);


            return(View(model));
        }
Пример #2
0
        public Admin()
        {
            InitializeComponent();
            checkIn();
            statusbarTime.Content = (DateTime.Now.TimeOfDay.Hours > 13 ? (DateTime.Now.TimeOfDay.Hours - 12) : DateTime.Now.TimeOfDay.Hours) + ":" + (DateTime.Now.TimeOfDay.Minutes < 10 ? "0" : "") + (DateTime.Now.TimeOfDay.Hours > 12 ? DateTime.Now.TimeOfDay.Minutes + " PM" : DateTime.Now.TimeOfDay.Minutes + " AM");

            _adminWindowViewModel = new adminViewModel();
            this.DataContext      = _adminWindowViewModel;

            applyColor(fabMain);

            actionPanelLabel.Content = "Admin";
            border.Visibility        = Visibility.Visible;
            fnSetFabVisible(Visibility.Hidden);
        }
Пример #3
0
        public ActionResult Add(adminViewModel pModel)
        {
            //super hackish but will work until roles table gets built in database
            List <role> roles = new List <role>();

            roles.Add(new role(1, "user"));
            roles.Add(new role(2, "admin"));
            pModel.roles = roles;
            string    passHash;
            userTable newUser = new userTable();

            //Validation
            var existingUser = (from records in db.userTables
                                where records.userName == pModel.userName
                                select new { uName = records.userName });

            if (existingUser.Count() != 0)
            {
                ModelState.AddModelError("userName", "User Name already exists, pick another User Name");
            }



            if (!string.IsNullOrEmpty(pModel.userName))
            {
                string regex = "([a-zA-Z0-9]){5,10}";
                Regex  re    = new Regex(regex);
                if (!re.IsMatch(pModel.userName))
                {
                    ModelState.AddModelError("userName", "Invalid User Name: User Name must be 5-10 characters and may only contain alphanumeric characters.");
                }
            }
            else
            {
                ModelState.AddModelError("userName", "User Name is Empty.");
            }

            if (!string.IsNullOrEmpty(pModel.userPasswordFirst))
            {
                string regex = @"(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}";
                Regex  re    = new Regex(regex);
                if (!re.IsMatch(pModel.userPasswordFirst))
                {
                    ModelState.AddModelError("userPasswordFirst", "Invalid password. Password must be at least 8 characters with at least one lowercase, one uppercase letter, and one digit.");
                }
            }
            else
            {
                ModelState.AddModelError("userPasswordFirst", "Password is Empty");
            }


            if (pModel.userPasswordFirst != pModel.userPasswordSecond)
            {
                ModelState.AddModelError("userPasswordSecond", "Passwords do not match");
            }
            else if (string.IsNullOrEmpty(pModel.userPasswordSecond))
            {
                ModelState.AddModelError("userPasswordSecond", "Password is Empty");
            }

            //add data

            if (ModelState.IsValid)
            {
                passHash         = security.createHash(pModel.userPasswordFirst);
                newUser.userName = pModel.userName;
                if (pModel.selectedRoleID == 1)
                {
                    newUser.userRole = "user";
                }
                else
                {
                    newUser.userRole = "admin";
                }
                newUser.userPassword = passHash;
                db.userTables.Add(newUser);
                db.SaveChanges();

                return(RedirectToAction("AddConfirmed", "Admin", new { userName = pModel.userName }));
            }

            else
            {
                return(View(pModel));
            }
        }