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
# # C1: Each room can only hold 1 class at a time | |
def check_C1(self, A, a, B, b): | |
if a[0] == b[0] and a[1] == b[1] and a[2] == b[2]: | |
return False | |
return True | |
# # C2: Each student (class) can only attend a class at a time | |
def check_C2(self, A, a, B, b): | |
for key in dict1: |
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
on: [workflow_dispatch] | |
name: DeployAzureVM | |
jobs: | |
CreateAzureVM: | |
runs-on: windows-latest | |
steps: |
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
# Login to Azure using Service Principal credentials from Github Secrets | |
Write-Output "Logging in to Azure with a service principal..." | |
az login ` | |
--service-principal ` | |
--username $Env:SP_CLIENT_ID ` | |
--password $Env:SP_CLIENT_SECRET ` | |
--tenant $Env:SP_TENANT_ID | |
Write-Output "Done" | |
# Select Azure subscription |
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
<script> | |
import Web3 from 'web3' | |
export default ({ | |
data() { | |
return { | |
buttonDisabled: false, | |
buttonInstallText: "Click here to install Metamask", | |
} | |
}, |
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
var express = require('express'); | |
var router = express.Router(); | |
// Used to perfrom signature authentication | |
var ethUtil = require('ethereumjs-util'); | |
// JWT generation and verification | |
const jwt = require('jsonwebtoken'); | |
import passport from 'passport' |
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
const JwtStrategy = require('passport-jwt').Strategy; | |
const ExtractJwt = require('passport-jwt').ExtractJwt; | |
const mongoose = require('mongoose'); | |
import User from '../models/users'; | |
const opts = {}; | |
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken(); | |
opts.secretOrKey = process.env.JWT_SECRET; | |
module.exports = passport => { |
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
// Test authenticated route | |
// Use this route to test if the front-end is able to access this route | |
// Front-end needs to pass the token in the request header (header name: "Authorization") | |
router.get('/authenticated/test', passport.authenticate('jwt', { session: false }), (req, res) => { | |
console.log('Authentication successful'); | |
res.json({ | |
message: 'Successfully authenticated', | |
user: req.user | |
}); | |
}); |
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
async connectToMetamask() { | |
try { | |
// Connect to metamask and get user accounts | |
const accounts = await this.$store.getters['metamask/ethereum'].request({ method: 'eth_requestAccounts' }); | |
// Update vuex store | |
this.$store.commit('metamask/setMetamaskConnected', true) | |
this.$store.commit('metamask/setAccounts', accounts) | |
// Check if user is registered, if not, register them |
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
// Get user nonce | |
router.get('/:wallet_address/nonce', (req, res) => { | |
// Check if user exists | |
// ... search in database for user and returns its current nonce | |
}); | |
// Process signed message | |
router.post('/:user/signature', (req, res) => { | |
// Get user from db | |
User.findOne({wallet_address: req.params.user}, (err, user) => { |
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
export const state = () => ({ | |
metamaskConnected: false, | |
ethereum: null, | |
accounts: [] | |
}) | |
export const mutations = { | |
setMetamaskConnected(state, value) { | |
state.metamaskConnected = value | |
}, |
OlderNewer