/// <summary> /// Retrieve an "Account" entity for a specified email and password combination. /// </summary> /// <param name="email">The email address associated with the account.</param> /// <param name="password">The hashed password associated with the account.</param> /// <returns>The "Account" entity that was requested.</returns> public Account GetAccount(string email, string password) { this.dbConnection.Open(); Account account = new Account(); string query = @"SELECT email, password, type FROM Account WHERE email = @email AND password = @password"; SQLiteCommand command = new SQLiteCommand(query, this.dbConnection); command.Parameters.AddWithValue("@email", email); command.Parameters.AddWithValue("@password", password); SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); string type = reader.GetString(2); if (type == "Administrator") { account = new AdministratorAccount(reader); } else if (type == "Student") { StudentAccount studentAccount = new StudentAccount(reader); studentAccount.Classes = this.GetClasses(studentAccount); account = studentAccount; } else { account = new Account(reader); } } reader.Close(); this.dbConnection.Close(); return(account); }
/// <summary> /// Create test Accounts. /// </summary> private void CreateTestContentAccounts() { AdministratorAccount administrator = new AdministratorAccount(); administrator.Email = "*****@*****.**"; administrator.Password = "******".GetHashCode().ToString(); administrator.Type = "Administrator"; dbConnector.SaveAccount(administrator); StudentAccount student = new StudentAccount(); student.Email = "*****@*****.**"; student.Password = "******".GetHashCode().ToString(); student.Type = "Student"; student.Classes = dbConnector.GetClasses(); dbConnector.SaveAccount(student); }
public ActionResult Index(AdministratorAccount account, string ReturnUrl = null) { AdministratorAccount personel = db.AdministratorAccounts.FirstOrDefault(x => x.username == account.username && x.password == account.password); if (personel == null) { ViewBag.Message = "yanlis Email veya Şifre !"; return(View()); } else { //if (ReturnUrl == null || ReturnUrl == string.Empty) // ReturnUrl = Server.UrlDecode("/"); //else // ReturnUrl = Server.UrlDecode(ReturnUrl); FormsAuthentication.SetAuthCookie(personel.administratorID.ToString(), false); return(Redirect("~/admin/Index")); } }