Exemplo n.º 1
0
        public ActionResult PasswordResetPincodeSendOptions(Guid token, PasswordResetPincodeSendOptionsModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var accessToken = WspContext.Services.Organizations.GetPasswordresetAccessToken(token);

            if (accessToken == null)
            {
                AddMessage(MessageType.Error, Resources.Messages.IncorrectPasswordResetUrl);

                return RedirectToRoute(AccountRouteNames.PasswordResetLogin);
            }

            var user = WspContext.Services.Organizations.GetUserGeneralSettings(accessToken.ItemId, accessToken.AccountId);

            switch (model.Method)
            {
                case PincodeSendMethod.Mobile:
                {
                    var result = WspContext.Services.Organizations.SendResetUserPasswordPincodeSms(accessToken.AccessTokenGuid, user.MobilePhone);

                    if (result.IsSuccess)
                    {
                        AddMessage(MessageType.Success, Resources.Messages.SmsWasSent);
                    }
                    else
                    {
                        AddMessage(MessageType.Error, Resources.Messages.SmsWasNotSent);

                        return RedirectToRoute(AccountRouteNames.PasswordResetPincodeSendOptions);
                    }

                    break;
                }
                case PincodeSendMethod.Email:
                {
                    var result = WspContext.Services.Organizations.SendResetUserPasswordPincodeEmail(accessToken.AccessTokenGuid, user.PrimaryEmailAddress);

                    if (result.IsSuccess)
                    {
                        AddMessage(MessageType.Success, Resources.Messages.PincodeEmailWasSent);
                    }
                    else
                    {
                        AddMessage(MessageType.Error, Resources.Messages.PincodeEmailWasNotSent);

                        return RedirectToRoute(AccountRouteNames.PasswordResetPincodeSendOptions);
                    }

                    break;
                }
                
            }

            return RedirectToRoute(AccountRouteNames.PasswordResetPincode);
        }
Exemplo n.º 2
0
        public ActionResult PasswordResetPincodeSendOptions(Guid token)
        {
            var accessToken = WspContext.Services.Organizations.GetPasswordresetAccessToken(token);

            if (accessToken == null)
            {
                AddMessage(MessageType.Error, Resources.Messages.IncorrectPasswordResetUrl);

                return RedirectToRoute(AccountRouteNames.PasswordResetLogin);
            }

            var user = WspContext.Services.Organizations.GetUserGeneralSettings(accessToken.ItemId, accessToken.AccountId);

            var settings = WspContext.Services.System.GetSystemSettingsActive(EnterpriseServer.SystemSettings.TWILIO_SETTINGS, false);

            bool twilioEnabled = settings != null
                && !string.IsNullOrEmpty(settings.GetValueOrDefault(EnterpriseServer.SystemSettings.TWILIO_ACCOUNTSID_KEY, string.Empty))
                && !string.IsNullOrEmpty(settings.GetValueOrDefault(EnterpriseServer.SystemSettings.TWILIO_AUTHTOKEN_KEY, string.Empty))
                && !string.IsNullOrEmpty(settings.GetValueOrDefault(EnterpriseServer.SystemSettings.TWILIO_PHONEFROM_KEY, string.Empty));

            if (string.IsNullOrEmpty(user.MobilePhone) || twilioEnabled == false)
            {
                var result = WspContext.Services.Organizations.SendResetUserPasswordPincodeEmail(accessToken.AccessTokenGuid, user.PrimaryEmailAddress);

                if (result.IsSuccess)
                {
                    AddMessage(MessageType.Success, Resources.Messages.PincodeEmailWasSent);
                }
                else
                {
                    AddMessage(MessageType.Error, Resources.Messages.PincodeEmailWasNotSent);
                }

                return RedirectToRoute(AccountRouteNames.PasswordResetPincode);
            }

            var model = new PasswordResetPincodeSendOptionsModel();

            model.MobileNumber = user.MobilePhone;
            model.Email = user.PrimaryEmailAddress;

            return View(model);
        }