using Bootstrap.Security;
using Longbow.Security.Cryptography;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
///
///
///
public class User : DataAccess.User
{
///
///
///
///
///
public override BootstrapUser RetrieveUserByUserName(string userName)
{
var users = MongoDbAccessManager.DBAccess.GetCollection("Users");
return users.Find(user => user.UserName == userName).FirstOrDefault();
}
///
///
///
///
///
///
public override bool Authenticate(string userName, string password)
{
if (string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password)) return false;
var users = MongoDbAccessManager.DBAccess.GetCollection("Users");
var u = users.Find(user => user.UserName == userName).FirstOrDefault();
return !string.IsNullOrEmpty(u.PassSalt) && u.Password == LgbCryptography.ComputeHash(password, u.PassSalt);
}
///
///
///
///
public override IEnumerable RetrieveNewUsers()
{
var users = MongoDbAccessManager.DBAccess.GetCollection("Users");
return users.Find(user => user.ApprovedTime == DateTime.MinValue).SortByDescending(user => user.RegisterTime).ToList();
}
}
}