Exemplo n.º 1
0
        public virtual ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {

                UserRepository repos = new UserRepository();
                MembershipCreateStatus createStatus;

                if (string.IsNullOrEmpty(model.InvitationCode))
                {
                    // register new user

                    // Attempt to register the user
                    User user = repos.CreateFamilyMember(db, model.Name, model.Email, model.Password, out createStatus);// .Create(db, model.Name, model.Email, model.Password, Role.FamilyAdmin,
                                             //out createStatus);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        FormsAuthentication.SetAuthCookie(user.Id.ToString(), model.RememberMe);

                        return RedirectToAction(MVC.User.Edit().WithId(user));//.Family.AddFamilyMember(isKid: true).WithId(user.Family));
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    }
                }
                else
                {
                    // register an unregistered family member
                    User user = db.Users.FirstOrDefault(u => u.InvitationCode == model.InvitationCode);

                    if (user != null && user.IsUnregisteredFamilyMember)
                    {
                        user.Name = model.Name;
                        user.Email = model.Email;
                        createStatus = repos.Register(db, user, model.Password);//.CreateAccountForUser(db, user, model.Email, model.Password);

                        if (createStatus == MembershipCreateStatus.Success)
                        {
                            FormsAuthentication.SetAuthCookie(user.Id.ToString(), model.RememberMe);
                            return RedirectToAction(MVC.Home.Index());
                        }
                        else
                        {
                            ModelState.AddModelError("", ErrorCodeToString(createStatus));
                        }
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 2
0
        //
        // GET: /Account/Register
        public virtual ActionResult Register(string invitationCode)
        {
            RegisterModel model = new RegisterModel();

            if (!string.IsNullOrEmpty(invitationCode))
            {
                UserRepository repos = new UserRepository();
                User user = db.Users.FirstOrDefault(m => m.InvitationCode == invitationCode);
                if (user != null && user.IsUnregisteredFamilyMember)
                {
                    model.Name = user.Name;
                    model.InvitationCode = invitationCode;
                    if (user.HasRealEmail)
                        model.Email = user.Email;
                }
            }

            return View(model);
        }