last commit before tests
This commit is contained in:
@@ -1,47 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using MySql.Data.MySqlClient;
|
||||
using BCrypt.Net;
|
||||
|
||||
namespace SkyTeam
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LogInPage.xaml
|
||||
/// </summary>
|
||||
public partial class LogInPage : Page
|
||||
{
|
||||
public LogInPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void AdminLink_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (Application.Current.MainWindow is MainWindow mainWindow)
|
||||
{
|
||||
mainWindow.MainFrame.Navigate(new AdminLoginPage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void LogInButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string email = BenutzernameTextBox.Text;
|
||||
string password = PasswortTextBox.Password;
|
||||
|
||||
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
MessageBox.Show("Bitte Email und Passwort eingeben.");
|
||||
return;
|
||||
}
|
||||
|
||||
string query = @"
|
||||
SELECT Id, Vorname, Rolle, PasswortHash
|
||||
FROM users
|
||||
WHERE Email = @email";
|
||||
|
||||
try
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@email", email);
|
||||
|
||||
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (!reader.Read())
|
||||
{
|
||||
MessageBox.Show("Benutzer wurde nicht gefunden.");
|
||||
return;
|
||||
}
|
||||
|
||||
string storedHash = reader.GetString("PasswortHash");
|
||||
|
||||
if (!BCrypt.Net.BCrypt.Verify(password, storedHash))
|
||||
{
|
||||
MessageBox.Show("Falsches Passwort.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SessionManager.CurrentUserId = reader.GetInt32("Id");
|
||||
SessionManager.CurrentUserName = reader.GetString("Vorname");
|
||||
SessionManager.Role = reader.GetString("Rolle");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
((MainWindow)Application.Current.MainWindow)
|
||||
.MainFrame.Navigate(new NavigationPage());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Datenbankfehler: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void anmeldungsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new RegistrationPage());
|
||||
|
||||
}
|
||||
|
||||
private void LogInButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new NavigationPage());
|
||||
|
||||
((MainWindow)Application.Current.MainWindow)
|
||||
.MainFrame.Navigate(new RegistrationPage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user