public void Init()
        {
            IdentityHelper ihelper  = IdentityHelper.GetInstance();
            string         userName = "******";
            AppUser        user     = new AppUser
            {
                AccountName = userName,
                Name        = "James",
                Mobile      = "1888888888",
                Email       = "*****@*****.**"
            };
            string password = "******";
            var    dbUser   = database.Users.SingleOrDefault(u => u.AccountName == userName);

            if (dbUser != null)
            {
                //等一下注释掉这一句
                database.Users.Remove(dbUser);
                database.SaveChanges();
            }
            IdentityResult result = ihelper.CreateUser(user, password, AppRoleEnum.OrgnizationMember, OrganizationEnum.SEA团队);

            testclaims = ihelper.CreateClaims(userName, password, userName);
            helper     = VolunteerHelper.GetInstance(testclaims);
        }
        public void EditVolunteerTest()
        {
            #region init
            IdentityHelper ihelper  = IdentityHelper.GetInstance();
            string         userName = "******";
            AppUser        user     = new AppUser
            {
                AccountName = userName,
                Name        = "James",
                Mobile      = "1888888888",
                Email       = "*****@*****.**"
            };
            string  password = "******";
            AppUser dbUser   = database.Users.SingleOrDefault(u => u.AccountName == userName);
            if (dbUser != null)
            {
                database.Users.Remove(dbUser);
                database.SaveChanges();
            }
            IdentityResult result1 = ihelper.CreateUser(user, password, AppRoleEnum.OrgnizationMember, OrganizationEnum.SEA团队);
            testclaims = ihelper.CreateClaims(userName, password, userName);
            helper     = VolunteerHelper.GetInstance(testclaims);
            #endregion
            #region 新建一个志愿者对象
            Volunteer v = new Volunteer
            {
                StudentNum = 0401,
                Name       = "EditTestName",
                Class      = "TestClass",
                Email      = "*****@*****.**",
                Room       = "testroom"
            };
            helper.AddVolunteer(v);
            #endregion

            #region 第一次修改
            v.Name = "ModifiedEditTestName";
            var tempvolunteer = helper.FindVolunteer(v.StudentNum);
            helper.EditVolunteer(tempvolunteer, v);//需要重建一个volunteer实体,因为实体v在加入数据库之后会自动更新链接到数据库中的条目。
            tempvolunteer = helper.FindVolunteer(v.StudentNum);
            if (!Volunteer.AreSame(v, tempvolunteer))
            {
                Assert.Fail("修改志愿者信息失败");
            }
            #endregion

            #region 第二次修改
            v.Name        = "EditByParamTestName";
            tempvolunteer = helper.FindVolunteer(v.StudentNum);
            helper.EditVolunteer(tempvolunteer, v.StudentNum, v.Name);
            tempvolunteer = helper.FindVolunteer(v.StudentNum);
            if (!Volunteer.AreSame(v, tempvolunteer))
            {
                Assert.Fail("第二次修改志愿者信息失败");
            }
            #endregion
            var result3 = helper.FindVolunteer(v.StudentNum);
            database.Volunteers.Remove(result3);//Remove
        }
        public void Init()
        {
            AppUser user     = CreateUser();
            string  password = "******";
            var     dbUser   = database.Users.SingleOrDefault(u => u.AccountName == user.AccountName);

            if (dbUser != null)
            {
                //等一下注释掉这一句
                database.Users.Remove(dbUser);
                database.SaveChanges();
            }
            IdentityResult result = identityhelper.CreateUser(user, password, Interface.AppRoleEnum.OrgnizationMember, OrganizationEnum.SEA团队);

            testclaims      = identityhelper.CreateClaims(user.AccountName, password);
            volunteerhelper = VolunteerHelper.GetInstance(testclaims);
        }
Example #4
0
        public void FindManagerListByStudentNumTest()
        {
            // 创建一个originalmanager
            Organization org             = identityhelper.CreateOrFindOrganization(OrganizationEnum.TestOnly);
            Guid         tempuser        = Guid.NewGuid();
            string       username        = tempuser.ToString();
            Random       tempusernum     = new Random();
            int          userstudentnum  = tempusernum.Next(000, 999);
            AppUser      originalmanager = new AppUser()
            {
                AccountName = username,
                StudentNum  = userstudentnum,
                Mobile      = "1234567890",
                Email       = "*****@*****.**"
            };

            identityhelper.CreateUser(originalmanager, "zxcvbnm,./", Interface.AppRoleEnum.OrgnizationMember, OrganizationEnum.TestOnly);
            var addmanager = database.Users.Single(u => u.AccountName == originalmanager.AccountName);

            if (addmanager == null)
            {
                Assert.Fail("添加manager失败!");
            }

            // 测试FindManageListByStudentNum
            var result = helper.FindManagerListByStudentNum(originalmanager.StudentNum).ToList();

            if (result == null)
            {
                Assert.Fail("未能成功找到managelist,方法调用失败!");
            }
            else
            {
                foreach (var item in result)
                {
                    if ((item.AccountName != originalmanager.AccountName) && (item.Mobile != originalmanager.Mobile))
                    {
                        Assert.Fail("所查找记录与原纪录不匹配!");
                    }
                }
            }
            // 删除数据库中添加的数据[users]
            DeleteOrgnization(org);
        }
Example #5
0
        protected override void Seed(DatabaseContext context)
        {
            //  This method will be called after migrating to the latest version.

            var identityManager = new IdentityHelper();
            var user            = new ApplicationUser()
            {
                UserName = "******"
            };

            identityManager.CreateUser(user, "password1");

            new List <Account>
            {
                new Account {
                    AccountID = 1, Status = "Active", ApplicationName = "Facebook", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09154606581", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 2, Status = "Active", ApplicationName = "Twitter", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09154606581", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 3, Status = "Active", ApplicationName = "Instagram", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09306326211", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 4, Status = "Active", ApplicationName = "Twitch", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09114567887", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 5, Status = "Active", ApplicationName = "Steam", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09306326211", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 6, Status = "Active", ApplicationName = "Garena", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09154606581", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 7, Status = "Active", ApplicationName = "Quora", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09154606581", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 8, Status = "Active", ApplicationName = "Grab", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09306326211", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 9, Status = "Active", ApplicationName = "Gmail", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09154606581", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 10, Status = "Active", ApplicationName = "Chinabank", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09154606581", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 11, Status = "Active", ApplicationName = "Facebook", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09306326211", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 12, Status = "Active", ApplicationName = "Yahoo", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09114567887", Password = pwHelper.EncryptPassword("qwerty@1")
                },
                new Account {
                    AccountID = 13, Status = "Active", ApplicationName = "Instagram", EmailAddress = "*****@*****.**", Username = "******", MobileNumber = "09154606581", Password = pwHelper.EncryptPassword("qwerty@1")
                }
            }.ForEach(a => context.Accounts.AddOrUpdate(a));
        }
        public void CreateUserTest()
        {
            string  accountName = "X!@#$%^&*()_+-=1234567890qwertyuiop[]\\{}|asdfghjkl;':\"zxcvbnm,./<>?";
            AppUser dbUser      = database.Users.SingleOrDefault(u => u.AccountName == accountName);

            if (dbUser != null)
            {
                database.Users.Remove(dbUser);
                database.SaveChanges();
            }

            AppUser user = new AppUser
            {
                Name        = "张三李四·.",
                AccountName = accountName,
                Email       = "*****@*****.**",
                Mobile      = "18888888888"
            };
            string         password = "******"zxcvbnm,./<>?";
            IdentityResult result   = helper.CreateUser(user, password, AppRoleEnum.OrgnizationMember, OrganizationEnum.SEA团队);

            if (!result.Succeeded)
            {
                Assert.Fail();
            }

            dbUser = database.Users.SingleOrDefault(u => u.AccountName == user.AccountName);
            if (dbUser == null)
            {
                Assert.Fail();
            }
            if (dbUser.Name != user.Name || dbUser.AccountName != user.AccountName || dbUser.Email != user.Email || dbUser.Mobile != user.Mobile)
            {
                Assert.Fail();
            }
            database.Users.Remove(dbUser);
            database.SaveChanges();
        }
        private void register_button_Click(object sender, RoutedEventArgs e)
        {
            int studentnum;

            if (!int.TryParse(studentid.Text, out studentnum))
            {
                ModernDialog.ShowMessage("学号输入非法", "警告", MessageBoxButton.OK);
            }
            else
            if (studentnum < 201300000 || studentnum > 205000000)
            {
                ModernDialog.ShowMessage("学号大小非法", "警告", MessageBoxButton.OK);
            }
            else
            if (wholename.Text == "" || studentid.Text == "" || accountname.Text == "" || telephonenumber.Text == "" || emailadress.Text == "" || dormitaryadress.Text == "" || passwordBox.Password == "" || comboBox.Text == "")
            {
                ModernDialog.ShowMessage("信息输入不完整,请检查后重试.", "警告", MessageBoxButton.OK);
            }
            else
            {
                IdentityHelper ih = IdentityHelper.GetInstance();
                if (passwordBox.Password.Length <= 5)
                {
                    ModernDialog.ShowMessage("密码过短,长度至少为6位", "警告", MessageBoxButton.OK);
                }
                else
                if (telephonenumber.Text.Length != 11)
                {
                    ModernDialog.ShowMessage("电话长度应为11位", "警告", MessageBoxButton.OK);
                }
                else
                if (!emailadress.Text.Contains("@"))
                {
                    ModernDialog.ShowMessage("非法的邮箱格式,请检查", "警告", MessageBoxButton.OK);
                }
                else
                if (dormitaryadress.Text.Length > 10 || dormitaryadress.Text.Length < 3)
                {
                    ModernDialog.ShowMessage("非法的宿舍格式,请检查", "警告", MessageBoxButton.OK);
                }
                else
                if (passwordBox.Password == passwordBox1.Password)
                {
                    string           passWord = passwordBox.Password;
                    OrganizationEnum org      = ih.Matching(comboBox.Text);
                    //创建第一个用户
                    AppUserStatus status = AppUserStatus.NotApproved;
                    AppRoleEnum   role   = AppRoleEnum.OrgnizationMember;
                    if (isAdministrator)
                    {
                        status = AppUserStatus.Enabled;
                        role   = AppRoleEnum.OrgnizationAdministrator;
                    }
                    if (accountname.Text == "admin" && wholename.Text == "admin")
                    {
                        status = AppUserStatus.Enabled;
                        role   = AppRoleEnum.Administrator;
                    }
                    AppUser au = new AppUser()
                    {
                        StudentNum  = int.Parse(studentid.Text),
                        AccountName = accountname.Text,
                        Name        = wholename.Text,
                        Mobile      = telephonenumber.Text,
                        Email       = emailadress.Text,
                        Room        = dormitaryadress.Text,
                        Status      = status
                    };
                    IdentityResult result = ih.CreateUser(au, passWord, role, org);
                    if (result.Succeeded == true)
                    {
                        if (isAdministrator)
                        {
                            ModernDialog.ShowMessage("注册机构账号成功!账号所属机构:[" + comboBox.Text + "],机构账号用户名:[" + accountname.Text + "],密码:[" + passWord + "],请牢记账号密码!", "", MessageBoxButton.OK);
                        }
                        else
                        {
                            ModernDialog.ShowMessage("注册成功!已发送注册审批请求,请等待管理员审批.", "", MessageBoxButton.OK);
                            System.Windows.Forms.Application.Restart();
                            Application.Current.Shutdown();
                        }
                        this.Close();
                    }
                    else
                    {
                        ModernDialog.ShowMessage("注册失败,错误信息:" + string.Join(",", result.Errors), "", MessageBoxButton.OK);
                    }
                }
                else
                {
                    ModernDialog.ShowMessage("两次密码输入不一致", "", MessageBoxButton.OK);
                }
            }
        }