Пример #1
0
        public static bool SeedDelepmentData(AppDbContext appContext, string userAdminId, string employerUserId)
        {
            var roleAdministrator = new Role(Role.Administrator);

            roleAdministrator.AddUser(userAdminId);
            var roleEmployer = new Role(Role.Employer);

            roleEmployer.AddUser(employerUserId);
            roleEmployer.AddUser(userAdminId);
            appContext.Roles.AddRange(new List <Role> {
                roleAdministrator, roleEmployer
            });

            var offerTypeDevOps    = new OfferType("DevOps");
            var offerTypeQA        = new OfferType("QA");
            var offerTypeDeveloper = new OfferType("Developer");
            var offerTypeManager   = new OfferType("Manager");
            var offerTypePM        = new OfferType("PM");

            appContext.OfferTypes.AddRange(new List <OfferType> {
                offerTypeDevOps,
                offerTypeQA,
                offerTypeDeveloper,
                offerTypeManager,
                offerTypePM
            });

            return(appContext.SaveChanges() >= 0);
        }
Пример #2
0
        public void AddUser(Role role, User user, User currentUser)
        {
            ValidationUtils.Assert(user != currentUser, "Невозможно назначить самому себе роль.");

            role.AddUser(user);

            roleRepository.Save(role);
        }
Пример #3
0
        internal void CreateAdmin()
        {
            User admin = new User {
                UserName = "******", Email = "*****@*****.**", Password = "******"
            };

            Role adminRole = new Role {
                Name = "Administrator"
            };

            adminRole.AddUser(admin);
        }
Пример #4
0
        private void AddRole_Click(Object sender, EventArgs e)
        {
            if (this.userID > -1)
            {
                SiteUser user   = new SiteUser(siteSettings, this.userID);
                int      roleID = int.Parse(allRoles.SelectedItem.Value, CultureInfo.InvariantCulture);
                Role     role   = new Role(roleID);
                Role.AddUser(roleID, userID, role.RoleGuid, user.UserGuid);
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
Пример #5
0
        public void AddUsersToRole(string identity, int roleID, string[] userNames)
        {
            this.VerifyUser(identity);
            User     user       = new User();
            UserInfo userByName = new UserInfo();
            Role     role       = new Role();

            for (int i = 0; i < userNames.Length; i++)
            {
                userByName = user.GetUserByName(userNames[i]);
                role.AddUser(userByName.ID, roleID);
            }
        }
Пример #6
0
        private void AddRole_Click(Object sender, EventArgs e)
        {
            if ((userId > -1) && (CurrentSite != null))
            {
                SiteUser user   = new SiteUser(CurrentSite, userId);
                int      roleID = int.Parse(allRoles.SelectedItem.Value, CultureInfo.InvariantCulture);
                Role     role   = new Role(roleID);
                Role.AddUser(roleID, userId, role.RoleGuid, user.UserGuid);
                user.RolesChanged = true;
                user.Save();

                BindRoles();
            }

            //WebUtils.SetupRedirect(this, Request.RawUrl);
        }
Пример #7
0
        void btnSetUserFromGreyBox_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            if (hdnUserID.Value.Length == 0)
            {
                return;
            }
            try
            {
                int      userId = Convert.ToInt32(hdnUserID.Value);
                SiteUser user   = new SiteUser(siteSettings, userId);

                Role.AddUser(roleID, userId, role.RoleGuid, user.UserGuid);

                WebUtils.SetupRedirect(this, Request.RawUrl);
            }
            catch (FormatException) { }
        }
Пример #8
0
        public Guid Provision(CustomersProvisionModel model)
        {
            var fullName = model.FirstName + " " + model.LastName;

            //create customer in stripe
            StripeCustomer stripeCustomer = StripeFactory.GetStripeService().CreateCustomer(fullName, model.Email);

            // Customer
            Customer customer = new Customer(fullName, model.Domain, model.Company, stripeCustomer.Id)
            {
                PlanCreatedOn = stripeCustomer.Created
            };

            _customerRepository.Add(customer);

            // roles
            var role = new Role(customer, "Administrator", true, UserType.SystemUser);

            _roleRepository.Add(role);

            // users
            var user = new User(customer, model.Email, model.FirstName, model.LastName, model.Password, true);

            _userRepository.Add(user);
            role.AddUser(user);
            customer.UpdateAdminUser(user);

            // security questions
            ReferenceList referenceList = _referenceListRepository.Query().SingleOrDefault(l => l.SystemName == "Security Questions");

            foreach (var securityQuestion in SecurityQuestions.Questions)
            {
                referenceList.AddItem(customer, securityQuestion);
            }

            // user security questions
            user.AddSecurityQuestion("a", "a");
            user.AddSecurityQuestion("b", "b");
            user.AddSecurityQuestion("c", "c");

            _unitOfWork.Commit();

            return(customer.Id);
        }
Пример #9
0
        /// <summary>
        /// required implementation
        /// </summary>
        /// <param name="userNames">a list of usernames</param>
        /// <param name="roleNames">a list of roles</param>
        public override void AddUsersToRoles(string[] userNames, string[] roleNames)
        {
            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

            if ((siteSettings != null) && (userNames != null) && (roleNames != null))
            {
                foreach (String userName in userNames)
                {
                    SiteUser siteUser = new SiteUser(siteSettings, userName);
                    if (siteUser.UserId > -1)
                    {
                        foreach (String roleName in roleNames)
                        {
                            Role role = new Role(siteSettings.SiteId, roleName);
                            if (role.RoleId > -1)
                            {
                                Role.AddUser(role.RoleId, siteUser.UserId, role.RoleGuid, siteUser.UserGuid);
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
        private int Save()
        {
            checkpass();
            if (comfim)
            {
                try
                {
                    var    full = txtFullName.Text.Trim().Split(' ');
                    string Fist = "";
                    string Last = "";
                    for (int i = 0; i < full.Length; i++)
                    {
                        if ((i + 1) < full.Length)
                        {
                            Last += full[i];
                        }
                        else
                        {
                            Fist += full[i];
                        }
                    }
                    SiteUser user = new SiteUser(siteSettings)
                    {
                        Name      = txtFullName.Text.Trim(),
                        FirstName = Fist,
                        LastName  = Last,
                        Email     = txtEmail.Text.Trim(),
                        LoginName = txtFullName.Text.Trim().Replace(' ', '-'),
                        Password  = txtPass2.Text,
                    };
                    user.Save();
                    user = new SiteUser(siteSettings, txtFullName.Text.Replace(' ', '-'));
                    KLAuthor author = null;

                    imageFolderPath = AuthorHepper.MediaFolderPath(siteSettings.SiteId, user.UserId);
                    if (user.Save())
                    {
                        author = new KLAuthor()
                        {
                            ArticleCount = 0,
                            UserID       = user.UserId,
                            IsDel        = false,
                            LevelAuthor  = "Basic",
                            Name         = txtFullName.Text,
                            IsActive     = false,
                        };
                        if (fileImage.UploadedFiles.Count > 0)
                        {
                            imageFolderPath = AuthorHepper.MediaFolderPath(siteSettings.SiteId, user.UserId);


                            AuthorHepper.VerifyAuthorFolders(fileSystem, imageFolderPath);

                            foreach (UploadedFile file in fileImage.UploadedFiles)
                            {
                                string ext = file.GetExtension();
                                if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                                {
                                    ContentMedia media = new ContentMedia();
                                    media.SiteGuid = siteSettings.SiteGuid;
                                    //image.Title = txtImageTitle.Text;
                                    media.DisplayOrder = 0;

                                    string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                                    string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                                    if (media.MediaFile == newFileName)
                                    {
                                        // an existing image delete the old one
                                        fileSystem.DeleteFile(newImagePath);
                                    }
                                    else
                                    {
                                        // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                                        int i = 1;
                                        while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                                        {
                                            newFileName = i.ToInvariantString() + newFileName;
                                            i          += 1;
                                        }
                                    }

                                    newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                                    file.SaveAs(Server.MapPath(newImagePath));

                                    media.MediaFile     = newFileName;
                                    media.ThumbnailFile = newFileName;

                                    author.Avatar = newFileName;
                                    media.Save();
                                    AuthorHepper.ProcessImage(media, fileSystem, imageFolderPath, file.FileName);
                                }
                            }
                        }
                    }
                    author.Save();

                    Role role = new Role(siteSettings.SiteId, "Author");
                    Role.AddUser(role.RoleId, author.UserID, role.RoleGuid, user.UserGuid);

                    if (!sendmail(user.Name, user.Email))
                    {
                        return(-1);
                    }

                    return(author.UserID);
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                }
            }
            return(-1);
        }
Пример #11
0
 private static void SeedData(EiMTDbContext context)
 {
     if (context.Users.FirstOrDefault(x => x.Email == "*****@*****.**") == null)
     {
         var admin    = new Role("Admin");
         var menager  = new Role("Menager");
         var employee = new Role("Employee");
         context.Roles.Add(admin);
         context.Roles.Add(menager);
         context.Roles.Add(employee);
         List <User> admins = new List <User>
         {
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password")
         };
         List <User> menagers = new List <User>()
         {
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
         };
         List <User> regular = new List <User>()
         {
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
         };
         List <Sector> ssectors = new List <Sector>();
         var           sectors  = new List <string>
         {
             "IT", "Marketing", "Menagment", "Business"
         };
         int menId = 0;
         foreach (var user in admins)
         {
             admin.AddUser(user);
             user.IsEmailConfirmed = true;
         }
         foreach (var user in menagers)
         {
             menager.AddUser(user);
             var s = new Sector(sectors[menId], user);
             context.Sectors.Add(s);
             ssectors.Add(s);
             menId++;
             user.IsEmailConfirmed = true;
         }
         menId = menagers.Count - 1;
         foreach (var user in regular)
         {
             menId = menId % menagers.Count;
             employee.AddUser(user);
             user.IsEmailConfirmed = true;
             ssectors[menId].Employees.Add(user);
             menId++;
         }
         context.Users.AddRange(admins);
         context.Users.AddRange(menagers);
         context.Users.AddRange(regular);
         context.SaveChanges();
         menId = 0;
         foreach (var sec in ssectors)
         {
             sec.Employees.Add(menagers[menId]);
             menId++;
         }
         context.SaveChanges();
     }
 }
Пример #12
0
        /// <summary>
        /// Sign up a user to a plan
        /// </summary>
        /// <param name="request">Sign up request</param>
        public PlanSignUpResponse PlanSignUp(PlanSignUpRequest request)
        {
            try
            {
                // Begin transaction
                _unitOfWork.Begin("PlanSignUp");

                var response = new PlanSignUpResponse();
                var dbPlan   = _planRepository.Query().FirstOrDefault(p => p.PlanCode.ToLower() == request.PlanName.ToLower());
                if (dbPlan == null)
                {
                    response.HasError  = true;
                    response.ErrorCode = ErrorCode.PlanNotFound;
                    return(response);
                }

                if (request.SignUpModel.Domain != null)
                {
                    if (
                        _customerRepository.Query().Any(
                            t => t.Hostname.ToLower() == request.SignUpModel.Domain.ToLower()))
                    {
                        response.ErrorCode = ErrorCode.DomainAlreadyExists;
                        response.HasError  = true;
                        return(response);
                    }
                }

                // Customer
                var customer = new Customer(request.SignUpModel.FullName, request.SignUpModel.Domain,
                                            request.SignUpModel.Company);
                _customerRepository.Add(customer);

                // Role
                var role = new Role(customer, "Administrator", true, UserType.SystemUser);
                _roleRepository.Add(role);

                // Setup the User
                var user = new User(customer, request.SignUpModel.Email, request.SignUpModel.FirstName,
                                    request.SignUpModel.LastName, request.SignUpModel.Password);
                _userRepository.Add(user);

                role.AddUser(user);

                customer.UpdateAdminUser(user);

                // Security questions
                var referenceList = _referenceListRepository.Query().FirstOrDefault(l => l.SystemName == "Security Questions");
                if (referenceList == null)
                {
                    throw new NullReferenceException("Security questions reference list is null");
                }

                foreach (var securityQuestion in SecurityQuestions.Questions)
                {
                    referenceList.AddItem(customer, securityQuestion);
                }

                // User security questions
                user.AddSecurityQuestion("a", "a");
                user.AddSecurityQuestion("b", "b");
                user.AddSecurityQuestion("c", "c");

                // Create customer in stripe
                var stripeCustomer = StripeFactory.GetStripeService().CreateCustomer(request.SignUpModel.FullName,
                                                                                     request.SignUpModel.Email);
                customer.PaymentCustomerId = stripeCustomer.Id;

                // Associate plan
                var result = StripeFactory.GetStripeService().AssignCustomerPlan(customer.PaymentCustomerId,
                                                                                 dbPlan.PlanCode,
                                                                                 request.SignUpModel.CardNumber,
                                                                                 request.SignUpModel.SecurityCode,
                                                                                 int.Parse(
                                                                                     request.SignUpModel.Expiration.
                                                                                     Substring(0, 2)),
                                                                                 int.Parse(
                                                                                     request.SignUpModel.Expiration.
                                                                                     Substring(3, 2)));

                if (result != "active")
                {
                    throw new Exception($"Incorrect assigning plan result for Customer {customer.FullName}");
                }

                customer.UpdatePlan(dbPlan);
                _customerRepository.Update(customer);

                // End transaction
                _unitOfWork.End();

                // Send email
                var emailTemplate =
                    _emailTemplatesRepository.GetTemplateByName(
                        EmailTemplateCode.SignUpGreeting.ToDescriptionString());

                emailTemplate = EmailTemplateFactory.ParseTemplate(emailTemplate, customer);
                var mailMessage = MailMessageMapper.ConvertToMailMessage(emailTemplate);
                var emailResult = EmailServiceFactory.GetEmailService().SendMail(mailMessage);

                if (!emailResult)
                {
                    throw new Exception("Problem sending email");
                }

                return(response);
            }
            catch (StripeException ex)
            {
                LoggingFactory.GetLogger().LogError(ex);
                throw new Exception("Assigning customer plan error", ex);
            }
            catch (Exception ex)
            {
                LoggingFactory.GetLogger().LogError(ex);
                throw;
            }
        }
    /// <summary>
    /// Add user to role.
    /// </summary>
    /// <param name="person">User.</param>
    /// <param name="role">Role.</param>
    private void addUserRole(Person person, Role role)
    {
        if (role.RoleID != RolesEnum.PublicUser.ToString())
        {
            if (!person.IsInRole(role.RoleID))
                role.AddUser(person.ID.Value);
            return;
        }

        if (String.IsNullOrEmpty(tbPassword.Text))
            return;

        IList<PersonAttribute> attributes =
            PersonAttributes.GetPersonAttributesByKeyword(person.ID.Value
                                                          , PersonAttributeTypes.PublicPassword.ToString());
        if (attributes == null || attributes.Count == 0)
            person.AddStandardStringAttribute(PersonAttributeTypes.PublicPassword,
                                                                     tbPassword.Text);
        else
        {
            attributes[0].StringField = tbPassword.Text;
            attributes[0].Save();
        }
        role.AddUser(person.ID.Value);
    }
Пример #14
0
 public void AddUser(int userID, int roleID)
 {
     bll.AddUser(userID, roleID);
 }