public void PutAuthCode(UserInfo user, bool again) { if (user == null || Equals(user, Constants.LostUser)) { throw new Exception(Resource.ErrorUserNotFound); } if (!StudioSmsNotificationSettingsHelper.IsVisibleSettings() || !StudioSmsNotificationSettingsHelper.Enable) { throw new MethodAccessException(); } var mobilePhone = SmsSender.GetPhoneValueDigits(user.MobilePhone); if (SmsKeyStorage.ExistsKey(mobilePhone) && !again) { return; } if (!SmsKeyStorage.GenerateKey(mobilePhone, out var key)) { throw new Exception(Resource.SmsTooMuchError); } if (SmsSender.SendSMS(mobilePhone, string.Format(Resource.SmsAuthenticationMessageToUser, key))) { TenantManager.SetTenantQuotaRow(new TenantQuotaRow { Tenant = TenantManager.GetCurrentTenant().TenantId, Path = "/sms", Counter = 1 }, true); } }
public static string SaveMobilePhone(UserInfo user, string mobilePhone) { mobilePhone = SmsSender.GetPhoneValueDigits(mobilePhone); if (user == null || Equals(user, Constants.LostUser)) throw new Exception(Resource.ErrorUserNotFound); if (string.IsNullOrEmpty(mobilePhone)) throw new Exception(Resource.ActivateMobilePhoneEmptyPhoneNumber); if (!string.IsNullOrEmpty(user.MobilePhone) && user.MobilePhoneActivationStatus == MobilePhoneActivationStatus.Activated) throw new Exception(Resource.MobilePhoneMustErase); user.MobilePhone = mobilePhone; user.MobilePhoneActivationStatus = MobilePhoneActivationStatus.NotActivated; if (SecurityContext.IsAuthenticated) { CoreContext.UserManager.SaveUserInfo(user); } else { try { SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); CoreContext.UserManager.SaveUserInfo(user); } finally { SecurityContext.Logout(); } } if (StudioSmsNotificationSettings.Enable) { PutAuthCode(user, false); } return mobilePhone; }