Ejemplo n.º 1
0
        public void ForgotPassword(string email)
        {
            ValidationResult validationResult;

            if (!this.IsValid(new ForgetPasswordViewModel {
                Email = email
            }, out validationResult))
            {
                var error = this.GenerateValidationError(validationResult);
                this.LogError("User.ForgotPassword", error);
                throw new FaultException <Error>(error, error.errorMessage);
            }

            User user = this.UserModel.GetOneByEmail(email).Value;

            UserActivationModel model = this.UserActivationModel;
            UserActivation      userActivation;

            if ((userActivation = model.GetLatestByUser(user.Id).Value) == null)
            {
                userActivation = UserActivation.Build(user);
                model.RegisterSave(userActivation);
            }

            user.Status = UserStatus.Active;
            this.UserModel.RegisterSave(user);
            this.SendActivationLinkEmail(user.FirstName, user.Email, userActivation.ActivationCode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The activate.
        /// </summary>
        /// <param name="activationCode">
        /// The activation code.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string Activate(string activationCode)
        {
            var arr = UserActivationModel.GetOneByCode(activationCode).Value;

            if (arr == null)
            {
                var error = new Error(
                    Errors.CODE_ERRORTYPE_USER_INACTIVE,
                    ErrorsTexts.UserActivationError_Subject,
                    ErrorsTexts.UserActivationError_InvalidActivationCode);
                this.LogError("Rest.Activate", error);
                throw new FaultException <Error>(error, error.errorMessage);
            }

            if (arr.DateExpires < DateTime.Now)
            {
                var error = new Error(
                    Errors.CODE_ERRORTYPE_USER_INACTIVE,
                    ErrorsTexts.UserActivationError_Subject,
                    ErrorsTexts.UserActivationError_InvalidActivationCode);
                this.LogError("Rest.Activate", error);
                throw new FaultException <Error>(error, error.errorMessage);
            }

            var user = arr.User;

            user.Status       = UserStatus.Active;
            user.DateModified = DateTime.Now;
            UserActivationModel model = this.UserActivationModel;
            UserActivation      userActivation;

            if ((userActivation = model.GetLatestByUser(user.Id).Value) == null)
            {
                userActivation = UserActivation.Build(user);
                model.RegisterSave(userActivation);
            }

            UserModel.RegisterSave(user);
            //IoC.Resolve<RealTimeNotificationModel>()
            //    .NotifyClientsAboutChangesInTable<User>(NotificationType.Update, user.Company.Id, user.Id);
            UserActivationModel.RegisterDelete(arr);
            this.SendActivationLinkEmail(user.FirstName, user.Email, userActivation.ActivationCode);
            if (WebOperationContext.Current != null)
            {
                var response = WebOperationContext.Current.OutgoingResponse;
                response.StatusCode = HttpStatusCode.Redirect;
                response.Headers.Add(HttpResponseHeader.Location, (string)this.Settings.BasePath);
            }

            return(null);
        }
Ejemplo n.º 3
0
        protected void SendActivation(User user)
        {
            UserActivationModel model = this.UserActivationModel;
            UserActivation      userActivation;
            List <MailAddress>  bcced = null;

            if ((userActivation = model.GetLatestByUser(user.Id).Value) == null)
            {
                userActivation = UserActivation.Build(user);
                model.RegisterSave(userActivation);
                bcced = GetBCCed(this.Settings.BCCNewEmail as string);
            }

            SendActivationEmail(user.FirstName, user.Email, user.Company, userActivation.ActivationCode, bcced);
        }
Ejemplo n.º 4
0
        public CompanyDTO Save(CompanyDTO dto)
        {
            ValidationResult validationResult;

            if (!this.IsValid(dto, out validationResult))
            {
                var error = this.GenerateValidationError(validationResult);
                this.LogError("Company.Save", error);
                throw new FaultException <Error>(error, error.errorMessage);
            }

            var companyModel        = this.CompanyModel;
            var companyLicenseModel = this.CompanyLicenseModel;
            var instance            = (dto.companyId == 0)
                ? null
                : companyModel.GetOneById(dto.companyId).Value;

            instance = this.Convert(dto, instance);
            var isTransient = instance.IsTransient();

            companyModel.RegisterSave(instance, true);

            if (isTransient && dto.licenseVO != null)
            {
                var user = this.UserModel.GetOneById(dto.licenseVO.createdBy).Value;

                var license = instance.CurrentLicense ?? new CompanyLicense();
                license.Company = instance;
                var licenseIsTransient = license.IsTransient();
                if (licenseIsTransient)
                {
                    license.CreatedBy   = user;
                    license.DateCreated = DateTime.Now;
                }

                license.ModifiedBy   = user;
                license.DateModified = DateTime.Now;
                var expiryDate = dto.licenseVO.expiryDate.ConvertFromUnixTimeStamp();
                license.ExpiryDate = expiryDate < DateTime.Now || expiryDate == DateTime.MinValue ? dto.licenseVO.isTrial ? DateTime.Now.AddDays(30) : DateTime.Now.AddYears(1) : expiryDate;
                var start = dto.licenseVO.startDate.ConvertFromUnixTimeStamp();
                license.DateStart          = start < DateTime.Now || start == SqlDateTime.MinValue.Value ? DateTime.Now : dto.licenseVO.startDate.ConvertFromUnixTimeStamp();
                license.LicenseStatus      = GetLicenseStatus(dto.licenseVO);
                license.TotalLicensesCount = dto.licenseVO.totalLicensesCount;

                license.TotalParticipantsCount = dto.licenseVO.totalParticipantsCount == 0 ? 100 : dto.licenseVO.totalParticipantsCount;
                license.Domain        = dto.licenseVO.domain;
                license.LicenseNumber = Guid.NewGuid().ToString();

                companyLicenseModel.RegisterSave(license);

                if (licenseIsTransient)
                {
                    instance.Licenses.Add(license);
                    companyModel.RegisterSave(instance, false);
                }
            }

            if ((!dto.primaryContactId.HasValue || dto.primaryContactId == default(int)) && dto.primaryContactVO != null)
            {
                bool passwordChanged, emailChanged;
                var  user            = this.ProcessPrimaryContact(dto, instance, out passwordChanged, out emailChanged);
                var  isUserTransient = user.IsTransient();
                user.Company = instance;
                UserModel.RegisterSave(user);
                //IoC.Resolve<RealTimeNotificationModel>().NotifyClientsAboutChangesInTable<User>(NotificationType.Update, user.Company.Id, user.Id);
                instance.PrimaryContact = user;
                companyModel.RegisterSave(instance, true);
                if (isUserTransient)
                {
                    UserActivationModel model = this.UserActivationModel;
                    UserActivation      userActivation;
                    if ((userActivation = model.GetLatestByUser(user.Id).Value) == null)
                    {
                        userActivation = UserActivation.Build(user);
                        model.RegisterSave(userActivation);
                    }

                    var license = instance.Licenses.FirstOrDefault();
                    if (license.Return(x => x.LicenseStatus == CompanyLicenseStatus.Trial, false))
                    {
                        user.Status = UserStatus.Active;
                        UserModel.RegisterSave(user);
                        this.SendTrialEmail(user, userActivation.ActivationCode, instance);
                    }
                    else if (license.Return(x => x.LicenseStatus == CompanyLicenseStatus.Enterprise, false))
                    {
                        user.Status = UserStatus.Active;
                        UserModel.RegisterSave(user);
                        this.SendEnterpriseEmail(user, userActivation.ActivationCode, instance);
                    }
                    else
                    {
                        this.SendActivation(user);
                    }
                }
                else if (passwordChanged || emailChanged)
                {
                    UserActivationModel model = this.UserActivationModel;
                    UserActivation      userActivation;
                    if ((userActivation = model.GetLatestByUser(user.Id).Value) == null)
                    {
                        userActivation = UserActivation.Build(user);
                        model.RegisterSave(userActivation);
                    }

                    this.SendActivationLinkEmail(user.FirstName, user.Email, userActivation.ActivationCode);
                }
            }
            else if (instance.PrimaryContact == null)
            {
                foreach (var companyLicense in instance.Licenses)
                {
                    companyLicenseModel.RegisterDelete(companyLicense);
                }

                companyModel.RegisterDelete(instance);
                companyModel.Flush();
                var errorRes = new Error(Errors.CODE_ERRORTYPE_GENERIC_ERROR, "CompanyWithoutContact", "Company was created without primary contact");
                throw new FaultException <Error>(errorRes, errorRes.errorMessage);
            }

            //IoC.Resolve<RealTimeNotificationModel>().NotifyClientsAboutChangesInTable<Company>(NotificationType.Update, instance.Id, instance.Id);
            var dtoResult = new CompanyDTO(instance);
            var lmses     = isTransient ? LmsCompanyModel.GetAllByCompanyId(instance.Id).ToList() : new List <LmsCompany>();

            var lms = lmses.FirstOrDefault();

            if (lms == null)
            {
                dtoResult.lmsVO = new CompanyLmsDTO();
            }
            else
            {
                LmsProvider lmsProvider = LmsProviderModel.GetById(lms.LmsProviderId);
                dtoResult.lmsVO = new CompanyLmsDTO(lms, lmsProvider, Settings);
            }
            return(dtoResult);
        }