Skip to content

Instantly share code, notes, and snippets.

View DomDumont's full-sized avatar
🎯
Focusing

Dominique Dumont DomDumont

🎯
Focusing
View GitHub Profile
@DomDumont
DomDumont / gist:a10f740cc48d173d5df47799d3cf1e19
Created October 16, 2023 18:18
dialog with animation in godot
func Open():
window.show()
var tween = create_tween()
tween.tween_property(window, "position:y", 300, 2).set_trans(Tween.TRANS_ELASTIC).set_ease(Tween.EASE_OUT)
tween.tween_property(window,"modulate:a",1,2)
tween.play()
func _on_window_close_requested():
@DomDumont
DomDumont / GoogleJSONWebToken.cs
Created November 30, 2018 16:35
Google json web token for Unity
using System;
using System.Text;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Collections.Generic;
using UnityEngine;
export const authenticate = async ({ headers: { authorization } }, Users) => {
const token = authorization && HEADER_REGEX.exec(authorization)[1];
jwt.verify(token, process.env.JWT_SECRET, (err, decoded: any) => {
if (err) {
return undefined;
}
else {
return Users.findOne({ _id: new ObjectID(decoded._id) });
}
const HEADER_REGEX = /bearer token-(.*)$/;
/**
* This is an extremely simple token. In real applications make
* sure to use a better one, such as JWT (https://jwt.io/).
*/
module.exports.authenticate = async ({headers: {authorization}}, Users) => {
const email = authorization && HEADER_REGEX.exec(authorization)[1];
return email && await Users.findOne({email});
}
signinUser: async (root, data, { mongo: { Users } }) => {
const user = await Users.findOne({ email: data.email.email });
if (user === null) {
throw new Error("Email not found !!");
}
const passwordIsGood = await bcrypt.compare(data.email.password, user.password);
if (passwordIsGood) {
const newToken = jwt.sign({ _id: user._id }, process.env.JWT_SECRET, { expiresIn: "1h" });
signinUser: async (root, data, { mongo: { Users } }) => {
const user = await Users.findOne({ email: data.email.email });
if (user === null) {
throw new Error("Email not found !!");
}
const passwordIsGood = await bcrypt.compare(data.email.password, user.password);
if (passwordIsGood) {
return { token: `token-${user.email}`, user };
signinUser: async (root, data, { mongo: { Users } }) => {
const user = await Users.findOne({ email: data.email.email });
if (user === null) {
throw new Error("Email not found !!");
}
if (data.email.password === user.password) {
return { token: `token-${user.email}`, user };
}
},
signinUser: async (root, data, {mongo: {Users}}) => {
const user = await Users.findOne({email: data.email.email});
if (data.email.password === user.password) {
return {token: `token-${user.email}`, user};
}
},
createUser: async (root, data, { mongo: { Users } }) => {
const user = await Users.findOne({ email: data.authProvider.email.email });
if (user) {
// a user with the same email was found, throw an error
throw new Error("Email already exists");
}
const hash = await bcrypt.hash(data.authProvider.email.password, 10);
const newUser = {
name: data.name,
createUser: async (root, data, { mongo: { Users } }) => {
const user = await Users.findOne({ email: data.authProvider.email.email });
if (user) {
// a user with the same email was found, throw an error
throw new Error("Email already exists");
}
const newUser = {
name: data.name,
email: data.authProvider.email.email,