Skip to content

Instantly share code, notes, and snippets.

View kvnam's full-sized avatar

Kavita Nambissan kvnam

  • Toronto, Canada
  • 05:32 (UTC -12:00)
View GitHub Profile
@kvnam
kvnam / Posts.actions.js
Last active October 10, 2018 04:49
ReactPress Store
import axios from '../../axios-wp';
export const loadAllPosts = (perpage) => {
//Load per_page count of posts from our WordPress installation
return dispatch => {
axios.get('/wp/v2/posts?per_page=' + perpage)
.then(postsRes => {
//Retrieve a list of all Media IDs from returned posts
let mediaIds = [];
postsRes.data.forEach(post => {
@kvnam
kvnam / Blog.js
Last active October 10, 2018 04:48
ReactPress Blog
import React, { Component } from 'react';
import { Container, Row, Col } from 'reactstrap';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import * as actionMethods from '../../store/actions/index.actions'; //Exports all action methods allowing easy import
import Post from '../../components/Post/Post';
class Blog extends Component{
@kvnam
kvnam / Stats.js
Last active November 6, 2018 15:10
fs Module
Stats {
dev: 2114,
ino: 48064969,
mode: 33188,
nlink: 1,
uid: 85,
gid: 100,
rdev: 0,
size: 527,
blksize: 4096,
@kvnam
kvnam / download.js
Last active November 10, 2018 09:00
GridFS Storage
module.exports.getFile = (req, res) => {
//Accepting user input directly is very insecure and should
//never be allowed in a production app.
//Sanitize the input before accepting it
//This is for demonstration purposes only
let fileName = req.body.text1;
//Connect to the MongoDB client
MongoClient.connect(url, function(err, client){
if(err){
@kvnam
kvnam / Signin.js
Created November 27, 2018 10:01
WordPress REST API - Sign in Component
import React from "react";
import { Col, Form, InputGroup, FormGroup, Input, Button, InputGroupAddon, InputGroupText } from "reactstrap";
const signIn = (props) => {
return (
<Col xs="12" md={{size:6, offset: 3}}>
<h1 style={{textAlign: "center"}}>Sign In!</h1>
<Form autoComplete="false">
<InputGroup className="mb-3">
<InputGroupAddon addonType="prepend">
@kvnam
kvnam / Auth.js
Last active November 27, 2018 10:21
ReactPress Auth Container component
import React, { Component } from "react";
import { Switch, Route, Redirect } from "react-router-dom";
import { connect } from "react-redux";
import * as actionMethods from "../../store/actions/index.actions";
import SignUp from "../../components/Auth/SignUp";
import SignIn from "../../components/Auth/SignIn";
import SignOut from "../../components/Auth/Signout";
class Auth extends Component{
@kvnam
kvnam / Error.js
Last active November 27, 2018 10:29
ReactPress - Signin Action
{
"code": "jwt_auth_failed",
"data": {
"status": 403
},
"message": "Invalid Credentials."
}
@kvnam
kvnam / user-signin-reducer.js
Last active November 27, 2018 10:46
ReactPress - User Reducer
const initialState = {
username: "",
email: "",
displayname: "",
token: "",
error: null,
isLoading: false,
redirectURL: "/"
};
@kvnam
kvnam / Signout.js
Created November 27, 2018 10:42
ReactPress Sign out
import React, { Component } from "react";
import { connect } from "react-redux";
import { Redirect } from "react-router-dom";
import * as actionTypes from "../../store/actions/index.actions";
class Signout extends Component{
componentDidMount(){
if(this.props.token){
//Dispatch User Signout action
this.props.logoutUser(this.props.token);
@kvnam
kvnam / usersignout-action.js
Created November 27, 2018 10:44
ReactPress User signout Action
export const userSignout = (token) => {
return dispatch => {
axios.post("/simple-jwt-authentication/v1/token/revoke", {}, {headers: {"Authorization": "Bearer " + token}}).then(response => {
//Clear local storage
localStorage.removeItem("token");
localStorage.removeItem("email");
dispatch({type: actionTypes.USER_SIGNOUT_SUCCESS});
}).catch(err => {
dispatch({type: actionTypes.USER_SIGNOUT_FAIL, error: err});
})