コード例 #1
0
        public ActionResult Register(RegisterViewModel viewModel, int stateInt)
        {
            string stringStateAbbreviation = StateList.First(m => m.Value == stateInt.ToString()).Text;

            if (ModelState.IsValid)
            {
                var model = new RegisterModel
                {
                    UserName            = viewModel.UserName,
                    Email               = viewModel.Email,
                    FirstMidName        = viewModel.FirstMidName,
                    LastName            = viewModel.LastName,
                    StreetAddress       = viewModel.StreetAddress,
                    City                = viewModel.City,
                    State               = stringStateAbbreviation,
                    ZipCode             = viewModel.ZipCode,
                    Phone               = viewModel.Phone,
                    DateOfBirth         = viewModel.DateOfBirth,
                    ParishAffiliation   = viewModel.ParishAffiliation,
                    MinistryInvolvement = viewModel.MinistryInvolvement,
                    Password            = viewModel.Password,
                    ConfirmPassword     = viewModel.ConfirmPassword
                };
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(
                    model.UserName, model.Password, model.Email, null, null, false, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    //FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    CustomProfile profile = CustomProfile.GetUserProfile(model.UserName);

                    SetDefaultStateOfUser(model, profile);

                    SaveNewProfile(model, profile);

                    MembershipUser user = Membership.GetUser(model.UserName, false);


                    AccountMembershipService.SendConfirmationEmail(user);
                    return(RedirectToAction("confirmation"));
                }

                ModelState.AddModelError(string.Empty, ErrorCodeToString(createStatus));
            }

            // If we got this far, something failed, redisplay form
            viewModel.State = StateList;
            return(View(viewModel));
        }
コード例 #2
0
        public ActionResult Create(CreateStudentViewModel studentModel, string selectedUser, string lastName,
                                   string firstMidName, string email)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var student = new Student();

                    //Establish the student data
                    student.UserName       = selectedUser;
                    student.LastName       = lastName;
                    student.FirstMidName   = firstMidName;
                    student.Email          = email;
                    student.EnrollmentDate = DateTime.Now;

                    db.Students.Add(student);                                   //inputs student data into database (is not saved yet)
                    db.SaveChanges();                                           //saves the student to database

                    MembershipUser user = Membership.GetUser(student.UserName); //gets the actual user
                    Roles.AddUserToRole(user.UserName, "Student");              //takes the user and sets role to student

                    // assigns Student data to the profile of the user (so the user is associated with this specified Student data)
                    CustomProfile profile = CustomProfile.GetUserProfile(student.UserName);
                    profile.FilledStudentInfo = "yes";
                    profile.Save();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("",
                                         "Saving failed for some reason.  You may have left some information blank.  Please try again (several times in several different ways if possible (i.e. try using a different computer) - if the problem persists see your system administrator.");
            }

            // This code block is here to allow the page to render in case we get a DataException and have to re-display the screen.
            MembershipUserCollection users = Membership.GetAllUsers();
            var model = new CreateStudentViewModel
            {
                Users = users.OfType <MembershipUser>().Select(x => new SelectListItem
                {
                    Value = x.UserName,
                    Text  = x.UserName,
                })
            };

            return(View(model));
        }
コード例 #3
0
        /// <summary>
        /// The save new profile data.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        private static void SaveNewProfileData(ProfileViewModel model, string state)
        {
            CustomProfile profile = CustomProfile.GetUserProfile();

            profile.LastName            = model.LastName;
            profile.FirstMidName        = model.FirstMidName;
            profile.StreetAddress       = model.StreetAddress;
            profile.City                = model.City;
            profile.State               = state;
            profile.ZipCode             = model.ZipCode;
            profile.Phone               = model.Phone;
            profile.DateOfBirth         = model.DateOfBirth;
            profile.ParishAffiliation   = model.ParishAffiliation;
            profile.MinistryInvolvement = model.MinistryInvolvement;
            profile.Save();
        }
コード例 #4
0
        /// <summary>
        /// The preload profile view model with current users profile data.
        /// </summary>
        /// <returns>
        /// Returns a ProfileViewModel with the current user's profile data
        /// </returns>
        private ProfileViewModel PreloadProfileViewModelWithCurrentUsersProfileData()
        {
            CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name);
            var           model   = new ProfileViewModel
            {
                LastName            = profile.LastName,
                FirstMidName        = profile.FirstMidName,
                StreetAddress       = profile.StreetAddress,
                City                = profile.City,
                StateString         = profile.State,
                ZipCode             = profile.ZipCode,
                Phone               = profile.Phone,
                DateOfBirth         = profile.DateOfBirth,
                ParishAffiliation   = profile.ParishAffiliation,
                MinistryInvolvement = profile.MinistryInvolvement
            };

            return(model);
        }
コード例 #5
0
        public ActionResult Verify(string id)
        {
            if (string.IsNullOrEmpty(id) || (!Regex.IsMatch(id, @"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}")))
            {
                ViewBag.Message = "The user account is not valid.";
                return(View());
            }

            else
            {
                MembershipUser user = Membership.GetUser(new Guid(id));
                if (!user.IsApproved)
                {
                    user.IsApproved = true;
                    Membership.UpdateUser(user);
                    FormsAuthentication.SetAuthCookie(user.UserName, false /* createPersistentCookie */);

                    CustomProfile profile = CustomProfile.GetUserProfile(user.UserName);
                    // check if already existing on the student table - update the table if needed
                    Student isStudent = db.Students.FirstOrDefault(o => o.UserName == User.Identity.Name);
                    if (isStudent != null)
                    {
                        // IF the user already exists in the Student Table . . .
                        UpdateStudentsTableWithUpdatedProfileDataFromRegisterModel(profile, isStudent);
                    }
                    else
                    {
                        // Create student in student table if they have not been there before (everyone needs to be at least a student)
                        CreateStudentTableDataWithNewProfileDataAndAssignStudentRole(profile, user);
                    }

                    return(RedirectToAction("Welcome"));
                }
                else
                {
                    FormsAuthentication.SignOut();
                    TempData["tempMessage"] = "You have already confirmed your email address... please log in.";
                    return(RedirectToAction("LogOn"));
                }
            }
        }