Beispiel #1
0
        public async Task <IActionResult> Teacher()
        {
            var user = await GetCurrentUserAsync();

            if (user is TeacherAccount)
            {
                var sc                   = _schoolClasses.GetByTeacher(user.Id);
                var messagesIn           = _messages.GetForUserReceiving(user.Id, 0, MessagesToRead, out var isMoreIn);
                var messagesOut          = _messages.GetForUserSending(user.Id, 0, MessagesToRead, out var isMoreOut);
                var students             = _students.GetStudentsForSchoolClass(sc.Id);
                var assignmentsGraded    = _assignments.GetGradedForSchoolClassId(sc.Id);
                var assignmentsNotGraded = _assignments.GetNotGradedForSchoolClassId(sc.Id);

                var model = new ManageAccountModel()
                {
                    MessagesInbound      = messagesIn,
                    MessagesOutbound     = messagesOut,
                    Students             = students,
                    TeacherSchoolClass   = sc,
                    AssignmentsGraded    = assignmentsGraded,
                    AssignmentsNotGraded = assignmentsNotGraded,
                    IsMoreIn             = isMoreIn,
                    IsMoreOut            = isMoreOut,
                    Offset = MessagesToRead,
                    UserId = user.Id
                };

                return(View(model));
            }

            return(RedirectToAction("Error", "Home"));
        }
        public ActionResult Index(ManageAccountModel account)
        {
            string id          = User.Identity.GetUserId();
            var    currentUser = ApplicationDbContext.Users.FirstOrDefault(u => u.Id == id)
                                 ?? throw new ArgumentNullException("User not found");
            var location = GetOrSaveUserLocation(account);

            AddPhotoToViewModel(account);

            if (currentUser.Location != location)
            {
                currentUser.Location = location;
            }

            if (currentUser.DateOfBirth != Encryption.Encrypt(account.DateOfBirth.ToString()))
            {
                currentUser.DateOfBirth = Encryption.Encrypt(account.DateOfBirth.ToString());
            }

            if (currentUser.Photo != account.Photo && account.Photo != null)
            {
                currentUser.Photo          = account.Photo;
                currentUser.PhotoThumbnail = account.PhotoThumbnail;
            }

            ApplicationDbContext.Entry(currentUser).State = EntityState.Modified;
            ApplicationDbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public async Task <IActionResult> Parent()
        {
            var user = await GetCurrentUserAsync();

            if (user is ParentAccount)
            {
                var messagesIn  = _messages.GetForUserReceiving(user.Id, 0, MessagesToRead, out var isMoreIn);
                var messagesOut = _messages.GetForUserSending(user.Id, 0, MessagesToRead, out var isMoreOut);
                var students    = _students.GetForParent(user.Id);

                var model = new ManageAccountModel()
                {
                    MessagesInbound  = messagesIn,
                    MessagesOutbound = messagesOut,
                    Students         = students,
                    IsMoreIn         = isMoreIn,
                    IsMoreOut        = isMoreOut,
                    Offset           = MessagesToRead,
                    UserId           = user.Id
                };

                return(View(model));
            }

            return(RedirectToAction("Error", "Home"));
        }
        private async Task <ManageAccountModel> GetManageAccountModel()
        {
            var userId = User.Identity.GetUserId();

            var phoneNumber = await UserManager.GetPhoneNumberAsync(userId);

            var model = new ManageAccountModel
            {
                HasPassword       = HasPassword(),
                PhoneNumber       = !string.IsNullOrWhiteSpace(phoneNumber) ? Encryption.Decrypt(phoneNumber) : phoneNumber,
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            var user = ApplicationDbContext.Users
                       .Include(s => s.Location)
                       .FirstOrDefault(x => x.Id == userId);

            if (user != null)
            {
                model.UserName           = user.UserName;
                model.Email              = Encryption.DecryptionForEmail(user.Email);
                model.Photo              = user.Photo;
                model.PhotoThumbnail     = user.PhotoThumbnail;
                model.DateOfBirth        = !string.IsNullOrWhiteSpace(user.DateOfBirth) ? DateTime.Parse(Encryption.Decrypt(user.DateOfBirth)) : (DateTime?)null;
                model.LocationId         = user.Location?.ParentLocation != null ? user.Location?.Id : null;
                model.LocationName       = user.Location?.ParentLocation != null ? user.Location?.Name : null;
                model.ParentLocationId   = user.Location?.ParentLocation == null ? user.Location?.Id : user.Location?.ParentLocation.Id;
                model.ParentLocationName = user.Location?.ParentLocation == null ? user.Location?.Name : user.Location?.ParentLocation.Name;
                model.CountryId          = user.Location?.Country.Id;
                model.CountryName        = user.Location?.Country.Name;
            }
            return(model);
        }
        public async Task <IActionResult> Manage()
        {
            var model = new ManageAccountModel
            {
                OpenIdApps = await GetUserOpenIdApps()
            };

            return(View(model));
        }
Beispiel #6
0
        public void AccountController_GetManageAccountModel_ValidateValues_Test()
        {
            AccountController ac = new AccountController();

            //set test values into ASAMemberModel
            ASAMemberModel amModel = new ASAMemberModel();

            SetASAMemberModelValues(amModel);

            //values that should be set on Model
            string emailAddressPrimary = "*****@*****.**";

            string firstName   = "FirstName";
            string lastName    = "LastName";
            string newPassword = "******";
            string password    = "******";
            short  yearOfBirth = 1975;

            string phoneNumber     = "1-619-555-1212";
            string phoneNumberType = "Mobile";

            string oeCode           = "123456";
            string branchCode       = "12";
            string organizationName = "ASA University";
            int    expectedGraduationYearDefault = 2001;

            // Wrap an already existing instance
            PrivateObject accessor = new PrivateObject(ac);

            // Call a private method
            ManageAccountModel maModel = (ManageAccountModel)accessor.Invoke("GetManageAccountModel", amModel);

            Assert.AreEqual(emailAddressPrimary, maModel.EmailAddress);
            Assert.AreEqual(emailAddressPrimary, maModel.UserName);

            Assert.AreEqual(phoneNumber, maModel.PhoneNumber);
            Assert.AreEqual(phoneNumberType, maModel.PhoneNumberType);

            Assert.AreEqual(oeCode, maModel.OECode);
            Assert.AreEqual(branchCode, maModel.BranchCode);
            Assert.AreEqual(organizationName, maModel.OrganizationName);

            Assert.AreEqual(newPassword, maModel.ConfirmPassword);
            Assert.AreEqual(newPassword, maModel.NewPassword);
            Assert.AreEqual(password, maModel.Password);

            Assert.AreEqual(firstName, maModel.FirstName);
            Assert.AreEqual(lastName, maModel.LastName);
            Assert.IsTrue(maModel.IsCommunityActive);
            Assert.AreEqual(expectedGraduationYearDefault, maModel.ExpectedGraduationYear);
            Assert.AreEqual(null, maModel.USPostalCode);
            Assert.AreEqual(null, maModel.SALTSchoolTypeID);
            Assert.AreEqual(yearOfBirth, maModel.YOB);

            Assert.IsFalse(maModel.AddressValidated);
        }
Beispiel #7
0
        public void UserName_manageAccountModel_check_for_valid_username_ValidValue()
        {
            ManageAccountModel passingValue = new ManageAccountModel()
            {
                UserName = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValue, "UserName");

            Assert.IsTrue(valid, "Assertion of positive case being true failed");
        }
Beispiel #8
0
        public void EmailAddressTest_manageAccount_check_for_required_InvalidValue()
        {
            ManageAccountModel invalidValue = new ManageAccountModel()
            {
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(invalidValue, "EmailAddress");

            Assert.IsFalse(valid, "Assertion of negative case being false failed");
            Assert.AreEqual("Email Address is required!", invalidValue.ErrorList[0].BusinessMessage);
        }
Beispiel #9
0
        public void EnrollmentStatus_manageAccount_Test_check_for_string_length_ValidValue()
        {
            ManageAccountModel passingValue = new ManageAccountModel()
            {
                EnrollmentStatus = "P"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValue, "EnrollmentStatus");

            Assert.IsTrue(valid, "Assertion of positive case being true failed");
        }
Beispiel #10
0
        public void UserName_manageAccount_check_for_string_length_ValidUpperBoundValue()
        {
            ManageAccountModel passingValueUpperBound = new ManageAccountModel()
            {
                UserName = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValueUpperBound, "UserName");

            Assert.IsTrue(valid, "Assertion of positive case (upper bound) being true failed");
        }
Beispiel #11
0
        public void EmailAddressTest_manageAccount_check_for_string_length_ValidLowerBoundValue()
        {
            ManageAccountModel passingValueLowerBound = new ManageAccountModel()
            {
                EmailAddress = "*****@*****.**"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValueLowerBound, "EmailAddress");

            Assert.IsTrue(valid, "Assertion of positive case (lower bound) being true failed");
        }
Beispiel #12
0
        public void PasswordTest_manageAccount_check_for_password_standards_ASA()
        {
            ManageAccountModel passingValue = new ManageAccountModel()
            {
                Password = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValue, "Password");

            Assert.IsTrue(valid, "Assertion of positive case (1 of 4 attributes) being true failed");
        }
Beispiel #13
0
        public void EmailAddressTest_manageAccount_check_for_valid_email_ValidValue()
        {
            ManageAccountModel passingValue = new ManageAccountModel()
            {
                EmailAddress = "*****@*****.**"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValue, "EmailAddress");

            Assert.IsTrue(valid, "Assertion of positive case being true failed");
        }
Beispiel #14
0
        public void PasswordTest_manageAccount_check_for_string_length_ValidUpperBoundValue()
        {
            ManageAccountModel passingValueUpperBound = new ManageAccountModel()
            {
                Password = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValueUpperBound, "Password");

            Assert.IsTrue(valid, "Assertion of positive case (upper bound) being true failed");
        }
Beispiel #15
0
        public void YOBTest_manageAccount_check_for_valid_YOB_ValidValue()
        {
            ManageAccountModel passingValue = new ManageAccountModel()
            {
                YOB = (short)(DateTime.Today.Year - 14)
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValue, "YOB");

            Assert.IsTrue(valid, "Assertion of positive case being true failed");
        }
Beispiel #16
0
        public void PasswordTest_Confirm_manageAccount_check_for_string_length_ValidLowerBoundValue()
        {
            ManageAccountModel passingValueLowerBound = new ManageAccountModel()
            {
                ConfirmPassword = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValueLowerBound, "ConfirmPassword");

            Assert.IsTrue(valid, "Assertion of positive case (lower bound) being true failed");
        }
Beispiel #17
0
        public void EmailAddressTest_manageAccount_check_for_required_ValidValue()
        {
            ManageAccountModel passingValue = new ManageAccountModel()
            {
                EmailAddress = "*****@*****.**"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(passingValue, "EmailAddress");

            Assert.IsTrue(valid, "Assertion of positive case being true failed");
        }
Beispiel #18
0
        public void UserName_manageAccountModel_check_for_valid_username_InvalidValue()
        {
            ManageAccountModel invalidValue = new ManageAccountModel()
            {
                UserName = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(invalidValue, "UserName");

            Assert.IsFalse(valid, "Assertion of negative case being false failed");
            Assert.AreEqual("Please enter a valid user name.", invalidValue.ErrorList[0].BusinessMessage);
        }
Beispiel #19
0
        public void UserName_manageAccount_check_for_string_length_InvalidUnderMinValue()
        {
            ManageAccountModel failingValueUnderMin = new ManageAccountModel()
            {
                UserName = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(failingValueUnderMin, "UserName");

            Assert.IsFalse(valid, "Assertion of negative case (under min) being false failed");
            Assert.AreEqual("The UserName must be between 8 and 64 characters long.", failingValueUnderMin.ErrorList[0].BusinessMessage);
        }
Beispiel #20
0
        public void EnrollmentStatus_manageAccount_Test_check_for_string_length_InvalidOverMaxValue()
        {
            ManageAccountModel failingValueOverMax = new ManageAccountModel()
            {
                EnrollmentStatus = "2C"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(failingValueOverMax, "EnrollmentStatus");

            Assert.IsFalse(valid, "Assertion of negative case (over max) being false failed");
            Assert.AreEqual("The field Enrollment Status must be a string with a minimum length of 1 and a maximum length of 1.", failingValueOverMax.ErrorList[0].BusinessMessage);
        }
Beispiel #21
0
        public void YOBTest_manageAccount_check_for_valid_YOB_InvalildValue()
        {
            ManageAccountModel invalildValue = new ManageAccountModel()
            {
                YOB = (short)(DateTime.Today.Year - 32767)
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(invalildValue, "YOB");

            Assert.IsFalse(valid, "Assertion of negative case being false failed");
            Assert.AreEqual("Year of birth is invalid.", invalildValue.ErrorList[0].BusinessMessage);
        }
Beispiel #22
0
        public void EmailAddressTest_manageAccount_check_for_valid_email_InvalidValue()
        {
            ManageAccountModel invalidValue = new ManageAccountModel()
            {
                EmailAddress = "failString"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(invalidValue, "EmailAddress");

            Assert.IsFalse(valid, "Assertion of negative case being false failed");
            Assert.AreEqual("Please enter a valid email.", invalidValue.ErrorList[0].BusinessMessage);
        }
Beispiel #23
0
        public async Task <IActionResult> Index()
        {
            ConfaqueUser user = await this._userManager.GetUserAsync(this.User).ConfigureAwait(false);

            ManageAccountModel model = new ManageAccountModel()
            {
                Email    = user.Email,
                Username = user.UserName,
                IsTwoFactorAuthEnabled = user.TwoFactorEnabled,
                IsEmailConfirmed       = user.EmailConfirmed,
            };

            return(View(model));
        }
        private Location GetOrSaveUserLocation(ManageAccountModel model)
        {
            var country = ApplicationDbContext.Countries.FirstOrDefault(x => x.Name.ToUpper() == model.CountryName.ToUpper());

            if (country == null)
            {
                country = ApplicationDbContext.Countries.Add(new Country {
                    Name = model.CountryName
                });
                ApplicationDbContext.SaveChanges();
            }

            var parentLocation = ApplicationDbContext.Locations
                                 .Where(x => x.Name.ToUpper() == model.ParentLocationName.ToUpper())
                                 .Include(y => y.ParentLocation).Include(y => y.Country)
                                 .FirstOrDefault(x => x.CountryId == country.Id && !x.ParentLocationId.HasValue);

            if (parentLocation == null)
            {
                parentLocation =
                    ApplicationDbContext.Locations.Add(new Location {
                    Name = model.ParentLocationName, Country = country
                });
                ApplicationDbContext.SaveChanges();
            }

            var userLocation = parentLocation;

            if (string.IsNullOrWhiteSpace(model.LocationName))
            {
                return(userLocation);
            }

            var location = ApplicationDbContext.Locations.Where(x => x.Name.ToUpper() == model.LocationName.ToUpper())
                           .Include(y => y.ParentLocation)
                           .FirstOrDefault(x => x.ParentLocationId.HasValue && x.ParentLocationId.Value == parentLocation.Id);

            if (location == null)
            {
                location = ApplicationDbContext.Locations.Add(
                    new Location {
                    Name = model.LocationName, Country = country, ParentLocation = parentLocation
                });
                ApplicationDbContext.SaveChanges();
            }

            userLocation = location;
            return(userLocation);
        }
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : 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."
                : "";

            ManageAccountModel model = await GetManageAccountModel();

            return(View(model));
        }
Beispiel #26
0
        public void EmailAddressTest_manageAccount_check_for_string_length_InvalidUnderMinValue()
        {
            ManageAccountModel failingValueUnderMin = new ManageAccountModel()
            {
                EmailAddress = "*****@*****.**"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(failingValueUnderMin, "EmailAddress");

            Assert.IsFalse(valid, "Assertion of negative case (under min) being false failed");
            Assert.AreEqual(1, failingValueUnderMin.ErrorList.Count, "Expected 1 error");
            Assert.AreEqual(failingValueUnderMin.ErrorList[0].BusinessMessage, "The EmailAddress address must be between 8 and 64 characters long.");
        }
 public ActionResult Manage(ManageAccountModel manageAccountModel)
 {
     if (ModelState.IsValid)
     {
         string loggedUserName = UserSession.GetLoggedUserName();
         var    user           = db.Users.SingleOrDefault(x => x.LoginName == loggedUserName);
         if (manageAccountModel.OldPassword == user.LoginPassword)
         {
             user.LoginPassword = manageAccountModel.Password;
             db.SaveChanges();
             return(RedirectToAction("Index", "Dashboard"));
         }
     }
     return(View());
 }
Beispiel #28
0
        public void UserName_manageAccount_check_for_string_length_InvalidOverMaxValue()
        {
            ManageAccountModel failingValueOverMax = new ManageAccountModel()
            {
                UserName = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(failingValueOverMax, "UserName");

            Assert.IsFalse(valid, "Assertion of negative case (over max) being false failed");
            Assert.AreEqual(2, failingValueOverMax.ErrorList.Count, "Expected 2 errors");
            String verifyMessage = failingValueOverMax.ErrorList[0].BusinessMessage + failingValueOverMax.ErrorList[1].BusinessMessage;

            Assert.IsTrue(verifyMessage.Contains("Please enter a valid user name."), "message should contain - Please enter a valid user name.");
            Assert.IsTrue(verifyMessage.Contains("The UserName must be between 8 and 64 characters long."), "message should contain - The UserName must be between 8 and 64 characters long.");
        }
Beispiel #29
0
        public void PasswordTest_Confirm_manageAccount_check_for_string_length_InvalidUnderMinValue()
        {
            ManageAccountModel failingValueUnderMin = new ManageAccountModel()
            {
                ConfirmPassword = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(failingValueUnderMin, "ConfirmPassword");

            Assert.IsFalse(valid, "Assertion of negative case (under min) being false failed");
            Assert.AreEqual(2, failingValueUnderMin.ErrorList.Count, "Expected 2 errors");
            String verifyMessage = failingValueUnderMin.ErrorList[0].BusinessMessage + failingValueUnderMin.ErrorList[1].BusinessMessage;

            Assert.IsTrue(verifyMessage.Contains("Invalid Password"), "message should contain - Invalid Password");
            Assert.IsTrue(verifyMessage.Contains("The Confirm Password must be between 8 and 32 characters long."), "message should contain - The Confirm Password must be between 8 and 32 characters long.");
        }
Beispiel #30
0
        public void PasswordTest_manageAccount_check_for_string_length_InvalidOverMaxValue()
        {
            ManageAccountModel failingValueOverMax = new ManageAccountModel()
            {
                Password = "******"
            };

            ASAModelValidator mv = new ASAModelValidator();

            bool valid = mv.Validate(failingValueOverMax, "Password");

            Assert.IsFalse(valid, "Assertion of negative case (over max) being false failed");
            Assert.AreEqual(2, failingValueOverMax.ErrorList.Count, "Expected 2 errors");
            String verifyMessage = failingValueOverMax.ErrorList[0].BusinessMessage + failingValueOverMax.ErrorList[1].BusinessMessage;

            Assert.IsTrue(verifyMessage.Contains("Invalid Password"), "message should contain - Invalid Password");
            Assert.IsTrue(verifyMessage.Contains("The Password must be between 8 and 32 characters long."), "message should contain - The Password must be between 8 and 32 characters long.");
        }