コード例 #1
0
        public TestorTreeItem[] AddGroups(int parentId, TestorTreeItem[] groups)
        {
            Debug.Assert(parentId >= 0);

            Provider.TestRoles(TestorUserRole.Administrator);

            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                foreach (TestorTreeItem group in groups)
                {
                    int    i         = 1;
                    string groupCode = String.Empty;
                    while (i > 0)
                    {
                        groupCode = Guid.NewGuid().ToString().Substring(0, 8);
                        i         = dataContext.GetGroupIdByCode(groupCode);
                    }
                    group.GroupCode = groupCode;
                    group.ItemId    = dataContext.AddGroupTreeItem(GetId(parentId), group.ItemName, groupCode);
                    AddGroups(group.ItemId, group.SubItems);
                }
                return(groups);
            }
        }
コード例 #2
0
ファイル: Register.aspx.cs プロジェクト: clgray/Locator
        protected void Btn_Reg_Click(object sender, EventArgs e)
        {
            int groupId = 0;

            TextBoxPassword.Attributes["Value"]       = TextBoxPassword.Text;
            TextBoxSecondPassword.Attributes["Value"] = TextBoxSecondPassword.Text;
            if (LocalUser.IsIntranet)
            {
                if (ViewState["SelectedNode"] != null)
                {
                    int.TryParse((string)ViewState["SelectedNode"], out groupId);
                }

                if (groupId == 0 || ViewState["SelectedNode"] == null)
                {
                    aspErrorMessage.Visible = true;
                    aspErrorMessage.Text    = "Выберите группу (Факультет -> Кафедра -> Группа).";
                    return;
                }
            }
            if (TextBoxCaptcha.Text.ToLower() != this.Session["CaptchaImageText"].ToString().ToLower())
            {
                aspErrorMessage.Visible          = true;
                aspErrorMessage.Text             = "Введён неправильный секретный код";
                TextBoxCaptcha.Text              = String.Empty;
                this.Session["CaptchaImageText"] = GenerateRandomCode();
                return;
            }
            else
            {
                TextBoxCaptcha.Text = String.Empty;
                this.Session["CaptchaImageText"] = GenerateRandomCode();
                aspErrorMessage.Visible          = false;
            }
            if (TextBoxLogin.Text.Trim().Contains(' ') || TextBoxPassword.Text.Contains(' '))
            {
                aspErrorMessage.Visible = true;
                aspErrorMessage.Text    = "Логин и пароль не могут содержать пробелы";
                return;
            }
            if (TextBoxPassword.Text != TextBoxSecondPassword.Text)
            {
                aspErrorMessage.Visible = true;
                aspErrorMessage.Text    = "Пароли не совпадают";
                return;
            }
            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                string eMail = TextBoxEmail.Text.Trim().ToLower();
                if (!String.IsNullOrEmpty(eMail) && dataContext.Users.Where(c => c.Email == eMail).Count() > 0)
                {
                    aspErrorMessage.Visible = true;
                    aspErrorMessage.Text    = "Данный e-mail уже используется";
                    return;
                }
                if (!LocalUser.IsIntranet)
                {
                    if (TextBoxGroup.Text.Trim() != String.Empty)
                    {
                        groupId = dataContext.GetGroupIdByCode(TextBoxGroup.Text.Trim());
                        if (groupId == 0)
                        {
                            aspErrorMessage.Visible = true;
                            aspErrorMessage.Text    = "Неверный код группы";
                            return;
                        }
                    }
                }
                TestorTreeItem[] groups = new TestorTreeItem[] { };
                if (groupId != 0)
                {
                    TestorTreeItem group = new TestorTreeItem(groupId, 0, String.Empty, TestorItemType.Group, new TestorTreeItem[] { });
                    groups = new TestorTreeItem[] { group };
                }
                string password = TextBoxPassword.Text.Trim();
                if (String.IsNullOrEmpty(password))
                {
                    password = "******";
                }
                TestorCoreUser user = new TestorCoreUser()
                {
                    LastName   = TextBoxLastName.Text.Trim(),
                    FirstName  = TextBoxName.Text.Trim(),
                    SecondName = TextBoxSecondName.Text.Trim(),
                    Password   = password,
                    Sex        = DropDownListGender.SelectedIndex == 0 ? true : false,
                    UserGroups = groups,
                    UserRole   = TestorUserRole.Student,
                    Status     = LocalUser.IsIntranet ? TestorUserStatus.LocalNetUser : TestorUserStatus.NotActivated,
                    StudNumber = TextBoxStudNumber.Text.Trim()
                };
                if (LocalUser.IsIntranet)
                {
                    user.Login       = Guid.NewGuid().ToString();
                    user.IsLocalUser = true;
                    user.Email       = String.Format("{0}@{1}.testor.ru", user.Login, Guid.NewGuid().ToString());
                }
                else
                {
                    user.Login = TextBoxLogin.Text.Trim();
                    user.Email = TextBoxEmail.Text.Trim().ToLower();
                }
                try
                {
                    TestorCoreUser coreUser = LocalUser.UserManagement.CreateUser(user);
                    ActivationKey  key      = new ActivationKey();
                    key.ActivationKey1 = Guid.NewGuid().ToString();
                    key.UserId         = coreUser.UserId;
                    dataContext.ActivationKeys.InsertOnSubmit(key);
                    if (LocalUser.IsIntranet)
                    {
                        dataContext.SubmitChanges();
                        FormsAuthentication.RedirectFromLoginPage(coreUser.Login, false);
                        return;
                    }
                    else
                    {
                        dataContext.SubmitChanges();
                        SendActivationMail(coreUser.Email, key.ActivationKey1, coreUser.Login);
                    }
                }
                catch (Exception ex)
                {
                    aspErrorMessage.Visible = true;
                    aspErrorMessage.Text    = ex.Message;
                    return;
                }
                MultiView1.ActiveViewIndex = 1;
            }
        }