2017-08-08 01:05:11 +02:00
|
|
|
module authenticator;
|
|
|
|
|
|
|
|
import poodinis;
|
|
|
|
|
|
|
|
import vibe.data.bson : Bson;
|
2017-08-13 19:54:40 +02:00
|
|
|
import vibe.db.mongo.collection : MongoCollection;
|
2017-08-08 01:05:11 +02:00
|
|
|
|
|
|
|
interface Authenticator
|
|
|
|
{
|
2017-08-12 22:46:51 +02:00
|
|
|
bool checkUser(string username, string password) @safe;
|
2017-08-08 01:05:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class MongoDBAuthenticator : Authenticator
|
|
|
|
{
|
|
|
|
private:
|
2017-08-13 19:54:40 +02:00
|
|
|
@Value("users")
|
|
|
|
MongoCollection users;
|
2017-08-08 01:05:11 +02:00
|
|
|
|
|
|
|
public:
|
2017-08-12 22:46:51 +02:00
|
|
|
bool checkUser(string username, string password) @safe
|
2017-08-08 01:05:11 +02:00
|
|
|
{
|
|
|
|
auto result = users.findOne(["username" : username, "password" : password]);
|
|
|
|
return result != Bson(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AuthInfo
|
|
|
|
{
|
|
|
|
string userName;
|
|
|
|
}
|