Skip to content

Instantly share code, notes, and snippets.

View ivanvs's full-sized avatar

Ivan Vasiljević ivanvs

View GitHub Profile
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using TestWebApp.Infrastructure;
using TestWebApp.Models;
using TestWebApp.Repositories;
@ivanvs
ivanvs / InitializeWithDefaultData.cs
Created January 14, 2019 21:48
Fix problem with connection to database
public class InitializeWithDefaultData : DropCreateDatabaseAlways<AuthContext>
{
protected override void Seed(AuthContext context)
{
using (var store = new RoleStore<IdentityRole>(context))
{
using (var manager = new RoleManager<IdentityRole>(store))
{
manager.Create(new IdentityRole("admin"));
manager.Create(new IdentityRole("student"));
@ivanvs
ivanvs / AuthContext.cs
Created January 13, 2019 11:31
Ispravke kako bi sistem radio
public class AuthContext : IdentityDbContext<ApplicationUser>
{
public AuthContext() : base("AuthContext")
{
Database.SetInitializer(new InitializeWithDefaultData());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
@ivanvs
ivanvs / server.js
Last active December 30, 2017 00:00
Example of using hapi-swagger on hapi.js ^17.0.0
const Hapi = require('hapi');
const Inert = require('inert');
const Vision = require('vision');
const HapiSwagger = require('hapi-swagger');
const Pack = require('./package');
const server = Hapi.Server({
host: 'localhost',
port: 3000
});
@ivanvs
ivanvs / 06-nodejs-twitter-auth-route.js
Last active October 12, 2017 19:15
React example how to do authenitcation with Twitter
router.route('/auth/twitter')
.post((req, res, next) => {
request.post({
url: `https://api.twitter.com/oauth/access_token?oauth_verifier`,
oauth: {
consumer_key: 'KEY',
consumer_secret: 'SECRET',
token: req.query.oauth_token
},
form: { oauth_verifier: req.query.oauth_verifier }
@ivanvs
ivanvs / 06-nodejs-twitter-reverse-route.js
Last active February 13, 2018 14:48
React example how to do authenitcation with Twitter
router.route('/auth/twitter/reverse')
.post(function(req, res) {
request.post({
url: 'https://api.twitter.com/oauth/request_token',
oauth: {
oauth_callback: "http%3A%2F%2Flocalhost%3A3000%2Ftwitter-callback",
consumer_key: 'KEY',
consumer_secret: 'SECRET'
}
}, function (err, r, body) {
@ivanvs
ivanvs / 03-react-twitter-authentication-logout.js
Created September 16, 2017 23:27
React example how to do authenitcation with Twitter
logout = () => {
this.setState({isAuthenticated: false, token: '', user: null})
};
@ivanvs
ivanvs / 01-react-twitter-authentication-render.js
Created September 16, 2017 23:22
React example how to do authenitcation with Twitter
onSuccess = (response) => {
const token = response.headers.get('x-auth-token');
response.json().then(user => {
if (token) {
this.setState({isAuthenticated: true, user: user, token: token});
}
});
};
onFailed = (error) => {
@ivanvs
ivanvs / 01-react-twitter-authentication-constructor.js
Created September 16, 2017 23:03
React example how to do authenitcation with Twitter
constructor() {
super();
this.state = { isAuthenticated: false, user: null, token: ''};
}
@ivanvs
ivanvs / 05-nodejs-twitter-jwt-handling.js
Created September 16, 2017 16:04
React example how to do authenitcation with Twitter
//token handling middleware
var authenticate = expressJwt({
secret: 'my-secret',
requestProperty: 'auth',
getToken: function(req) {
if (req.headers['x-auth-token']) {
return req.headers['x-auth-token'];
}
return null;
}