예제 #1
0
        public ActionResult CreateMember(string[] milestone, string[] step, RegisterViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
               // Attempt to register the user
                string error;
                var profile = CustomProfile.GetProfile(Profile.UserName);
                viewModel.OrganizationName = profile.Organization;
                viewModel.OrganizationId = profile.OrganizationId;
                var createStatus = _unitOfWork.Accounts.CreateUser(Mapper.Map<RegisterViewModel, UserModel>(viewModel), out error);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    var user = _unitOfWork.Accounts.GetUserProfileByUserName(viewModel.Email);
                    // Add user permission
                    foreach (var s in step)
                    {
                        _unitOfWork.UserPermissions.Insert(new UserPermission{StepId = Guid.Parse(s), UserId = user.UserId, UserPermissionId = Guid.NewGuid()});
                    }

                    _unitOfWork.Commit();

                    //_emailService.SendEmail(viewModel.Email, "Registration Confirmation",
                    //                        "Hi " + viewModel.FamilyName +
                    //                        ", you are now member of the HTPBP online application.", out error);

                    return RedirectToAction("Team");
                }

                ModelState.AddModelError("", String.IsNullOrEmpty(error)? Helper.ErrorCodeToString(createStatus): error);
            }

            // If we got this far, something failed, redisplay form
            return View(viewModel);
        }
예제 #2
0
        public ActionResult EditUser(RegisterViewModel viewModel)
        {
            // Dont care about password for now
            ModelState.Remove("Password");

            if (ModelState.IsValid)
            {
                string error;
                if (_unitOfWork.Accounts.UpdateUser(Mapper.Map<RegisterViewModel, UserModel>(viewModel), out error))
                {
                    return RedirectToAction("Users");
                }

                ModelState.AddModelError("", error);
            }

            // If we got this far, something failed, redisplay form
            return View(viewModel);
        }
예제 #3
0
        public ActionResult EditMember(string[] milestone, string[] step, RegisterViewModel viewModel)
        {
            // Dont care about password for now
            ModelState.Remove("Password");

            if (ModelState.IsValid)
            {
                string error;

                if (_unitOfWork.Accounts.UpdateUser(Mapper.Map<RegisterViewModel, UserModel>(viewModel), out error))
                {
                    var grantedSteps = _unitOfWork.UserPermissions.Get(u => u.UserId == viewModel.UserId);
                    if (grantedSteps != null)
                    {
                        foreach (var userPermission in grantedSteps)
                        {
                            if (!step.Contains(userPermission.StepId.ToString()))
                                _unitOfWork.UserPermissions.Delete(userPermission);
                        }
                        _unitOfWork.Commit();

                        grantedSteps = _unitOfWork.UserPermissions.Get(u => u.UserId == viewModel.UserId);
                        // Add user permission
                        foreach (var s in step.Where(s => !grantedSteps.Any(g => g.StepId.ToString() == s)))
                        {
                            _unitOfWork.UserPermissions.Insert(new UserPermission{UserId = viewModel.UserId, StepId = Guid.Parse(s), UserPermissionId = Guid.NewGuid()});
                        }

                        _unitOfWork.Commit();
                    }

                    return RedirectToAction("Team");
                }

                ModelState.AddModelError("", error);
            }

            // If we got this far, something failed, redisplay form
            return View(viewModel);
        }
예제 #4
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
               // Attempt to register the user
                string error;

                // By default, only team lead can register because they are the first person from that organization to register
                model.Role = RoleTypes.TeamLeader;

                var createStatus = _unitOfWork.Accounts.CreateUser(Mapper.Map<RegisterViewModel, UserModel>(model), out error);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.Email, createPersistentCookie: false);

                    LoadProfile(model.Email);

                    //Send confirmation email
                    //try {
                    //    WebMail.SmtpServer = "smtp.gmail.com";
                    //    WebMail.SmtpPort = 587;
                    //    WebMail.EnableSsl = true;
                    //    WebMail.UserName = "******";
                    //    WebMail.Password = "******";
                    //    WebMail.From = "*****@*****.**";

                    //    WebMail.Send(model.Email, "Registration Confirmation",
                    //        "Hi " + model.FamilyName + ", you are now member of the HTPBP online application.");

                    //} catch (Exception) {
                    //    //@:<b>Sorry - we couldn't send the email to confirm your RSVP.</b>
                    //}

                    return RedirectToAction("Index", "BikePlan");
                }

                ModelState.AddModelError("", String.IsNullOrEmpty(error)? Helper.ErrorCodeToString(createStatus): error);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #5
0
        public ActionResult JsonRegister(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                string error;

                // By default, only team lead can register because they are the first person from that organization to register
                model.Role = RoleTypes.TeamLeader;
                var createStatus = _unitOfWork.Accounts.CreateUser(Mapper.Map<RegisterViewModel, UserModel>(model), out error);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.Email, createPersistentCookie: false);
                    return Json(new { success = true });
                }
                else
                {
                    //ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    ModelState.AddModelError("", String.IsNullOrEmpty(error) ? Helper.ErrorCodeToString(createStatus) : error);
                }
            }

            // If we got this far, something failed
            return Json(new { errors = GetErrorsFromModelState() });
        }