/// <summary>
        /// Checks if changing your plan is possible.
        /// And begins the plan change (upgrade/downgrade) process is requested.
        /// </summary>
        /// <param name="proceed">/if set <c>true</c> then the upgrade process begins (if upgrade/downgrade is possible), otherwise related information only displayed.</param>
        /// <returns></returns>
        public virtual async Task <ActionResult> ChangePlan(bool proceed = false)
        {
            Logger.LogInformation("Getting current user to continue the plan change process.");
            var me = await AppUserCache.GetLoggedOnUser();

            Logger.LogInformation("Found user is {@me}", me);
            Logger.LogInformation("Checking plan change feasibility.");
            var canUpgrage = Plans.CanUpgrade(me.PlanId.Value, me.IsAdmin);

            if (canUpgrage)
            {
                Logger.LogInformation("Plane change is possible.");
                if (proceed)
                {
                    Logger.LogInformation($"Redirecting to {SHOPIFY_ACTIONS.ChoosePlan.ToString()}.");
                    return(RedirectToAction(SHOPIFY_ACTIONS.ChoosePlan.ToString(), Settings.GetShopifyControllerName()));
                }
                else
                {
                    Logger.LogInformation("Rendering change plan view.");
                    Logger.LogInformation($"Change plan view name is {this.Views.MyProfile.ChangePlan}.");
                    return(View(this.Views.MyProfile.ChangePlan));
                }
            }
            else
            {
                Logger.LogWarning("Plane change is not possible already using highest plan.");
                WebMsg.AddTempInfo(this, "You are already using the highest plan.");
                Logger.LogInformation($"Redirecting to {PROFILE_ACTIONS.Index.ToString()}");
                return(RedirectToAction(PROFILE_ACTIONS.Index.ToString(), Settings.GetAppMyProfileControllerName()));
            }
        }
Пример #2
0
        public virtual async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            Logger.LogInformation("Processing login request {@model}", model);
            Logger.LogInformation($"Return url is '{returnUrl}'.");
            ViewData["ReturnUrl"] = returnUrl;
            var viewName = this.Views.Account.Login;

            if (ModelState.IsValid)
            {
                Logger.LogInformation("Valid login model data detected.");
                Logger.LogInformation("Trying to log the user in using signinmanager.PasswordSignInAsync().");
                var result = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, false, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    Logger.LogInformation($"Login was successfull.");
                    Logger.LogInformation("Calling GetLoggedOnUser(true) to refresh user cache.");
                    await AppUserCache.GetLoggedOnUser(true);

                    Logger.LogInformation("Done calling GetLoggedOnUser(true).");
                    var user = await AppUserCache.GetLoggedOnUser();

                    Logger.LogInformation("Calling LogInHappened() event with user {@user}", user);
                    await LogInHappened(user);

                    Logger.LogInformation("Done handling LogInHappened() event.");
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        Logger.LogInformation($"Now redirecting to '{returnUrl}'.");
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        var controller = Settings.GetAppDashboardControllerName();
                        Logger.LogInformation($"Now redirecting to '{controller}/index'.");
                        return(RedirectToAction(DASHBOARD_ACTIONS.Index.ToString(), controller));
                    }
                }
                else
                {
                    Logger.LogWarning("Login was unsuccessful.");
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    Logger.LogInformation("Calling LoginErrorHappened() event.");
                    await LoginErrorHappened(model);

                    Logger.LogInformation("Done handling LoginErrorHappened() event.");
                    return(View(viewName, model));
                }
            }
            Logger.LogWarning("Invalid login model data detected.");
            return(View(viewName, model));
        }
        /// <summary>
        /// Displays the app support page
        /// </summary>
        /// <returns></returns>
        public virtual async Task <IActionResult> Support()
        {
            Logger.LogInformation("Getting current user to generate support view.");
            var currentUser = await AppUserCache.GetLoggedOnUser();

            Logger.LogInformation("Found  current user {@user}.", currentUser);
            Logger.LogInformation($"Support view name is {Views.Dashboard.Support}.");
            return(View(Views.Dashboard.Support, new ContactUsViewModel()
            {
                ShopDomain = currentUser.MyShopifyDomain,
                FromEmail = currentUser.Email,
                PlanName = Plans[currentUser.GetPlanId()]?.Name
            }));
        }
        /// <summary>
        /// Generates a view with basic profile information (such as billing date, trial expiry, plan name etc tec)
        /// </summary>
        /// <returns></returns>
        public virtual async Task <ActionResult> Index()
        {
            Logger.LogInformation("Getting user to display his profile.");
            var me = await AppUserCache.GetLoggedOnUser();

            Logger.LogInformation("Found user is {@user}", me);
            Logger.LogInformation("Getting  plan data.");
            var plan = Plans[me.GetPlanId()];

            Logger.LogInformation("Found plan is {@plan}", plan);
            Logger.LogInformation("Preparing to get recurring charge info.");
            ShopifyRecurringChargeObject recChargeInfo = null;
            bool getFrmApi = (me.IsAdmin && me.BillingIsConnected) ? false : true;

            if (!getFrmApi)
            {
                Logger.LogInformation("User is admin and billing is connected so recurring charge info will NOT be loaded.");
            }
            else
            {
                Logger.LogInformation("Recurring charge info will be read from shopify API.");
            }

            if (getFrmApi)
            {
                try
                {
                    Logger.LogInformation("Requesting recurring charge infor from shopify.");
                    recChargeInfo = await ShopifyAPI.GetRecurringChargeAsync(me.MyShopifyDomain, me.ShopifyAccessToken, me.ShopifyChargeId.Value);

                    Logger.LogInformation("Recieved recurring charge info {@info}.", recChargeInfo);
                }
                catch (Exception ex)
                {
                    recChargeInfo = null;
                    Logger.LogError("Error occurred while reading recurring charge info from shopify.", ex);
                }
            }
            Logger.LogInformation($"My profile index view nmae is {this.Views.MyProfile.Index}.");
            return(View(this.Views.MyProfile.Index, new MyProfileViewModel()
            {
                Me = me,
                MyPlan = plan,
                ChargeData = recChargeInfo
            }));
        }
Пример #5
0
        public virtual async Task <ActionResult> LogOff()
        {
            Logger.LogInformation("Getting the current logged on user object first.");
            var me = await AppUserCache.GetLoggedOnUser();

            Logger.LogInformation("Current user is {@me}.", me);
            Logger.LogInformation("Now calling ClearLoggedOnUser() to clear the cache.");
            AppUserCache.ClearLoggedOnUser();
            Logger.LogInformation("Done calling ClearLoggedOnUser().");
            Logger.LogInformation("Now calling SignOutAsync() to do identity framework signout.");
            await _signInManager.SignOutAsync();

            Logger.LogInformation("Done calling SignOutAsync().");
            Logger.LogInformation("Now calling LogOffHappened() event.");
            await LogOffHappened(me);

            Logger.LogInformation("Done handling LogOffHappened() event.");
            var redirectTo = ShopifyUrlHelper.GetAdminUrl(me.MyShopifyDomain);

            Logger.LogInformation($"Now redirecting to '{redirectTo}'.");
            return(Redirect(ShopifyUrlHelper.GetAdminUrl(me.MyShopifyDomain)));
        }
        public virtual async Task <IActionResult> SendMsg(ContactUsViewModel model)
        {
            Logger.LogInformation("Getting logged on user to send message");
            var user = await AppUserCache.GetLoggedOnUser();

            Logger.LogInformation("Found user is {@user}", user);
            Logger.LogInformation("Sending email.");
            var result = await Emailer.SendSupportEmailAsync(user, model);

            Logger.LogInformation("Email sent was " + (result ? "successful" : "unsuccessful"));
            if (result)
            {
                WebMsg.AddTempSuccessPopUp(this, "Successfully sent the message. Someone will get in touch with you shortly!");
                Logger.LogInformation($"Now redirecting to {DASHBOARD_ACTIONS.Support.ToString()}");
                return(RedirectToAction(DASHBOARD_ACTIONS.Support.ToString(), Settings.GetAppDashboardControllerName()));
            }
            else
            {
                WebMsg.AddTempDangerPopUp(this, "Could not send your meesage to the support department.Try again.");
                return(View(Views.Dashboard.Support, model));
            }
        }