Пример #1
0
        /// <summary>
        /// Страница регистрации
        /// </summary>
        /// <returns></returns>
        public ViewResult Register(string id)
        {
            ViewData.Model = GetTimeZones();

            if (!id.IsNullOrEmpty())
            {
                IUsersInvite invite = Utility.Invites.GetInvite(id);
                if (invite != null)
                {
                    ViewData["EMail"] = invite.EMail.Trim();
                }
            }

            return(View());
        }
Пример #2
0
        /// <summary>
        /// Создание пользователя
        /// </summary>
        /// <exception cref="TariffException"></exception>
        public IUser Add(string nick, string password, string login, TimeSpan timeZone, string inviteCode, RegistrationType type)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                string email = login.IsValidEmail() ? login : "";
                IUser  user  = Repository.Users.Add(nick, login, CodePassword(password, login), email, timeZone, type);

                if (!inviteCode.IsNullOrEmpty())
                {
                    // Пользователь был приглашен кем-то через имейл
                    IUsersInvite invite = Repository.Invites.GetInvite(inviteCode);
                    if (invite != null && invite.EMail.ToUpper() == login.ToUpper())
                    {
                        // Инвайт верный, добавляем в организацию
                        IOrganization organization = Utility.Organizations.Get(invite.OrganizationId);
                        Utility.Organizations.AddUser(organization, user, EmployeeRole.Employee, true);
                    }
                    else
                    {
                        // приглашение через ссылку
                        IOrganization organization = Utility.Organizations.GetByInviteCode(inviteCode);
                        if (organization != null)
                        {
                            Utility.Organizations.AddUser(organization, user);
                        }
                    }
                }

                // Первая доска, рабочее время и тп создаются при активации (Activate)
                OnCreate.Invoke(new EventArgs <IUser>(user));

                scope.Complete();

                return(user);
            }
        }
Пример #3
0
        public void OrganizationTest()
        {
            FormCollection        collection = new FormCollection();
            ViewResult            result;
            RedirectToRouteResult redirectToRouteResult;

            OrganizationController organizationController = Base.GetController <OrganizationController>();
            PartialViewResult      partialViewResult      = organizationController.Edit(null);

            List <ITariff> tariffs = partialViewResult.ViewData.Get <List <ITariff> >("tariffs");

            Assert.IsNotNull(tariffs);
            ITariff freeTariff = tariffs.Single(x => x.IsFree());

            Assert.IsNotNull(freeTariff);
            Main.Registation(Email0);

            // создали тестовую организацию
            collection.Clear();
            organizationController = Base.GetController <OrganizationController>();
            collection.Add("Name", "test");
            collection.Add("TariffId", freeTariff.Id.ToString());
            partialViewResult = organizationController.Edit(null, collection);
            IOrganization organization = ((List <EmployeeSettings>)partialViewResult.Model).Single().Organization;

            Assert.IsNotNull(organization);
            int organizationId = organization.Id;

            #region Приглашения

            InviteController inviteController = Base.GetController <InviteController>();

            // через мыло незареганного
            collection.Clear();
            collection.Add("Email", Email3);
            inviteController.NewInvite(organizationId, collection);
            List <IUsersInvite> invites = inviteController.Utility.Invites.GetInvites(organizationId);
            IUsersInvite        invite  = invites.FirstOrDefault(x => x.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(invite);
            Main.Registation(Email3, out result, out redirectToRouteResult, invite.InviteCode);
            ViewResultBase   resultBase = organizationController.EmployeeList(organizationId);
            EmployeeSettings emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(emeil3User);
            collection.Clear();
            collection.Add("delete", "true");
            organizationController.EmployeeEdit(organizationId, emeil3User.User.Id, collection);

            // через мыло зареганного
            inviteController.Dispose();
            inviteController = Base.GetController <InviteController>();
            collection.Clear();
            collection.Add("Email", Email3);
            inviteController.NewInvite(organizationId, collection);
            invites = organizationController.Utility.Invites.GetInvites(organizationId);
            invite  = invites.FirstOrDefault(x => x.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(invite);
            Base.GetController <AdminController>().ClearCache();
            resultBase = organizationController.EmployeeList(organizationId);
            emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(emeil3User);
            var userController = Base.GetController <UserController>();
            userController.Login(null, Email3, Email3, true, null);
            inviteController.AcceptInvite(organizationId);
            emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsTrue(emeil3User.Settings.UserRole == (int)EmployeeRole.Employee);

            // через ссылку незареганного пользователя
            userController.Dispose();
            userController = Base.GetController <UserController>();
            userController.SignOut();
            redirectToRouteResult = (RedirectToRouteResult)userController.Invite(organization.InviteCode);
            Assert.IsTrue(redirectToRouteResult.RouteValues["action"].ToString() == "Register");
            collection.Clear();
            Main.Registation(Email4, out result, out redirectToRouteResult, organization.InviteCode);
            resultBase = inviteController.List();
            var           organizations = (IEnumerable <IOrganization>)resultBase.Model;
            IOrganization first         = organizations.FirstOrDefault();
            Assert.IsTrue(first != null && first.Id == organizationId);
            inviteController.AcceptInvite(first.Id);
            resultBase = organizationController.EmployeeList(organizationId);
            EmployeeSettings emeil4User = ((List <EmployeeSettings>)resultBase.Model).FirstOrDefault(x => x.User.EMail.ToUpper() == Email4.ToUpper());
            Assert.IsNotNull(emeil4User);
            collection.Clear();
            collection.Add("delete", "true");
            organizationController.EmployeeEdit(organizationId, emeil4User.User.Id, collection);

            // через ссылку зареганного пользователя
            userController.Dispose();
            userController        = Base.GetController <UserController>();
            redirectToRouteResult = (RedirectToRouteResult)userController.Invite(organization.InviteCode);
            Assert.IsTrue(redirectToRouteResult.RouteValues["action"].ToString() == "Index");
            collection.Clear();
            inviteController.Dispose();
            inviteController = Base.GetController <InviteController>();
            resultBase       = inviteController.List();
            organizations    = (IEnumerable <IOrganization>)resultBase.Model;
            first            = organizations.FirstOrDefault();
            Assert.IsTrue(first != null && first.Id == organizationId);
            inviteController.AcceptInvite(first.Id);
            resultBase = organizationController.EmployeeList(organizationId);
            emeil4User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email4.ToUpper());
            Assert.IsNotNull(emeil4User);

            #endregion

            #region Удаление

            userController.Dispose();
            userController = Base.GetController <UserController>();
            userController.Login(null, Email3, Email3, true, null);

            BoardsController boardsController = Base.GetController <BoardsController>();
            collection.Clear();
            collection.Add("name", "t1");
            collection.Add("OrganizationId", organizationId.ToString());
            boardsController.Create(collection);

            collection.Clear();
            collection.Add("name", "t2");
            collection.Add("OrganizationId", organizationId.ToString());
            boardsController.Create(collection);

            collection.Clear();
            organizationController = Base.GetController <OrganizationController>();
            organizationController.Delete(organizationId);

            boardsController  = Base.GetController <BoardsController>();
            partialViewResult = boardsController.List(null);
            Assert.IsFalse((partialViewResult.Model as List <IBoard>).Single().OrganizationId.HasValue);            // остается только личная доска

            #endregion
        }
Пример #4
0
        /// <summary>
        /// Код инвайта для нового пользователя
        /// </summary>
        public string CreateNewInvite(int organizationId, string email, int inviterId)
        {
            IUsersInvite invite = Repository.Invites.CreateNewInvite(organizationId, email, inviterId);

            return(invite.InviteCode);
        }