Beispiel #1
0
 public PortalController(
     IOptionsMonitor <ILog> options,
     MessageService messageService,
     StudioNotifyService studioNotifyService,
     ApiContext apiContext,
     UserManager userManager,
     AuthContext authContext,
     TenantManager tenantManager,
     EmailValidationKeyProvider emailValidationKeyProvider,
     PaymentManager paymentManager,
     CommonLinkUtility commonLinkUtility,
     UrlShortener urlShortener,
     PermissionContext permissionContext
     )
 {
     Log                        = options.CurrentValue;
     MessageService             = messageService;
     StudioNotifyService        = studioNotifyService;
     ApiContext                 = apiContext;
     UserManager                = userManager;
     AuthContext                = authContext;
     TenantManager              = tenantManager;
     EmailValidationKeyProvider = emailValidationKeyProvider;
     PaymentManager             = paymentManager;
     CommonLinkUtility          = commonLinkUtility;
     UrlShortener               = urlShortener;
     PermissionContext          = permissionContext;
 }
Beispiel #2
0
 public QueueWorkerReassign(IHttpContextAccessor httpContextAccessor,
                            MessageService messageService,
                            StudioNotifyService studioNotifyService,
                            QueueWorkerRemove queueWorkerRemove) : base(httpContextAccessor, messageService, studioNotifyService)
 {
     QueueWorkerRemove = queueWorkerRemove;
 }
Beispiel #3
0
 public UserManagerWrapper(
     StudioNotifyService studioNotifyService,
     UserManager userManager,
     SecurityContext securityContext,
     MessageService messageService,
     CustomNamingPeople customNamingPeople,
     TenantUtil tenantUtil,
     CoreBaseSettings coreBaseSettings,
     IPSecurity.IPSecurity iPSecurity,
     DisplayUserSettingsHelper displayUserSettingsHelper,
     SettingsManager settingsManager,
     UserFormatter userFormatter)
 {
     StudioNotifyService       = studioNotifyService;
     UserManager               = userManager;
     SecurityContext           = securityContext;
     MessageService            = messageService;
     CustomNamingPeople        = customNamingPeople;
     TenantUtil                = tenantUtil;
     CoreBaseSettings          = coreBaseSettings;
     IPSecurity                = iPSecurity;
     DisplayUserSettingsHelper = displayUserSettingsHelper;
     SettingsManager           = settingsManager;
     UserFormatter             = userFormatter;
 }
        private void SendErrorNotify(UserManager userManager, StudioNotifyService studioNotifyService, string errorMessage)
        {
            var fromUser = userManager.GetUsers(FromUser);
            var toUser   = userManager.GetUsers(ToUser);

            studioNotifyService.SendMsgReassignsFailed(_currentUserId, fromUser, toUser, errorMessage);
        }
        public string TfaAppNewApp(TfaModel model)
        {
            var isMe = model.Id.Equals(Guid.Empty);
            var user = CoreContext.UserManager.GetUsers(isMe ? SecurityContext.CurrentAccount.ID : model.Id);

            if (!isMe && !SecurityContext.CheckPermissions(Tenant, new UserSecurityProvider(user.ID), Constants.Action_EditUser))
            {
                throw new SecurityAccessDeniedException(Resource.ErrorAccessDenied);
            }

            if (!TfaAppAuthSettings.IsVisibleSettings || !TfaAppUserSettings.EnableForUser(user.ID))
            {
                throw new Exception(Resource.TfaAppNotAvailable);
            }

            if (user.IsVisitor(Tenant) || user.IsOutsider(Tenant))
            {
                throw new NotSupportedException("Not available.");
            }

            TfaAppUserSettings.DisableForUser(user.ID);
            MessageService.Send(MessageAction.UserDisconnectedTfaApp, MessageTarget.Create(user.ID), user.DisplayUserName(false));

            if (isMe)
            {
                return(CommonLinkUtility.GetConfirmationUrl(Tenant.TenantId, user.Email, ConfirmType.TfaActivation));
            }

            StudioNotifyService.SendMsgTfaReset(Tenant.TenantId, user);
            return(string.Empty);
        }
Beispiel #6
0
        public string SendNotificationToChange(string userId)
        {
            var user = CoreContext.UserManager.GetUsers(
                string.IsNullOrEmpty(userId)
                    ? SecurityContext.CurrentAccount.ID
                    : new Guid(userId));

            var canChange =
                user.IsMe() ||
                SecurityContext.CheckPermissions(new UserSecurityProvider(user.ID), ASC.Core.Users.Constants.Action_EditUser);

            if (!canChange)
            {
                throw new SecurityAccessDeniedException(Resource.ErrorAccessDenied);
            }

            user.MobilePhoneActivationStatus = MobilePhoneActivationStatus.NotActivated;
            CoreContext.UserManager.SaveUserInfo(user);

            if (user.IsMe())
            {
                return(StudioNotifyService.GenerateConfirmUrl(user.Email, ConfirmType.PhoneActivation));
            }

            AdminLog.PostAction("UserProfile: erase phone number for user with id {0}", user.ID);
            StudioNotifyService.Instance.SendMsgMobilePhoneChange(user);
            return(string.Empty);
        }
Beispiel #7
0
 public FirstTimeTenantSettings(
     IOptionsMonitor <ILog> options,
     IConfiguration configuration,
     TenantManager tenantManager,
     CoreSettings coreSettings,
     TenantExtra tenantExtra,
     SettingsManager settingsManager,
     UserManager userManager,
     SetupInfo setupInfo,
     SecurityContext securityContext,
     PaymentManager paymentManager,
     MessageService messageService,
     LicenseReader licenseReader,
     StudioNotifyService studioNotifyService,
     TimeZoneConverter timeZoneConverter,
     CoreBaseSettings coreBaseSettings)
 {
     Log                 = options.CurrentValue;
     Configuration       = configuration;
     TenantManager       = tenantManager;
     CoreSettings        = coreSettings;
     TenantExtra         = tenantExtra;
     SettingsManager     = settingsManager;
     UserManager         = userManager;
     SetupInfo           = setupInfo;
     SecurityContext     = securityContext;
     PaymentManager      = paymentManager;
     MessageService      = messageService;
     LicenseReader       = licenseReader;
     StudioNotifyService = studioNotifyService;
     TimeZoneConverter   = timeZoneConverter;
     CoreBaseSettings    = coreBaseSettings;
 }
 public SmtpSettingsController(
     MessageService messageService,
     StudioNotifyService studioNotifyService,
     ApiContext apiContext,
     UserManager userManager,
     SecurityContext securityContext,
     PermissionContext permissionContext,
     TenantManager tenantManager,
     CoreSettings coreSettings,
     CoreConfiguration coreConfiguration,
     CoreBaseSettings coreBaseSettings,
     IConfiguration configuration)
 {
     MessageService      = messageService;
     StudioNotifyService = studioNotifyService;
     ApiContext          = apiContext;
     UserManager         = userManager;
     SecurityContext     = securityContext;
     PermissionContext   = permissionContext;
     TenantManager       = tenantManager;
     CoreSettings        = coreSettings;
     CoreConfiguration   = coreConfiguration;
     CoreBaseSettings    = coreBaseSettings;
     Configuration       = configuration;
 }
Beispiel #9
0
        private string SmsLoginUrl(AccountLinkControl accountLinkControl)
        {
            if (!StudioSmsNotificationSettings.IsVisibleSettings ||
                !StudioSmsNotificationSettings.Enable)
            {
                return(string.Empty);
            }

            UserInfo user;

            if (string.IsNullOrEmpty(HashId))
            {
                user = CoreContext.UserManager.GetUsers(TenantProvider.CurrentTenantID, Login, Hasher.Base64Hash(Password, HashAlg.SHA256));
            }
            else
            {
                Guid userId;
                TryByHashId(accountLinkControl, HashId, out userId);
                user = CoreContext.UserManager.GetUsers(userId);
            }

            if (user == null)
            {
                return(string.Empty);
            }

            var confirmType =
                string.IsNullOrEmpty(user.MobilePhone) ||
                user.MobilePhoneActivationStatus == MobilePhoneActivationStatus.NotActivated
                    ? ConfirmType.PhoneActivation
                    : ConfirmType.PhoneAuth;

            return(StudioNotifyService.GenerateConfirmUrl(user.Email, confirmType));
        }
        private void SendErrorNotify(StudioNotifyService studioNotifyService, string errorMessage, string userName)
        {
            if (!_notify)
            {
                return;
            }

            studioNotifyService.SendMsgRemoveUserDataFailed(_currentUserId, User, userName, errorMessage);
        }
Beispiel #11
0
 public SmtpSettingsController(LogManager logManager,
                               MessageService messageService,
                               StudioNotifyService studioNotifyService,
                               ApiContext apiContext)
 {
     LogManager          = logManager;
     MessageService      = messageService;
     StudioNotifyService = studioNotifyService;
     ApiContext          = apiContext;
 }
        private void SendSuccessNotify(StudioNotifyService studioNotifyService, MessageService messageService, MessageTarget messageTarget, string userName, long docsSpace, long crmSpace, long mailSpace, long talkSpace)
        {
            if (_notify)
            {
                studioNotifyService.SendMsgRemoveUserDataCompleted(_currentUserId, User, userName,
                                                                   docsSpace, crmSpace, mailSpace, talkSpace);
            }

            if (_httpHeaders != null)
            {
                messageService.Send(_httpHeaders, MessageAction.UserDataRemoving, messageTarget.Create(FromUser), new[] { userName });
            }
            else
            {
                messageService.Send(MessageAction.UserDataRemoving, messageTarget.Create(FromUser), userName);
            }
        }
        private void SendSuccessNotify(UserManager userManager, StudioNotifyService studioNotifyService, MessageService messageService, MessageTarget messageTarget, DisplayUserSettingsHelper displayUserSettingsHelper)
        {
            var fromUser = userManager.GetUsers(FromUser);
            var toUser   = userManager.GetUsers(ToUser);

            studioNotifyService.SendMsgReassignsCompleted(_currentUserId, fromUser, toUser);

            var fromUserName = fromUser.DisplayUserName(false, displayUserSettingsHelper);
            var toUserName   = toUser.DisplayUserName(false, displayUserSettingsHelper);

            if (_httpHeaders != null)
            {
                messageService.Send(_httpHeaders, MessageAction.UserDataReassigns, messageTarget.Create(FromUser), new[] { fromUserName, toUserName });
            }
            else
            {
                messageService.Send(MessageAction.UserDataReassigns, messageTarget.Create(FromUser), fromUserName, toUserName);
            }
        }
Beispiel #14
0
        public string SendUserPassword(string email)
        {
            email = (email ?? "").Trim();
            if (!email.TestEmailRegex())
            {
                throw new ArgumentNullException("email", Resource.ErrorNotCorrectEmail);
            }

            if (!IPSecurity.Verify())
            {
                throw new Exception(Resource.ErrorAccessRestricted);
            }

            var userInfo = UserManager.GetUserByEmail(email);

            if (!UserManager.UserExists(userInfo) || string.IsNullOrEmpty(userInfo.Email))
            {
                return(string.Format(Resource.ErrorUserNotFoundByEmail, email));
            }
            if (userInfo.Status == EmployeeStatus.Terminated)
            {
                return(Resource.ErrorDisabledProfile);
            }
            if (userInfo.IsLDAP())
            {
                return(Resource.CouldNotRecoverPasswordForLdapUser);
            }
            if (userInfo.IsSSO())
            {
                return(Resource.CouldNotRecoverPasswordForSsoUser);
            }

            StudioNotifyService.UserPasswordChange(userInfo);

            var displayUserName = userInfo.DisplayUserName(false, DisplayUserSettingsHelper);

            MessageService.Send(MessageAction.UserSentPasswordChangeInstructions, displayUserName);

            return(null);
        }
 public void Deconstruct(out TenantManager tenantManager,
                         out CoreBaseSettings coreBaseSettings,
                         out MessageService messageService,
                         out StudioNotifyService studioNotifyService,
                         out SecurityContext securityContext,
                         out UserManager userManager,
                         out UserPhotoManager userPhotoManager,
                         out DisplayUserSettingsHelper displayUserSettingsHelper,
                         out MessageTarget messageTarget,
                         out IOptionsMonitor <ILog> optionsMonitor)
 {
     tenantManager             = TenantManager;
     coreBaseSettings          = CoreBaseSettings;
     messageService            = MessageService;
     studioNotifyService       = StudioNotifyService;
     securityContext           = SecurityContext;
     userManager               = UserManager;
     userPhotoManager          = UserPhotoManager;
     displayUserSettingsHelper = DisplayUserSettingsHelper;
     messageTarget             = MessageTarget;
     optionsMonitor            = Options;
 }
        public void SendInstallInfo(UserInfo user)
        {
            try
            {
                StudioNotifyService.SendRegData(user);

                var url = Configuration["web:install-url"];
                if (string.IsNullOrEmpty(url))
                {
                    return;
                }

                var tenant = TenantManager.GetCurrentTenant();
                var q      = new MailQuery
                {
                    Email = user.Email,
                    Id    = CoreSettings.GetKey(tenant.TenantId),
                    Alias = tenant.GetTenantDomain(CoreSettings),
                };

                var index = url.IndexOf("?v=", StringComparison.InvariantCultureIgnoreCase);
                if (0 < index)
                {
                    q.Version = url.Substring(index + 3) + Environment.OSVersion;
                    url       = url.Substring(0, index);
                }

                using var webClient = new WebClient();
                var values = new NameValueCollection
                {
                    { "query", Signature.Create(q, "4be71393-0c90-41bf-b641-a8d9523fba5c") }
                };
                webClient.UploadValues(url, values);
            }
            catch (Exception error)
            {
                Log.Error(error);
            }
        }
 public ReassignProgressItemScope(TenantManager tenantManager,
                                  CoreBaseSettings coreBaseSettings,
                                  MessageService messageService,
                                  StudioNotifyService studioNotifyService,
                                  SecurityContext securityContext,
                                  UserManager userManager,
                                  UserPhotoManager userPhotoManager,
                                  DisplayUserSettingsHelper displayUserSettingsHelper,
                                  MessageTarget messageTarget,
                                  IOptionsMonitor <ILog> options)
 {
     TenantManager             = tenantManager;
     CoreBaseSettings          = coreBaseSettings;
     MessageService            = messageService;
     StudioNotifyService       = studioNotifyService;
     SecurityContext           = securityContext;
     UserManager               = userManager;
     UserPhotoManager          = userPhotoManager;
     DisplayUserSettingsHelper = displayUserSettingsHelper;
     MessageTarget             = messageTarget;
     Options = options;
 }
Beispiel #18
0
        public RemoveProgressItem(HttpContext context, MessageService messageService, QueueWorkerRemove queueWorkerRemove, StudioNotifyService studioNotifyService, int tenantId, UserInfo user, Guid currentUserId, bool notify)
        {
            _context            = context;
            MessageService      = messageService;
            StudioNotifyService = studioNotifyService;
            _httpHeaders        = QueueWorker.GetHttpHeaders(context.Request);

            _tenantId      = tenantId;
            User           = user;
            FromUser       = user.ID;
            _userName      = UserFormatter.GetUserName(user, DisplayUserNameFormat.Default);
            _currentUserId = currentUserId;
            _notify        = notify;

            //_docService = Web.Files.Classes.Global.FileStorageService;
            //_mailEraser = new MailGarbageEngine();

            Id          = queueWorkerRemove.GetProgressItemId(tenantId, FromUser);
            Status      = ProgressStatus.Queued;
            Error       = null;
            Percentage  = 0;
            IsCompleted = false;
        }
        public ReassignProgressItem(HttpContext context, MessageService messageService, QueueWorkerReassign queueWorkerReassign, QueueWorkerRemove queueWorkerRemove, StudioNotifyService studioNotifyService, int tenantId, Guid fromUserId, Guid toUserId, Guid currentUserId, bool deleteProfile)
        {
            _context            = context;
            MessageService      = messageService;
            QueueWorkerRemove   = queueWorkerRemove;
            StudioNotifyService = studioNotifyService;
            _httpHeaders        = QueueWorker.GetHttpHeaders(context.Request);

            _tenantId      = tenantId;
            FromUser       = fromUserId;
            ToUser         = toUserId;
            _currentUserId = currentUserId;
            _deleteProfile = deleteProfile;

            //_docService = Web.Files.Classes.Global.FileStorageService;
            //_projectsReassign = new ProjectsReassign();

            Id          = queueWorkerReassign.GetProgressItemId(tenantId, fromUserId);
            Status      = ProgressStatus.Queued;
            Error       = null;
            Percentage  = 0;
            IsCompleted = false;
        }
Beispiel #20
0
 public RemoveProgressItemScope(TenantManager tenantManager,
                                CoreBaseSettings coreBaseSettings,
                                MessageService messageService,
                                StudioNotifyService studioNotifyService,
                                SecurityContext securityContext,
                                UserManager userManager,
                                MessageTarget messageTarget,
                                WebItemManagerSecurity webItemManagerSecurity,
                                StorageFactory storageFactory,
                                UserFormatter userFormatter,
                                IOptionsMonitor <ILog> options)
 {
     TenantManager          = tenantManager;
     CoreBaseSettings       = coreBaseSettings;
     MessageService         = messageService;
     StudioNotifyService    = studioNotifyService;
     SecurityContext        = securityContext;
     UserManager            = userManager;
     MessageTarget          = messageTarget;
     WebItemManagerSecurity = webItemManagerSecurity;
     StorageFactory         = storageFactory;
     UserFormatter          = userFormatter;
     Options = options;
 }
Beispiel #21
0
 public void Deconstruct(out TenantManager tenantManager,
                         out CoreBaseSettings coreBaseSettings,
                         out MessageService messageService,
                         out StudioNotifyService studioNotifyService,
                         out SecurityContext securityContext,
                         out UserManager userManager,
                         out MessageTarget messageTarget,
                         out WebItemManagerSecurity webItemManagerSecurity,
                         out StorageFactory storageFactory,
                         out UserFormatter userFormatter,
                         out IOptionsMonitor <ILog> optionsMonitor)
 {
     tenantManager          = TenantManager;
     coreBaseSettings       = CoreBaseSettings;
     messageService         = MessageService;
     studioNotifyService    = StudioNotifyService;
     securityContext        = SecurityContext;
     userManager            = UserManager;
     messageTarget          = MessageTarget;
     webItemManagerSecurity = WebItemManagerSecurity;
     storageFactory         = StorageFactory;
     userFormatter          = UserFormatter;
     optionsMonitor         = Options;
 }
        private UserInfo GetUserByThirdParty(LoginProfile loginProfile)
        {
            try
            {
                if (!string.IsNullOrEmpty(loginProfile.AuthorizationError))
                {
                    // ignore cancellation
                    if (loginProfile.AuthorizationError != "Canceled at provider")
                    {
                        throw new Exception(loginProfile.AuthorizationError);
                    }
                    return(Constants.LostUser);
                }

                var userInfo = Constants.LostUser;

                Guid userId;
                if (TryGetUserByHash(loginProfile.HashId, out userId))
                {
                    userInfo = UserManager.GetUsers(userId);
                }

                var isNew = false;
                if (CoreBaseSettings.Personal)
                {
                    if (UserManager.UserExists(userInfo.ID) && SetupInfo.IsSecretEmail(userInfo.Email))
                    {
                        try
                        {
                            SecurityContext.AuthenticateMeWithoutCookie(ASC.Core.Configuration.Constants.CoreSystem);
                            UserManager.DeleteUser(userInfo.ID);
                            userInfo = Constants.LostUser;
                        }
                        finally
                        {
                            SecurityContext.Logout();
                        }
                    }

                    if (!UserManager.UserExists(userInfo.ID))
                    {
                        userInfo = JoinByThirdPartyAccount(loginProfile);

                        isNew = true;
                    }
                }

                if (isNew)
                {
                    //TODO:
                    //var spam = HttpContext.Current.Request["spam"];
                    //if (spam != "on")
                    //{
                    //    try
                    //    {
                    //        const string _databaseID = "com";
                    //        using (var db = DbManager.FromHttpContext(_databaseID))
                    //        {
                    //            db.ExecuteNonQuery(new SqlInsert("template_unsubscribe", false)
                    //                                   .InColumnValue("email", userInfo.Email.ToLowerInvariant())
                    //                                   .InColumnValue("reason", "personal")
                    //                );
                    //            Log.Debug(string.Format("Write to template_unsubscribe {0}", userInfo.Email.ToLowerInvariant()));
                    //        }
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        Log.Debug(string.Format("ERROR write to template_unsubscribe {0}, email:{1}", ex.Message, userInfo.Email.ToLowerInvariant()));
                    //    }
                    //}

                    StudioNotifyService.UserHasJoin();
                    UserHelpTourHelper.IsNewUser     = true;
                    PersonalSettingsHelper.IsNewUser = true;
                }

                return(userInfo);
            }
            catch (Exception)
            {
                CookiesManager.ClearCookies(CookiesType.AuthKey);
                CookiesManager.ClearCookies(CookiesType.SocketIO);
                SecurityContext.Logout();
                throw;
            }
        }
        public WizardSettings SaveData(WizardModel wizardModel)
        {
            try
            {
                var(email, passwordHash, lng, timeZone, promocode, amiid, analytics, subscribeFromSite) = wizardModel;

                var tenant   = TenantManager.GetCurrentTenant();
                var settings = SettingsManager.Load <WizardSettings>();
                if (settings.Completed)
                {
                    throw new Exception("Wizard passed.");
                }

                if (!string.IsNullOrEmpty(SetupInfo.AmiMetaUrl) && IncorrectAmiId(amiid))
                {
                    //throw new Exception(Resource.EmailAndPasswordIncorrectAmiId); TODO
                }

                if (tenant.OwnerId == Guid.Empty)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(6)); // wait cache interval
                    tenant = TenantManager.GetTenant(tenant.TenantId);
                    if (tenant.OwnerId == Guid.Empty)
                    {
                        Log.Error(tenant.TenantId + ": owner id is empty.");
                    }
                }

                var currentUser = UserManager.GetUsers(TenantManager.GetCurrentTenant().OwnerId);

                if (!UserManagerWrapper.ValidateEmail(email))
                {
                    throw new Exception(Resource.EmailAndPasswordIncorrectEmail);
                }

                if (string.IsNullOrEmpty(passwordHash))
                {
                    throw new Exception(Resource.ErrorPasswordEmpty);
                }

                SecurityContext.SetUserPasswordHash(currentUser.ID, passwordHash);

                email = email.Trim();
                if (currentUser.Email != email)
                {
                    currentUser.Email            = email;
                    currentUser.ActivationStatus = EmployeeActivationStatus.NotActivated;
                }
                UserManager.SaveUserInfo(currentUser);

                if (!string.IsNullOrWhiteSpace(promocode))
                {
                    try
                    {
                        PaymentManager.ActivateKey(promocode);
                    }
                    catch (Exception err)
                    {
                        Log.Error("Incorrect Promo: " + promocode, err);
                        throw new Exception(Resource.EmailAndPasswordIncorrectPromocode);
                    }
                }

                if (RequestLicense)
                {
                    TariffSettings.SetLicenseAccept(SettingsManager);
                    MessageService.Send(MessageAction.LicenseKeyUploaded);

                    LicenseReader.RefreshLicense();
                }

                if (TenantExtra.Opensource)
                {
                    settings.Analytics = analytics;
                }
                settings.Completed = true;
                SettingsManager.Save(settings);

                TrySetLanguage(tenant, lng);

                tenant.TimeZone = TimeZoneConverter.GetTimeZone(timeZone).Id;

                TenantManager.SaveTenant(tenant);

                StudioNotifyService.SendCongratulations(currentUser);
                StudioNotifyService.SendRegData(currentUser);

                SendInstallInfo(currentUser);

                if (subscribeFromSite && TenantExtra.Opensource && !CoreBaseSettings.CustomMode)
                {
                    SubscribeFromSite(currentUser);
                }

                return(settings);
            }
            catch (BillingNotFoundException)
            {
                throw new Exception(UserControlsCommonResource.LicenseKeyNotFound);
            }
            catch (BillingNotConfiguredException)
            {
                throw new Exception(UserControlsCommonResource.LicenseKeyNotCorrect);
            }
            catch (BillingException)
            {
                throw new Exception(UserControlsCommonResource.LicenseException);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
 public UserManagerWrapper(StudioNotifyService studioNotifyService)
 {
     StudioNotifyService = studioNotifyService;
 }
Beispiel #25
0
        public UserInfo AddUser(UserInfo userInfo, string passwordHash, bool afterInvite = false, bool notify = true, bool isVisitor = false, bool fromInviteLink = false, bool makeUniqueName = true)
        {
            if (userInfo == null)
            {
                throw new ArgumentNullException("userInfo");
            }

            if (!UserFormatter.IsValidUserName(userInfo.FirstName, userInfo.LastName))
            {
                throw new Exception(Resource.ErrorIncorrectUserName);
            }

            if (!CheckUniqueEmail(userInfo.ID, userInfo.Email))
            {
                throw new Exception(CustomNamingPeople.Substitute <Resource>("ErrorEmailAlreadyExists"));
            }
            if (makeUniqueName)
            {
                userInfo.UserName = MakeUniqueName(userInfo);
            }
            if (!userInfo.WorkFromDate.HasValue)
            {
                userInfo.WorkFromDate = TenantUtil.DateTimeNow();
            }

            if (!CoreBaseSettings.Personal && !fromInviteLink)
            {
                userInfo.ActivationStatus = !afterInvite ? EmployeeActivationStatus.Pending : EmployeeActivationStatus.Activated;
            }

            var newUserInfo = UserManager.SaveUserInfo(userInfo);

            SecurityContext.SetUserPasswordHash(newUserInfo.ID, passwordHash);

            if (CoreBaseSettings.Personal)
            {
                StudioNotifyService.SendUserWelcomePersonal(newUserInfo);
                return(newUserInfo);
            }

            if ((newUserInfo.Status & EmployeeStatus.Active) == EmployeeStatus.Active && notify)
            {
                //NOTE: Notify user only if it's active
                if (afterInvite)
                {
                    if (isVisitor)
                    {
                        StudioNotifyService.GuestInfoAddedAfterInvite(newUserInfo);
                    }
                    else
                    {
                        StudioNotifyService.UserInfoAddedAfterInvite(newUserInfo);
                    }

                    if (fromInviteLink)
                    {
                        StudioNotifyService.SendEmailActivationInstructions(newUserInfo, newUserInfo.Email);
                    }
                }
                else
                {
                    //Send user invite
                    if (isVisitor)
                    {
                        StudioNotifyService.GuestInfoActivation(newUserInfo);
                    }
                    else
                    {
                        StudioNotifyService.UserInfoActivation(newUserInfo);
                    }
                }
            }

            if (isVisitor)
            {
                UserManager.AddUserIntoGroup(newUserInfo.ID, Constants.GroupVisitor.ID);
            }

            return(newUserInfo);
        }
Beispiel #26
0
 public QueueWorkerRemove(IHttpContextAccessor httpContextAccessor, MessageService messageService, StudioNotifyService studioNotifyService) : base(httpContextAccessor, messageService, studioNotifyService)
 {
 }
 public AuthenticationController(
     UserManager userManager,
     TenantManager tenantManager,
     SecurityContext securityContext,
     TenantCookieSettingsHelper tenantCookieSettingsHelper,
     CookiesManager cookiesManager,
     PasswordHasher passwordHasher,
     EmailValidationKeyModelHelper emailValidationKeyModelHelper,
     ICache cache,
     SetupInfo setupInfo,
     MessageService messageService,
     ProviderManager providerManager,
     IOptionsSnapshot <AccountLinker> accountLinker,
     CoreBaseSettings coreBaseSettings,
     PersonalSettingsHelper personalSettingsHelper,
     StudioNotifyService studioNotifyService,
     UserManagerWrapper userManagerWrapper,
     UserHelpTourHelper userHelpTourHelper,
     Signature signature,
     InstanceCrypto instanceCrypto,
     DisplayUserSettingsHelper displayUserSettingsHelper,
     MessageTarget messageTarget,
     StudioSmsNotificationSettingsHelper studioSmsNotificationSettingsHelper,
     SettingsManager settingsManager,
     SmsManager smsManager,
     TfaManager tfaManager,
     TimeZoneConverter timeZoneConverter,
     SmsKeyStorage smsKeyStorage,
     CommonLinkUtility commonLinkUtility,
     ApiContext apiContext,
     AuthContext authContext)
 {
     UserManager                   = userManager;
     TenantManager                 = tenantManager;
     SecurityContext               = securityContext;
     TenantCookieSettingsHelper    = tenantCookieSettingsHelper;
     CookiesManager                = cookiesManager;
     PasswordHasher                = passwordHasher;
     EmailValidationKeyModelHelper = emailValidationKeyModelHelper;
     Cache                               = cache;
     SetupInfo                           = setupInfo;
     MessageService                      = messageService;
     ProviderManager                     = providerManager;
     AccountLinker                       = accountLinker;
     CoreBaseSettings                    = coreBaseSettings;
     PersonalSettingsHelper              = personalSettingsHelper;
     StudioNotifyService                 = studioNotifyService;
     UserHelpTourHelper                  = userHelpTourHelper;
     Signature                           = signature;
     InstanceCrypto                      = instanceCrypto;
     DisplayUserSettingsHelper           = displayUserSettingsHelper;
     MessageTarget                       = messageTarget;
     StudioSmsNotificationSettingsHelper = studioSmsNotificationSettingsHelper;
     SettingsManager                     = settingsManager;
     SmsManager                          = smsManager;
     TfaManager                          = tfaManager;
     TimeZoneConverter                   = timeZoneConverter;
     SmsKeyStorage                       = smsKeyStorage;
     CommonLinkUtility                   = commonLinkUtility;
     ApiContext                          = apiContext;
     AuthContext                         = authContext;
     UserManagerWrapper                  = userManagerWrapper;
 }
Beispiel #28
0
        protected void Page_PreInit(object sender, EventArgs e)
        {
            ProcessSecureFilter();

            var wizardSettings = SettingsManager.Instance.LoadSettings <WizardSettings>(TenantProvider.CurrentTenantID);

            if (Request["first"] == "1" && !string.IsNullOrEmpty(Request["id"]) && wizardSettings.Completed)
            {
                // wizardSettings.Completed - open source, Request["first"] - cloud
                wizardSettings.Completed = false;
                SettingsManager.Instance.SaveSettings(wizardSettings, TenantProvider.CurrentTenantID);
            }

            var authCookie = Request["id"] ?? CookiesManager.GetCookies(CookiesType.AuthKey);

            if (!wizardSettings.Completed && !(this is confirm))
            {
                var successAuth = SecurityContext.IsAuthenticated;
                if (!successAuth)
                {
                    successAuth = AuthByCookies(authCookie);
                    if (successAuth)
                    {
                        CookiesManager.SetCookies(CookiesType.AuthKey, authCookie);
                    }
                    else
                    {
                        try
                        {
                            authCookie  = SecurityContext.AuthenticateMe(UserManagerWrapper.AdminID.ToString(), "admin");
                            successAuth = true;
                        }
                        catch (System.Security.Authentication.InvalidCredentialException) { }
                        catch (System.Security.SecurityException) { }
                    }
                }
                if (!successAuth && !(this is Auth))
                {
                    Response.Redirect("~/auth.aspx");
                }
                if (successAuth && !(this is Wizard))
                {
                    Response.Redirect("~/wizard.aspx");
                }
            }
            else if (!SecurityContext.IsAuthenticated && wizardSettings.Completed && !(this is confirm))
            {
                if (this is Auth && Session["refererURL"] == null && !string.IsNullOrEmpty(Request["id"]))
                {
                    if (AuthByCookies(authCookie))
                    {
                        CookiesManager.SetCookies(CookiesType.AuthKey, authCookie);
                        var first = Request["first"] == "1";
                        if (first)
                        {
                            try
                            {
                                var tenant = CoreContext.TenantManager.GetCurrentTenant(false);
                                tenant.Name = Resources.Resource.StudioWelcomeHeader;
                                CoreContext.TenantManager.SaveTenant(tenant);
                            }
                            catch
                            {
                            }
                        }
                        Response.Redirect(VirtualPathUtility.ToAbsolute("~/") + (first ? "?first=1" : ""));
                        return;
                    }
                }

                //for redirect into one of the projects after creating new tenant
                else if (Session["refererURL"] == null && !string.IsNullOrEmpty(Request["id"]))
                {
                    if (AuthByCookies(authCookie))
                    {
                        CookiesManager.SetCookies(CookiesType.AuthKey, authCookie);
                        try
                        {
                            var tenant = CoreContext.TenantManager.GetCurrentTenant(false);
                            tenant.Name = Resources.Resource.StudioWelcomeHeader;
                            CoreContext.TenantManager.SaveTenant(tenant);
                        }
                        catch
                        {
                            Log.Error("Can't set current tenant in MainPage");
                        }
                        var refererURL = GetRefererUrl();
                        if (String.IsNullOrEmpty(refererURL))
                        {
                            Response.Redirect("~/auth.aspx");
                        }
                        else
                        {
                            var currentUser = CoreContext.UserManager.GetUsers(CoreContext.TenantManager.GetCurrentTenant().OwnerId);
                            if (!currentUser.IsOwner())
                            {
                                Response.Redirect("~/auth.aspx");
                            }
                            SecurityContext.AuthenticateMe(CoreContext.Authentication.GetAccountByID(currentUser.ID));

                            FirstTimeTenantSettings.SetDefaultTenantSettings();
                            FirstTimeTenantSettings.SendInstallInfo(currentUser);

                            Response.Redirect(refererURL);
                        }
                    }
                }

                if (!(this is Auth) && !AutoAuthByCookies() && !ExclusivePage())
                {
                    var refererURL = GetRefererUrl();
                    Session["refererURL"] = refererURL;
                    Response.Redirect("~/auth.aspx");
                    return;
                }
            }

            if (TenantStatisticsProvider.IsNotPaid() &&
                !(this is Auth || this is Tariffs || this is confirm))
            {
                Response.Redirect(TenantExtra.GetTariffPageLink(), true);
            }
            else if (SecurityContext.IsAuthenticated &&
                     StudioSmsNotificationSettings.IsVisibleSettings &&
                     StudioSmsNotificationSettings.Enable &&
                     !(this is confirm || this is Auth))
            {
                var user = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);

                if (!CoreContext.UserManager.IsUserInGroup(SecurityContext.CurrentAccount.ID, Constants.GroupAdmin.ID) &&
                    (string.IsNullOrEmpty(user.MobilePhone) ||
                     user.MobilePhoneActivationStatus == MobilePhoneActivationStatus.NotActivated))
                {
                    Response.Redirect(StudioNotifyService.GenerateConfirmUrl(user.Email, ConfirmType.PhoneActivation));
                }
            }

            //check disable and public
            var webitem          = CommonLinkUtility.GetWebItemByUrl(Request.Url.ToString());
            var parentIsDisabled = false;

            if (webitem != null && webitem.IsSubItem())
            {
                var parentItemID = WebItemManager.Instance.GetParentItemID(webitem.ID);
                parentIsDisabled = WebItemManager.Instance[parentItemID].IsDisabled();
            }

            if (webitem != null && (webitem.IsDisabled() || parentIsDisabled) && !ExclusivePage())
            {
                if (webitem.ID == new Guid("{F4D98AFD-D336-4332-8778-3C6945C81EA0}") &&
                    string.Equals(GetType().BaseType.FullName, "ASC.Web.People.Profile"))
                {
                    Response.Redirect("~/my.aspx");
                    return;
                }

                Response.Redirect("~/");
                return;
            }

            if (SecurityContext.IsAuthenticated)
            {
                try
                {
                    StatisticManager.SaveUserVisit(TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID, CommonLinkUtility.GetProductID());
                }
                catch (Exception exc)
                {
                    Log.Error("failed save user visit", exc);
                }
            }

            PersonalHelper.TransferRequest(this);
        }