コード例 #1
0
		public void EachTestInitialize()
		{
			Player p1 = new Player() {FirstName="TestFirstName1", LastName="TestLastName1", BirthDate=new DateTime(1993,10,10), PhoneNumber="606", Email="*****@*****.**", SkillLevel=.0f, City="Testowo", TopPosition=1};
			Player p2 = new Player() { FirstName = "TestFirstName2", LastName = "TestLastName2", BirthDate = new DateTime(1991, 11, 04), PhoneNumber = "606", Email = "*****@*****.**", SkillLevel = .5f, City = "Testolandia", TopPosition = 2 };
			Account a1 = new Account()
			{
				Login = "******",
				Password = "******",
				Player = p1
			};
			Account a2 = new Account()
			{
				Login = "******",
				Password = "******",
				Player = p2
			};
			context.Accounts.Add(a1);
			context.Accounts.Add(a2);
			context.Players.Add(p1);
			context.Players.Add(p2);
			context.SaveChanges();
			id1 = context.Accounts.FirstOrDefault<Account>(a => a.Login == "test1").AccountId;
			id2 = context.Accounts.FirstOrDefault<Account>(a => a.Login == "test2").AccountId;
			context.SaveChanges();
		}
コード例 #2
0
		public ActionResult Register(RegistrationViewModel rvm)
		{
			if (ModelState.IsValid)
			{
				using(var db = new TennisOrganizerContext())
				{
					if (!Account.CheckAvailability(rvm.Login))
					{
						ViewData.Add("LoginAvailability", (bool)false);
						return View(rvm);
					}
					else
					{
						Account acc = new Account { Login = rvm.Login, Password = rvm.Password };
						rvm.Player.ImagePath = "default.png";
						Player p = rvm.Player;
						p.TopPosition = db.Players.Count<Player>() + 1;

						Account.CreateAccount(acc, p);

						TempData.Add("RegisteredLogin", rvm.Login);
						TempData.Add("RegisteredName", rvm.Player.FirstName);
						TempData.Add("RegisteredEmail", rvm.Player.Email);
						if (!TempData.ContainsKey("ValidRegistration")) ;
						TempData.Add("ValidRegistration", (bool) true);
						return RedirectToAction("RegisterSuccess");
					}
				}
			}
			else
			{
				return View(rvm);
			}
		}
コード例 #3
0
		public void Test_CheckAvailability()
		{
			Account acc = new Account() { Login = "******", Password = "******" };
			db.Accounts.Add(acc);
			db.SaveChanges();

			bool result = Account.CheckAvailability("test");
			bool result2= Account.CheckAvailability("Account_Test");

			Assert.IsFalse(result);
			Assert.IsTrue(result2);
		}
コード例 #4
0
		public static bool CreateAccount(Account acc, Player p)
		{
			if (acc == null || p == null) return false;
			if (CheckAvailability(acc.Login) == false) return false;
			acc.Player = p;
			acc.Password = Encrypter.GetSHA256Hash(acc.Password);
			using (var db = new TennisOrganizerContext())
			{
				db.Accounts.Add(acc);
				db.Players.Add(p);
				db.SaveChanges();

				var query = (from a in db.Accounts
							 where a.Login == acc.Login
							 select a);
				if (query.Count<Account>() != 0) return true;
				else return false;
			}
		}
コード例 #5
0
		public ActionResult Index(Account acc, string ReturnUrl)
		{
			using (var db =  new TennisOrganizerContext())
			{
				var query = db.Accounts.FirstOrDefault<Account>(a => a.Login == acc.Login);
				if (query == null)
				{
					ViewData.Add("LoginNotFound", (bool)true);
					return View(acc);
				}
				else if (Account.CheckPassword(query.Login, acc.Password) == false)
				{
					ViewData.Add("PasswordIncorrect", (bool)true);
					return View(acc);
				}
				else
				{
				//	Session["User"] = acc.Login;
					FormsAuthentication.SetAuthCookie(acc.Login, false);
					if (ReturnUrl != null) return Redirect(ReturnUrl);
					return RedirectToAction("Profile", "Main");
				}
			}
		}
コード例 #6
0
		public void Test_CreateAccount()
		{
			Account acc = null;
			Player p = null;

			bool result1 = Account.CreateAccount(acc, p);
			acc = new Account { Login = "******", Password = "******"};
			p = new Player { FirstName = "AccountTest", LastName = "AccountTest",  BirthDate=new DateTime(2015,01,01), Email = "*****@*****.**", City = "AccountTest" };

			bool result2 = Account.CreateAccount(acc, p);
			bool result3 = Account.CreateAccount(acc, p);
			Assert.IsFalse(result1);
			Assert.IsTrue(result2);
			Assert.IsFalse(result3);
		}
コード例 #7
0
		public void Test_CheckPassword()
		{
			Account acc = null;
			acc = new Account() { Login = "******", Password = "******", Player = p };
			Account.CreateAccount(acc, p);
			bool result1 = Account.CheckPassword(acc.Login, "asd");
			bool result2 = Account.CheckPassword("Account_Test_fail", "asd");
			bool result3 = Account.CheckPassword(acc.Login, "badPassword");

			Assert.IsTrue(result1);
			Assert.IsFalse(result2);
			Assert.IsFalse(result3);

		}
コード例 #8
0
		public void Test_UpdatePlayer()
		{
			Account acc = null;
			Player p2 = null;
			acc = new Account() { Login = "******", Password = "******", Player = p };
			bool result2 = acc.UpdatePlayer( "asd", p);
			Account.CreateAccount(acc, p);
			bool result3 = acc.UpdatePlayer( "dsa", p);


			Assert.IsFalse(result2);
			Assert.IsFalse(result3);
		}
コード例 #9
0
		public void Test_UpdateAccount()
		{
			Account acc = null;
			acc = new Account { Login = "******", Password = "******" };
			bool result2 = acc.UpdatePlayer("asd", p);
			Account.CreateAccount(acc, p);
			bool result3 = acc.UpdateAccount("dsa", "dsa", "Account_Test");
			bool result4 = acc.UpdateAccount("asd", "dsa", "Account_Test2");
			var query = db.Accounts.Where<Account>(a => a.Login == "Account_Test2").FirstOrDefault<Account>();
			bool result5 = query == null ? false : true;
			if(result5 == true)
			{
				acc.UpdateAccount("dsa", "asd", "Account_Test2");
			}
			Assert.IsFalse(result2);
			Assert.IsFalse(result3);
			Assert.IsTrue(result4);
			Assert.IsTrue(result5);
		}
コード例 #10
0
		public ActionResult AccountEdition(AccountEditorData model)
		{
			if (Session["LoggedInPlayerId"] == null || Session["LoggedInPlayer"] == null) return RedirectToAction("Index", "Home");
			if(ModelState.IsValid)
			{
				if (model.Login != (string)Session["LoggedInPlayer"])
				{
					if (!Account.CheckAvailability(model.Login))
					{
						ViewData.Add("LoginAvailability", (bool)false);
						return View(model);
					}
					Account acc = new Account() { AccountId = (int)Session["LoggedInPlayerId"] };
					if(acc.UpdateAccount(model.Password, model.NewPassword, model.Login) == false)
					{
						ViewData.Add("PasswordIncorrect", (bool)true);
						return View(model);
					}
					else
					{
						FormsAuthentication.SignOut();
						FormsAuthentication.SetAuthCookie(model.Login, false);
					}
				}
			}
			return View(model);
		}