mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
moved everything up a directory
This commit is contained in:
parent
448cd8d92e
commit
9a78f790a6
76 changed files with 0 additions and 0 deletions
71
RequestPlex.Core/UserMapper.cs
Normal file
71
RequestPlex.Core/UserMapper.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using Mono.Data.Sqlite;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Authentication.Forms;
|
||||
using Nancy.Security;
|
||||
|
||||
using RequestPlex.Store;
|
||||
|
||||
namespace RequestPlex.Core
|
||||
{
|
||||
public class UserMapper : IUserMapper
|
||||
{
|
||||
|
||||
public IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context)
|
||||
{
|
||||
var db = new DbConfiguration(new SqliteFactory());
|
||||
var repo = new UserRepository<UserModel>(db);
|
||||
|
||||
var user = repo.Get(identifier.ToString());
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new UserIdentity
|
||||
{
|
||||
UserName = user.UserName,
|
||||
};
|
||||
}
|
||||
|
||||
public static Guid? ValidateUser(string username, string password)
|
||||
{
|
||||
var db = new DbConfiguration(new SqliteFactory());
|
||||
var repo = new UserRepository<UserModel>(db);
|
||||
var users = repo.GetAll();
|
||||
var userRecord = users.FirstOrDefault(u => u.UserName == username && u.Password == password); // TODO hashing
|
||||
|
||||
if (userRecord == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Guid(userRecord.User);
|
||||
}
|
||||
|
||||
public static bool DoUsersExist()
|
||||
{
|
||||
var db = new DbConfiguration(new SqliteFactory());
|
||||
var repo = new UserRepository<UserModel>(db);
|
||||
var users = repo.GetAll();
|
||||
return users.Any();
|
||||
}
|
||||
|
||||
public static Guid? CreateUser(string username, string password)
|
||||
{
|
||||
var db = new DbConfiguration(new SqliteFactory());
|
||||
var repo = new UserRepository<UserModel>(db);
|
||||
|
||||
var userModel = new UserModel { UserName = username, User = Guid.NewGuid().ToString(), Password = password };
|
||||
repo.Insert(userModel);
|
||||
|
||||
var userRecord = repo.Get(userModel.User);
|
||||
|
||||
return new Guid(userRecord.User);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue