Exemple #1
0
 public Administrator(string lastName, string firstName, string login, string password, DateTime currentDate)
 {
     LastName     = lastName;
     FirstName    = firstName;
     Login        = login;
     PasswordHash = CryptographyUtils.ComputeHash(password);
     CreationDate = currentDate;
 }
Exemple #2
0
        public virtual void ChangePassword(string currentPassword, string newPassword)
        {
            var currentPasswordHash = CryptographyUtils.ComputeHash(currentPassword);

            ValidationUtils.Assert(PasswordHash == currentPasswordHash, "Указан неверный пароль.");

            PasswordHash = CryptographyUtils.ComputeHash(newPassword);
        }
        /// <summary>
        /// Аутентификация администратора системы на основании логина и пароля
        /// </summary>
        /// <param name="login">Логин администратора</param>
        /// <param name="password">Пароль администратора</param>
        public Administrator TryLogin(string login, string password)
        {
            // поиск администратора по логину
            var administrator = administratorRepository.GetByLogin(login);

            ValidationUtils.NotNull(administrator, "Неверный логин или пароль.");

            // вычисление хэша пароля
            string passwordHash = CryptographyUtils.ComputeHash(password);

            // если пароль не совпадает, то выдаем такое же сообщение (чтобы не выдать наличие или отсутствие администратора по логину)
            ValidationUtils.Assert(administrator.PasswordHash == passwordHash, "Неверный логин или пароль.");

            return(administrator);
        }
Exemple #4
0
        public User(Employee employee, string displayName, string login, string password, Team team, User createdBy) : this()
        {
            Employee      = employee;
            employee.User = this;

            DisplayName = displayName;

            Login        = login;
            PasswordHash = CryptographyUtils.ComputeHash(password);

            CreatedBy = createdBy;

            DisplayNameTemplate = "LF";

            AddTeam(team);
        }
Exemple #5
0
        public User TryLogin(string login, string password)
        {
            // вычисление хэша пароля
            string passwordHash = CryptographyUtils.ComputeHash(password);

            // поиск пользователя по логину
            var user = userRepository.Query<User>().Where(x => x.Login == login).FirstOrDefault<User>();
            ValidationUtils.NotNull(user, "Неверный логин или пароль.");

            // если пароль не совпадает, то выдаем такое же сообщение (чтобы не выдать наличие или отсутствие пользователя по логину)
            ValidationUtils.Assert(user.PasswordHash == passwordHash, "Неверный логин или пароль.");

            // если пользователь аутентифицирован, но заблокирован
            ValidationUtils.Assert(user.BlockingDate == null, String.Format("Пользователь {0} заблокирован и не имеет доступа к системе.", user.DisplayName));

            return user;
        }
Exemple #6
0
 public virtual void ResetPassword(string newPassword)
 {
     PasswordHash = CryptographyUtils.ComputeHash(newPassword);
 }
        public ActionResult RegisterEasy(FreeClientRegistrationViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var firstError = ModelState.Values.Where(x => x.Errors.Any()).FirstOrDefault();

                    ValidationUtils.IsNull(firstError, firstError.Errors.FirstOrDefault().ErrorMessage);
                }

                var currentDateTime = DateTimeUtils.GetCurrentDateTime();

                using (IUnitOfWork uow = unitOfWorkFactory.Create(IsolationLevel.Serializable))
                {
                    var rate = rateRepository.GetById(5 /* тариф «Тестовый период»*/);
                    ValidationUtils.NotNull(rate, "Тариф не найден.");

                    var client = new Client(currentDateTime);
                    client.AdminEmail   = model.AdminEmail;
                    client.DBServerName = AppSettings.ClientDBServerName;
                    client.Phone        = model.Phone;
                    client.PromoCode    = model.PromoCode;

                    clientRepository.Save(client);

                    client.DBName = "bizpulse_" + client.Number.ToString();

                    var admin = new ClientUser(model.AdminLastName, model.AdminFirstName, model.AdminLogin, CryptographyUtils.ComputeHash(model.AdminPassword),
                                               true, currentDateTime);

                    client.AddUser(admin);

                    // добавление первого набора услуг и первой услуги в набор
                    client.CreateInitialStandardServiceSet(client, rate, currentDateTime);

                    uow.Commit();

                    // создание БД клиента
                    CreateClientDatabase(client, currentDateTime);

                    // отправка письма о регистрации
                    SendRegistrationLetter(client, admin, model.AdminPassword);

                    return(Content(client.Id.ToString()));
                }
            }
            catch (Exception ex)
            {
                return(Content(ProcessException(ex)));
            }
        }
        public ActionResult RegisterPhysicalPerson(PhysicalPersonRegistrationViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var firstError = ModelState.Values.Where(x => x.Errors.Any()).FirstOrDefault();

                    ValidationUtils.IsNull(firstError, firstError.Errors.FirstOrDefault().ErrorMessage);
                }

                var currentDateTime = DateTimeUtils.GetCurrentDateTime();

                var registrationAddressCityId = ValidationUtils.TryGetShort(model.RegistrationAddressCityId, "Неверное значение входного параметра.");
                var postalAddressCityId       = ValidationUtils.TryGetShort(model.PostalAddressCityId, "Неверное значение входного параметра.");
                var rateId = ValidationUtils.TryGetShort(model.RateId, "Неверное значение входного параметра.");

                var extraUserCount                = ValidationUtils.TryGetShort(model.ExtraUserCount);
                var extraTeamCount                = ValidationUtils.TryGetShort(model.ExtraTeamCount);
                var extraStorageCount             = ValidationUtils.TryGetShort(model.ExtraStorageCount);
                var extraAccountOrganizationCount = ValidationUtils.TryGetShort(model.ExtraAccountOrganizationCount);
                var extraGigabyteCount            = ValidationUtils.TryGetShort(model.ExtraGigabyteCount);

                using (IUnitOfWork uow = unitOfWorkFactory.Create(IsolationLevel.Serializable))
                {
                    var registrationAddressCity = cityRepository.GetById(registrationAddressCityId);
                    ValidationUtils.NotNull(registrationAddressCity, "Город не найден.");

                    var registrationAddress = new Address(registrationAddressCity, model.RegistrationAddressPostalIndex, model.RegistrationAddressLocalAddress);

                    var rate = rateRepository.GetById(rateId);
                    ValidationUtils.NotNull(rate, "Тариф не найден.");

                    Address postalAddress = null;

                    if (model.PostalAddressEqualsRegistration)
                    {
                        postalAddress = new Address(registrationAddress.City, registrationAddress.PostalIndex, registrationAddress.LocalAddress);
                    }
                    else
                    {
                        var postalAddressCity = cityRepository.GetById(postalAddressCityId);
                        ValidationUtils.NotNull(postalAddressCityId, "Город не найден.");

                        postalAddress = new Address(postalAddressCity, model.PostalAddressPostalIndex, model.PostalAddressLocalAddress);
                    }

                    var client = new PhysicalPerson(model.LastName, model.FirstName, model.Patronymic, model.INNIP, registrationAddress, postalAddress, currentDateTime);

                    client.AdminEmail   = model.AdminEmail;
                    client.DBServerName = AppSettings.ClientDBServerName;
                    client.OGRNIP       = model.OGRNIP;
                    client.Phone        = model.Phone;
                    client.PromoCode    = model.PromoCode;

                    clientRepository.Save(client);

                    client.DBName = "bizpulse_" + client.Number.ToString();

                    var admin = new ClientUser(model.AdminLastName, model.AdminFirstName, model.AdminLogin, CryptographyUtils.ComputeHash(model.AdminPassword),
                                               true, currentDateTime);
                    admin.Patronymic = model.AdminPatronymic;

                    client.AddUser(admin);

                    // добавление первого набора услуг и первой услуги в набор
                    client.CreateInitialServiceSet(client, rate, extraUserCount, extraTeamCount, extraStorageCount,
                                                   extraAccountOrganizationCount, extraGigabyteCount, currentDateTime);

                    uow.Commit();

                    // создание БД клиента
                    CreateClientDatabase(client, currentDateTime);

                    // отправка письма о регистрации
                    SendRegistrationLetter(client, admin, model.AdminPassword);

                    return(Content(client.Id.ToString()));
                }
            }
            catch (Exception ex)
            {
                return(Content(ProcessException(ex)));
            }
        }