Exemple #1
0
        public ActionResult Create([Bind(Include = "Id, Name, CreatedById, Deleted")] Household household)
        {
            if (ModelState.IsValid)
            {
                string userId = User.Identity.GetUserId();
                household.CreatedById = userId;
                db.Households.Add(household);

                HouseholdUsersHelper helper = new HouseholdUsersHelper(db);
                helper.AddUserToHousehold(household.Id, userId);

                Budget budget = new Budget
                {
                    HouseholdId = household.Id,
                    household   = db.Households.Find(household.Id),
                    Name        = household.Name + "'s Budget",
                    Amount      = 0
                };
                db.Budgets.Add(budget);
                db.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(household));
        }
Exemple #2
0
        public async Task <ActionResult> InviteLogin(InviteLoginViewModel model, int householdId)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                //return RedirectToLocal(returnUrl);
                // Find the user Id and assign it to a variable. User.Identity.GetUserId() will not work because the user is not logged in until this process is completed.
                var user = SignInManager.AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();

                // Call the helper to assign var user to the household.
                var db = new ApplicationDbContext();
                HouseholdUsersHelper helper = new HouseholdUsersHelper(db);
                helper.AddUserToHousehold(householdId, user);
                return(RedirectToAction("Index", "Home"));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
            //return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Exemple #3
0
        public async Task <ActionResult> InviteRegister(InviteRegisterViewModel model, int householdId)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.FirstName + " " + model.LastName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    // Call the helper to assign var user to the household.
                    var db = new ApplicationDbContext();
                    HouseholdUsersHelper helper = new HouseholdUsersHelper(db);
                    helper.AddUserToHousehold(householdId, user.Id);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Create([Bind(Include = "Id,Name,OwnerId")] Household household)
        {
            if (ModelState.IsValid)
            {
                string userId = User.Identity.GetUserId();
                household.OwnerId = userId;
                db.Households.Add(household);

                HouseholdUsersHelper helper = new HouseholdUsersHelper(db);
                helper.AddUserToHousehold(household.Id, userId);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(household));
        }