Ejemplo n.º 1
0
        public ActionResult ChangeEmailAddress(AccountChangeEmailModel model)
        {
            var exists = _auth0Helper.SearchAuth0UserByEmail(model.EmailAddress)?.Any(x => x.UserId.StartsWith("auth0") && x.UserId != CurrentUser.UserId);

            if (exists.GetValueOrDefault())
            {
                ModelState.AddModelError("", "E-mail address already exists");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _auth0Helper.ChangeEmail(CurrentUser.UserId, model.EmailAddress);
                    this.AuthenticationManager.SignOut();

                    SnuffoSettings.ShowMessage(TempData, "E-mail Address Updated", "Your E-mail address has been updated. Please login again.", AlertMessageType.Success);
                    return(Redirect($"/{CurrentUser.LanguageCode}/account/login-register/"));
                }
                catch (Exception e)
                {
                    HandleAuth0Exception(e);
                }
            }
            return(CurrentUmbracoPage());
        }
Ejemplo n.º 2
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            User user   = null;
            var  userId = Request.QueryString["u"] ?? CurrentUser.UserId;

            if (!userId.IsNullOrEmpty())
            {
                user = _auth0Helper.GetAuth0User(userId);
            }
            if (user == null)
            {
                ModelState.AddModelError("", "User not found");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _auth0Helper.ChangePassword(userId, model.Password);

                    SnuffoSettings.ShowMessage(TempData, "Reset Password", "Your password has been changed", AlertMessageType.Success);
                    if (model.RedirectToLogin)
                    {
                        return(Redirect($"/{CurrentUser.LanguageCode}/account/login-register/"));
                    }
                }
                catch (Exception e)
                {
                    HandleAuth0Exception(e);
                }
            }
            return(CurrentUmbracoPage());
        }
Ejemplo n.º 3
0
        public ActionResult AccountProfile(AccountProfileModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _auth0Helper.UpdateAuth0User(model);

                    SnuffoSettings.ShowMessage(TempData, "Profile Updated", "Your profile has been updated", AlertMessageType.Success);
                }
                catch (Exception e)
                {
                    HandleAuth0Exception(e);
                }
            }
            return(CurrentUmbracoPage());
        }
Ejemplo n.º 4
0
        public ActionResult DeleteAccount(ContentModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _auth0Helper.DeleteAuth0User(CurrentUser.UserId);
                    this.AuthenticationManager.SignOut();

                    SnuffoSettings.ShowMessage(TempData, "Account Deleted", "Your account has been deleted.", AlertMessageType.Info);
                    return(Redirect($"/{CurrentUser.LanguageCode}/"));
                }
                catch (Exception e)
                {
                    HandleAuth0Exception(e);
                }
            }
            return(CurrentUmbracoPage());
        }
Ejemplo n.º 5
0
        public ActionResult Subscribe(SubscribeModel model)
        {
            if (!model.HoneyPot.IsNullOrEmpty())
            {
                ModelState.AddModelError("", "");
            }
            if (!DateTime.TryParseExact(model.Timestamp, "ffffHHMMtssddyyyymm", null, DateTimeStyles.None, out DateTime commentDate) &&
                commentDate.Day == DateTime.UtcNow.Day &&
                commentDate.Month == DateTime.UtcNow.Month &&
                commentDate.Year == DateTime.UtcNow.Year &&
                commentDate.Hour == DateTime.UtcNow.Hour)
            {
                ModelState.AddModelError("", "");
            }

            if (ModelState.IsValid)
            {
                // Persist to database
                var sub = UvendiaContext.Subscriptions.Single($"{nameof(Subscription.Email)}=@Email", new { model.Email });
                if (sub == null)
                {
                    UvendiaContext.Subscriptions.Insert <long>(
                        new Subscription
                    {
                        Email      = model.Email,
                        IsActive   = true,
                        ModifiedBy = CurrentUser.UserId,
                        CreatedBy  = CurrentUser.UserId
                    });
                }
                else
                {
                    sub.IsActive   = true;
                    sub.ModifiedOn = DateTime.Now;
                    sub.ModifiedBy = CurrentUser.UserId;
                    UvendiaContext.Subscriptions.Save(sub);
                }
                SnuffoSettings.ShowMessage(TempData, "Subscribed", "Your e-mail has been subscribed successfully");
            }

            return(CurrentUmbracoPage());
        }
Ejemplo n.º 6
0
        public ActionResult UpdateAccountAddress(AccountAddressModel model)
        {
            model.ContactAddress.AddressTypeId = AddressType.Default.Id;
            if (model.ShippingAddress != null)
            {
                model.ShippingAddress.AddressTypeId = AddressType.ShipAddress.Id;
            }

            base.SuppressValidation(model.GetPropertyName(x => x.UserId));
            base.SuppressValidation(model.GetPropertyName(x => x.EmailAddress));
            base.SuppressValidation(model.GetPropertyName(x => x.FirstName));
            base.SuppressValidation(model.GetPropertyName(x => x.LastName));
            base.SuppressValidation(model.GetPropertyName(x => x.Phone));

            if (model.HasSameAddress)
            {
                base.SuppressValidation(model.GetPropertyName(x => x.ShippingAddress));
                model.ShippingAddress = null;
                UvendiaContext.Addresses.DeleteByUseryIdAndAddressType(CurrentUser.UserId, AddressType.ShipAddress);
            }

            if (ModelState.IsValid)
            {
                model.ContactAddress.CreatedBy = CurrentUser.UserId;
                var addresses = new List <Address>()
                {
                    model.ContactAddress
                };
                if (model.ShippingAddress != null)
                {
                    model.ShippingAddress.Phone     = model.ContactAddress.Phone;
                    model.ShippingAddress.CreatedBy = CurrentUser.UserId;
                    addresses.Add(model.ShippingAddress);
                }

                UvendiaContext.Addresses.Save(addresses);
                SnuffoSettings.ShowMessage(TempData, "Updated", "Your address updated successfuly.", AlertMessageType.Success);
            }
            return(CurrentUmbracoPage());
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets the alert message to be show for the user.
 /// </summary>
 /// <param name="message">Message to be shown.</param>
 public void ShowAlertMessage(string title, string msg, AlertMessageType messageType = AlertMessageType.Info)
 {
     SnuffoSettings.ShowMessage(TempData, title, msg, messageType);
 }