minimal passport
This commit is contained in:
31
server-node/src/auth/passport-config.ts
Normal file
31
server-node/src/auth/passport-config.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import LocalStrategy from "passport-local";
|
||||
import * as User from "./user/user-controller";
|
||||
|
||||
export function initialize(passport: typeof import("passport")) {
|
||||
passport.use("local", new LocalStrategy.Strategy(
|
||||
function(username, password, done) {
|
||||
User.findOne({ username: username }, function (err, user) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
if (!user) {
|
||||
return done(null, false);
|
||||
}
|
||||
if (!User.verifyPassword(user, password)) {
|
||||
return done(null, false);
|
||||
}
|
||||
return done(null, user);
|
||||
});
|
||||
}
|
||||
));
|
||||
|
||||
passport.serializeUser((user, done) => {
|
||||
done(null, user.id)
|
||||
});
|
||||
|
||||
passport.deserializeUser((id: number, done) => {
|
||||
User.findOne({id: id}, function (err, user) {
|
||||
done(err, user);
|
||||
});
|
||||
});
|
||||
}
|
||||
16
server-node/src/auth/user/user-controller.ts
Normal file
16
server-node/src/auth/user/user-controller.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { User } from "./user-model";
|
||||
|
||||
export function findOne(params: {id?: number, username?: string}, cb: (err: Error | null, user: User) => void): undefined {
|
||||
//TODO: replace with db connection.
|
||||
cb(null, {
|
||||
id: 1,
|
||||
username: "test",
|
||||
mail: "test@test.com",
|
||||
accessControlList: []
|
||||
});
|
||||
}
|
||||
|
||||
export function verifyPassword(user: User, password: string) {
|
||||
//TODO: replace with db connection.
|
||||
return password == "test";
|
||||
}
|
||||
6
server-node/src/auth/user/user-model.ts
Normal file
6
server-node/src/auth/user/user-model.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface User {
|
||||
id: number,
|
||||
username: string,
|
||||
mail: string,
|
||||
accessControlList: string[],
|
||||
}
|
||||
Reference in New Issue
Block a user