예제 #1
0
        public User AddFamilyMember(KidStepsContext context, Family family, PersonName name, string email, bool isKid)
        {
            UserRepository userRepos =
                new UserRepository();
            User newUser = userRepos.CreateFamilyMember(context, name, email);
            newUser.Family = family;

            if (isKid)
            {
                newUser.RoleFlags |= Role.Kid;
                family.HasKids = true;
            }

            context.SaveChanges();

            return newUser;
        }
예제 #2
0
        public Family Create(
            KidStepsContext context,
            User admin)
        {
            Family family = new Family();
            context.Families.Add(family);
            family.Name = admin.Name.Last;
            family.Admin = admin;
            admin.Family = family;

            // add public viewer
            UserRepository userRepos = new UserRepository();
            User publicViewer = userRepos.CreatePublicViewer(context);
            publicViewer.Family = family;

            context.SaveChanges();

            return family;
        }
예제 #3
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);
        }
예제 #4
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);
        }