Beispiel #1
0
        public bool SetPassword(UserClasses uc, long UserID)
        {
            LoginSecController lc = new LoginSecController();

            Assert.AreNotEqual(lc, null);
            Console.WriteLine("Setting Password for user " + Convert.ToString(UserID));

            uc.UserID = UserID;

            IHttpActionResult resp = lc.SetPassword(uc);

            Assert.AreNotEqual(resp, null);

            Assert.IsInstanceOfType(resp, typeof(OkNegotiatedContentResult <bool>));

            var lresp = resp as OkNegotiatedContentResult <bool>;

            Assert.AreNotEqual(lresp, null);

            bool passwordSet = false;

            passwordSet = lresp.Content;

            return(passwordSet);
        }
 void InitializeDatabaseInterfaces()
 {
     DamageTypes.SetupDatabaseInterface(out m_dbiDamageTypes);
     WeaponTypes.SetupDatabaseInterface(out m_dbiWeaponTypes);
     UserClasses.SetupDatabaseInterface(out m_dbiUserClasses);
     Abilities.SetupDatabaseInterface(out m_dbiAbilities);
     Objects.SetupDatabaseInterface(out m_dbiObjects);
     Squads.SetupDatabaseInterface(out m_dbiSquads);
     Techs.SetupDatabaseInterface(out m_dbiTechs);
     Powers.SetupDatabaseInterface(out m_dbiPowers);
     Civs.SetupDatabaseInterface(out m_dbiCivs);
     Leaders.SetupDatabaseInterface(out m_dbiLeaders);
 }
Beispiel #3
0
        public async Task <IActionResult> Enroll([Bind("ClassId,UserId")] UserClasses userClasses)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userClasses);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(StudentClasses)));
            }
            ViewData["ClassId"] = new SelectList(_context.ClassList, "ClassName", "ClassName", userClasses.ClassId);
            ViewBag.ClassList   = _context.ClassList.ToList();
            return(View(userClasses));
        }
Beispiel #4
0
        public IHttpActionResult SetPassword(UserClasses sp)
        {
            ObjectParameter op = new ObjectParameter("success", typeof(int));

            db.setPassword(sp.Hash, sp.UserID, sp.Password, op);
            if ((int)op.Value == 1)
            {
                return(Ok(true));
            }
            else
            {
                return(Ok(false));
            }
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName")] Students students)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(students);
                UserClasses user = new UserClasses();
                user.fk_Class = (int)Session["CurrentClassId"];
                user.fk_User  = db.Students.Max(x => x.Id);
                db.UserClasses.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(students));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Section,StartTime,EndTime,Length,Days")] Class @class)
        {
            if (ModelState.IsValid)
            {
                db.Classes.Add(@class);
                UserClasses user = new UserClasses();
                user.fk_Class = db.Classes.Max(x => x.Id);
                user.fk_User  = Convert.ToInt32(Session["UserID"]);
                db.UserClasses.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(@class));
        }
Beispiel #7
0
        // #NOTE place new DatabaseObjectKind code here

        void InitializeDatabaseInterfaces()
        {
            DamageTypes.SetupDatabaseInterface();
            ImpactEffects.SetupDatabaseInterface();
            WeaponTypes.SetupDatabaseInterface();
            UserClasses.SetupDatabaseInterface();
            Abilities.SetupDatabaseInterface();
            Objects.SetupDatabaseInterface();
            Squads.SetupDatabaseInterface();
            Tactics.SetupDatabaseInterface();
            Techs.SetupDatabaseInterface();
            TerrainTileTypes.SetupDatabaseInterface();
            Powers.SetupDatabaseInterface();
            Civs.SetupDatabaseInterface();
            Leaders.SetupDatabaseInterface();
        }
Beispiel #8
0
        public void cc_LoginSec_SetPasswordAndLogin()
        {
            UserClasses uc = new UserClasses();

            // need to find userid of added user


            Assert.AreNotEqual(AddedUser, null);

            ac_GetAllUsers();

            Assert.AreNotEqual(userList, null);
            Assert.AreNotEqual(userList.Count, 0);
            string Supplier = "";

            foreach (Users u in userList)
            {
                if (u.UserName == AddedUser.UserName)
                {
                    AddedUser.UserID = u.UserID;
                    Supplier         = u.SupplierCode;
                }
            }

            Assert.AreNotEqual(AddedUser.UserID, 0);



            uc.Hash     = _loginResponse.Token;
            uc.UserID   = (long)AddedUser.UserID;
            uc.Password = "******";

            bool resp = SetPassword(uc, AddedUser.UserID);

            Console.WriteLine("Password set to [B4rc0de1] for UserID [" + Convert.ToString(uc.UserID) + "] using hash [" + _loginResponse.Token + "]");

            Assert.AreEqual(resp, true);

            LoginResponse lr = LoginUser(AddedUser.UserName, "B4rc0de1", Supplier);

            Assert.AreNotEqual(lr, null);
            Assert.AreNotEqual(lr.Token, "0");
            Console.Write("Logged in Successfully");
        }
Beispiel #9
0
        public string GetName(DatabaseObjectKind kind, int id)
        {
            Contract.Requires <ArgumentOutOfRangeException>(kind != DatabaseObjectKind.None);

            // #NOTE place new DatabaseObjectKind code here

            switch (kind)
            {
            case DatabaseObjectKind.Ability:        return(Abilities.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.Civ:            return(Civs.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.DamageType:     return(DamageTypes.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.ImpactEffect: return(ImpactEffects.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.Leader:         return(Leaders.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.Object:         return(Objects.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.ObjectType:     return(ObjectTypes.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.Power:          return(Powers.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.Squad:          return(Squads.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.Tactic:         return(Tactics.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.Tech:           return(Techs.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.TerrainTileType: return(TerrainTileTypes.TryGetNameWithUndefined(id));

            // TODO: Should just use the Objects DBI AFAICT
            case DatabaseObjectKind.Unit:           return(TryGetNameUnit(id));

            case DatabaseObjectKind.UserClass:      return(UserClasses.TryGetNameWithUndefined(id));

            case DatabaseObjectKind.WeaponType:     return(WeaponTypes.TryGetNameWithUndefined(id));

            default: throw new KSoft.Debug.UnreachableException(kind.ToString());
            }
        }
Beispiel #10
0
        public long CreateUser(string UserName, string Password, string FullName, string Telephone, string Supplier, string hash, int AdminLevel, bool Fail = true)
        {
            /*
             * Add a new user
             */


            if (String.IsNullOrEmpty(UserName))
            {
                Assert.Fail("username parameter is missing");
            }
            if (String.IsNullOrEmpty(Supplier))
            {
                Assert.Fail("supplier parameter is missing");
            }
            if (String.IsNullOrEmpty(hash))
            {
                Console.WriteLine("Caution : hash is empty on CreateUser()");
            }

            AddedUser              = new AddUser();
            AddedUser.AdminLevel   = AdminLevel;
            AddedUser.FullName     = FullName;
            AddedUser.SupplierCode = Supplier;
            AddedUser.UserName     = UserName;
            AddedUser.Telephone    = Telephone;
            AddedUser.Hash         = hash;

            Console.WriteLine("New user { " + AddedUser._display() + " }");


            UserController uc = new UserController();

            Assert.AreNotEqual(uc, null);
            IHttpActionResult resp = uc.AddUser(AddedUser);

            Assert.AreNotEqual(resp, null);

            AddUserResponse aur = new AddUserResponse();

            Assert.AreNotEqual(aur, null);

            Assert.IsInstanceOfType(resp, typeof(OkNegotiatedContentResult <AddUserResponse>));

            var lresp = resp as OkNegotiatedContentResult <AddUserResponse>;

            Assert.AreNotEqual(lresp, null);

            aur = lresp.Content;

            Assert.AreNotEqual(aur, null);    //checked returned an object

            Console.WriteLine("Response : { " + aur._display() + " }");
            Console.WriteLine(String.Format("Result of add is {0}", aur.ReturnCode));
            if (aur.ErrorMessage.Count > 0)
            {
                foreach (string msg in aur.ErrorMessage)
                {
                    Console.WriteLine(msg);
                }
            }
            if (Fail)
            {
                Assert.AreEqual(aur.ReturnCode, 0);
            }


            if (aur.ReturnCode == 0)
            {
                // need to find userid

                ab_Login_Valid();
                ac_GetAllUsers();
                Assert.AreNotEqual(userList, null);
                Assert.AreNotEqual(userList.Count, 0);
                foreach (Users u in userList)
                {
                    if (u.UserName == AddedUser.UserName)
                    {
                        AddedUser.UserID = u.UserID;
                        Supplier         = u.SupplierCode;
                    }
                }

                Console.WriteLine("Setting password to " + Password);

                UserClasses x = new UserClasses();
                x.Hash     = _loginResponse.Token;
                x.UserID   = (long)AddedUser.UserID;
                x.Password = Password;
                LoginResponse savelr = _loginResponse;
                bool          result = SetPassword(x, AddedUser.UserID);
                _loginResponse = savelr;

                Assert.AreEqual(result, true);
            }


            return(AddedUser.UserID);
        }
Beispiel #11
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ApplicationUser     user         = null;
            List <IdentityRole> userRoles    = null;
            List <School>       UserSchools  = null;
            List <Student>      UserStudents = null;
            List <ClassRoom>    UserClasses  = null;
            IndexViewModel      model        = null;
            string userId = "";

            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                                        : message == ManageMessageId.EmailConfirmationSent ? "Email Confirmation Sent. Please check your email to confirm change"
                                        : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                                        : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                                        : message == ManageMessageId.Error ? "An error has occurred."
                                        : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                                        : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                                        : message == ManageMessageId.AddStudentSuccess ? "Student was successfully added"
                                        : message == ManageMessageId.RemoveStudentSuccess ? "Student was successfully removed"
                                        : message == ManageMessageId.AddClassSuccess ? "Class was successfully added"
                                        : message == ManageMessageId.RemoveClassSuccess ? "Class was successfully removed"
                                        : message == ManageMessageId.RemoveClassSuccess ? "Class was successfully removed"
                                        : "";

            userId = User.Identity.GetUserId();
            user   = UserManager.FindById(userId);

            userRoles = null;
            userRoles = RoleManager.Roles.Where(r => r.Users.Any(ru => ru.UserId == userId)).ToList();

            if (User.IsInRole("Guardian"))
            {
                UserStudents = EntityDB.Students.Where(s => s.Guardians.Any(g => g.Id == userId)).ToList();
                UserSchools  = UserStudents.Select(us => us.School).Distinct().ToList();
                UserClasses  = new List <ClassRoom>();
            }
            else if (User.IsInRole("Teacher"))
            {
                UserClasses  = EntityDB.ClassRooms.Where(c => c.TeacherUserID == userId).ToList();
                UserStudents = new List <Student>();
                UserSchools  = UserClasses.Select(uc => uc.School).Distinct().ToList();
            }
            else if (User.IsInRole("School Admin"))
            {
                AspNetUser aspNetUser = EntityDB.AspNetUsers.Where(a => a.Id == userId).FirstOrDefault();
                if (aspNetUser == null)
                {
                    throw new Exception("Unable to locate user account by ID");
                }
                UserSchools  = aspNetUser.Schools.ToList();
                UserStudents = new List <Student>();
                UserClasses  = new List <ClassRoom>();
            }
            else if (User.IsInRole("System Admin"))
            {
                UserSchools  = new List <School>();
                UserStudents = new List <Student>();
                UserClasses  = new List <ClassRoom>();
            }
            else
            {
                throw new Exception("User Security Misconfigured");
            }

            model = new IndexViewModel
            {
                EmailConfirmed    = user.EmailConfirmed,
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                IsSubscribed      = MailGunUtility.IsSubscribed(user.Email),
                Email             = user.Email,
                FirstName         = user.FirstName,
                LastName          = user.LastName,
                MiddleName        = user.MiddleName,
                Schools           = UserSchools,
                Students          = UserStudents,
                Classes           = UserClasses,
                Roles             = userRoles
            };

            return(View(model));
        }