Example #1
0
        public IActionResult AddBill()
        {
            // For passing simple types.
            //   return RedirectToAction("ManageBills", new { productID = 5, productName = "bob"});
            string                 userId              = User.getUserId();
            RoomieRepo             roomieRepo          = new RoomieRepo(_context);
            Roommate               currentSignedInUser = roomieRepo.GetRoommate(userId);
            IEnumerable <Roommate> roommates           = roomieRepo.GetAllOtherRoommates(userId);
            AddTransactionVM       addTransactionVM    = new AddTransactionVM {
                currentUser = currentSignedInUser, otherRoommates = roommates
            };

            return(View(addTransactionVM));
        }
Example #2
0
        public IActionResult Profile()
        {
            //get current users total balance
            string          userId       = User.getUserId();
            TransactionRepo TransRepo    = new TransactionRepo(_context);
            decimal         totalBalance = TransRepo.GetTotalBalance(userId);
            //get all other roommates
            RoomieRepo             roomieRepo = new RoomieRepo(_context);
            IEnumerable <Roommate> roommates  = roomieRepo
                                                .GetAllOtherRoommates(userId);
            //create and fill VMs
            //get current user name
            Roommate         currentSignedInUser = roomieRepo.GetRoommate(userId);
            RoomieAndBalance currentUser         = new RoomieAndBalance()
            {
                Balance  = totalBalance,
                Roommate = currentSignedInUser
            };
            ProfilePageVM ppvm = new ProfilePageVM()
            {
                CurrentUser          = currentUser,
                RoomiesRelationships = new List <RoomieAndBalance>(),
            };

            //get all other balances with roomies, put them into a VM,
            //which then goes into another bigger VM
            if (roommates != null)
            {
                foreach (var roomie in roommates)
                {
                    decimal relationshipBalance =
                        TransRepo.GetIndividualRelationshipBalance(userId, roomie.RoommateId);
                    RoomieAndBalance roomieAndBalance = new RoomieAndBalance()
                    {
                        Roommate = roomie,
                        Balance  = relationshipBalance
                    };
                    ppvm.RoomiesRelationships.Add(roomieAndBalance);
                }
            }
            return(View(ppvm));
        }
        // ZZZ Change RegisterViewModel to also include 'FirstName', 'LastName'.
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                // *** By now the identity user has just been creaated so 'user' has an id.
                if (result.Succeeded)
                {
                    // *** If identity user created...then add the information needed to roomate.


                    RoomieRepo roomieRepo = new RoomieRepo(_context);
                    // ZZZ Change AddRoomate() to include 'FirstName' and 'LastName' parameters.
                    roomieRepo.AddRoommate(user.Id, model.firstName, model.lastName);

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    // ***********comment out the following line to disable auto sign in upon registration
                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    //_logger.LogInformation("User created a new account with password.");
                    // ***********
                    //return RedirectToAction("JoinCreateHousehold", "Household");

                    ModelState.AddModelError(string.Empty, "please complete your registration using the link that has been sent to your email.");
                    return(View(model));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #4
0
        public IActionResult Relationship(string roommateId)
        {
            RoomieRepo                 roomieRepo          = new RoomieRepo(_context);
            TransactionRepo            transRepo           = new TransactionRepo(_context);
            string                     userId              = User.getUserId();
            Roommate                   currentSignedInUser = roomieRepo.GetRoommate(userId);
            Roommate                   roommate            = roomieRepo.GetRoommate(roommateId);
            List <RoommateTransaction> transactions        = transRepo.GetAllRelationshipTransactions(userId, roommateId).ToList();
            decimal                    relationshipBalance = transRepo.GetIndividualRelationshipBalance(userId, roommateId);

            RelationshipVM relVM = new RelationshipVM()
            {
                CurrentUser = currentSignedInUser,
                Roommate    = roommate,
                OneRoommateTranstactions = transactions,
                RelationshipBalance      = relationshipBalance
            };

            return(View(relVM));
        }
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true

                //2s delay
                System.Threading.Thread.Sleep(2000);
                // Require the user to have a confirmed email before they can log on.
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    if (!await _userManager.IsEmailConfirmedAsync(user))
                    {
                        ModelState.AddModelError(string.Empty,
                                                 "You must have a confirmed email to log in.");
                        return(View(model));
                    }
                }

                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");


                    //we need another condition here which checks if the user has a household or not
                    UserRepo   userRepo   = new UserRepo(_context);
                    var        userId     = userRepo.FindUserId(model.Email);
                    RoomieRepo roomieRepo = new RoomieRepo(_context);
                    var        roommate   = roomieRepo.GetRoommate(userId);
                    if (roommate != null)
                    {
                        if (roommate.HomeId == null)
                        {
                            return(RedirectToAction("JoinCreateHousehold", "Household"));
                        }
                        else
                        {
                            return(RedirectToAction("Profile", "Home"));
                            //return RedirectToLocal(returnUrl);
                        }
                    }
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToAction(nameof(Lockout)));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View(model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View());
        }