Skip to content
Snippets Groups Projects
Commit 0644f5bc authored by Daniel Lorych's avatar Daniel Lorych :cookie:
Browse files

Add Login service

parent 64896e8c
No related branches found
No related tags found
No related merge requests found
using System;
using Npgsql;
namespace Helios.Source
{
public class LoginService
{
private readonly NpgsqlConnection _connection;
private string password = string.Empty;
public LoginService(string connectionString)
{
_connection = new NpgsqlConnection(connectionString);
}
public Login GetLogin(string email, string password)
{
this.password = password;
Login userLogin = new Login(email);
userLogin = GetUserDetails(userLogin);
return userLogin;
}
private Login GetUserDetails(Login userLogin)
{
NpgsqlCommand cmd = new NpgsqlCommand("select * from user_login where email = @emailParam and user_password = @passwordParam", _connection);
cmd.Parameters.AddWithValue("@emailParam", userLogin.EmailAddress);
cmd.Parameters.AddWithValue("@passwordParam", this.password);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
userLogin.IsValidUser = true;
userLogin.IsAdmin = bool.Parse(reader["is_admin"].ToString());
}
else
{
userLogin.IsValidUser = false;
userLogin.IsAdmin = false;
}
return userLogin;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment