Exemplo n.º 1
0
        public async Task <ActionResult> ForgotPassword(FindAccount forgotPassword)
        {
            string message = "";
            bool   status  = false;

            var account = await context.Users.SingleOrDefaultAsync(a => a.Email == forgotPassword.UsernameOrEmail || a.Username == forgotPassword.UsernameOrEmail);

            if (account != null)
            {
                #region Generate Reset Password Code
                account.ResetPasswordCode = Guid.NewGuid();
                #endregion

                #region Send Verification Email
                SendEmail(account.Email, account.ResetPasswordCode.ToString(), account.FirstName, "", "", "ResetPassword");
                #endregion

                context.Configuration.ValidateOnSaveEnabled = false; // To avoid Confirm Password does not match issue on save changes
                await context.SaveChangesAsync();

                status  = true;
                message = $"Reset Password link has been sent to your email address:";
                ViewData.Add("Email", account.Email);
            }
            else
            {
                message = "Account not found";
            }
            ViewBag.Message = message;
            ViewBag.Status  = status;
            return(View());
        }
        public async Task <ActionResult> FindDriver(FindAccount findDriver)
        {
            string message = "";

            var account = await context.Users.SingleOrDefaultAsync(a => a.Email == findDriver.UsernameOrEmail || a.Username == findDriver.UsernameOrEmail);

            if (account != null && account.UserType.Equals("Driver"))
            {
                // Driver found
                var location = await context.DriverLocations.FindAsync(account.Username);

                if (location != null)
                {
                    // Location found, redirect to details
                    return(RedirectToAction("Details", new { Id = account.Username }));
                }
                else
                {
                    // Location not found, redirect to create
                    return(RedirectToAction("Create", new { Id = account.Username }));
                }
            }
            else
            {
                // Driver not found
                message = "Driver not found";
            }

            ViewBag.Message = message;
            return(View());
        }
        public async Task FindAccountAsync(string queryStringValue)
        {
            var testValues = queryStringValue.Split(",");
            var query      = new Dictionary <String, StringValues>();

            query.TryAdd(testValues[0], testValues[1]);
            string body    = "";
            var    request = TestFactory.CreateHttpRequest(query, body);

            var         option      = Options.Create(_appSettings);
            FindAccount findAccount = new FindAccount(option);

            var response = await findAccount.Run(request, logger);

            try
            {
                var result = (OkObjectResult)response;
                Assert.Equal(200, result.StatusCode);
            }
            catch (InvalidCastException)
            {
                //var result = (ResponseContentModel)((BadRequestObjectResult)response).Value;
                //Assert.Equal(409, result.status);
            }
        }