-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First steps with the auth system, implemented websocket support.
- Loading branch information
1 parent
518a9bd
commit 8d10793
Showing
8 changed files
with
548 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,55 @@ | ||
import {Request, Response} from "express"; | ||
import UserModel from "../models/UserModel"; | ||
|
||
export namespace Controls { | ||
export class AuthController { | ||
static auth(req: Request, res: Response, next: void) { | ||
import {v4 as uuid} from 'uuid'; | ||
|
||
} | ||
const jwt = require('jsonwebtoken'); | ||
const bcrypt = require('bcryptjs'); | ||
|
||
static create(req: Request, res: Response) { | ||
export class AuthController { | ||
static auth(req: Request, res: Response, next: void) { | ||
|
||
} | ||
} | ||
|
||
static create(req: Request, res: Response) { | ||
// const {username, password} = req.headers; | ||
// | ||
// if (username !== undefined && password !== undefined) { | ||
// const user = UserModel.findOne({ | ||
// username: `${username}` | ||
// }); | ||
// | ||
// if (user === null) { | ||
// console.log("NEW !") | ||
// } | ||
// | ||
// const hashedPassword = bcrypt.hashSync(password, 8); | ||
// | ||
// UserModel.create({ | ||
// username: `${username}`, | ||
// password: `${hashedPassword}`, | ||
// }, (err, user) => { | ||
// if (err) | ||
// return res.status(500).send("There was a problem registering the user."); | ||
// | ||
// // create a token | ||
// const token = jwt.sign({uuid: user[0]}, process.env.SECRET, { | ||
// expiresIn: 86400 // expires in 24 hours | ||
// }); | ||
// | ||
// res.status(200).send({auth: true, token: token}); | ||
// }).then(r => { | ||
// }); | ||
// } else { | ||
// res.sendStatus(400); | ||
// } | ||
} | ||
|
||
static remove(req: Request, res: Response): void { | ||
static remove(req: Request, res: Response): void { | ||
|
||
} | ||
} | ||
|
||
static list(req: Request, res: Response): void { | ||
static list(req: Request, res: Response): void { | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import mongoose, {Schema, Document} from 'mongoose'; | ||
|
||
export interface IUser extends Document { | ||
username: string; | ||
password: string; | ||
} | ||
|
||
const UserSchema: Schema = new Schema({ | ||
username: {type: String, required: true}, | ||
password: {type: String, required: true} | ||
}, { | ||
versionKey: false | ||
}); | ||
|
||
export default mongoose.model<IUser>('User', UserSchema, "users"); |
Oops, something went wrong.