Merge branch 'fix_register' of Asara/sudoscientist-js-frontend into master
This commit is contained in:
commit
58a8fa234a
11 changed files with 5395 additions and 4400 deletions
3
.env.development
Normal file
3
.env.development
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
REACT_APP_API_PROTO=http://
|
||||||
|
REACT_APP_API_DOMAIN=sudosci.test
|
||||||
|
REACT_APP_API_PATH=:8080/v1/api/
|
3
.env.production
Normal file
3
.env.production
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
REACT_APP_API_PROTO=https://
|
||||||
|
REACT_APP_API_DOMAIN=api.sudoscientist.com
|
||||||
|
REACT_APP_API_PATH=/v1/api/
|
|
@ -8,5 +8,6 @@ This project was started using create-react-app
|
||||||
|
|
||||||
```
|
```
|
||||||
npm install
|
npm install
|
||||||
|
update .env files
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
9713
package-lock.json
generated
9713
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,7 @@
|
||||||
"react-mde": "^7.6.2",
|
"react-mde": "^7.6.2",
|
||||||
"react-redux": "^7.1.1",
|
"react-redux": "^7.1.1",
|
||||||
"react-router-dom": "^5.1.2",
|
"react-router-dom": "^5.1.2",
|
||||||
"react-scripts": "3.0.0",
|
"react-scripts": "^3.3.0",
|
||||||
"redux": "^4.0.4",
|
"redux": "^4.0.4",
|
||||||
"redux-thunk": "^2.3.0",
|
"redux-thunk": "^2.3.0",
|
||||||
"universal-cookie": "^4.0.2"
|
"universal-cookie": "^4.0.2"
|
||||||
|
|
|
@ -20,9 +20,25 @@ export const fetchUserProfile = (user) => async (dispatch) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const userLogin = (username, password) => async (dispatch) => {
|
export const userLogin = (username, password) => async (dispatch) => {
|
||||||
const response = await sudoscientist.post('/auth/signin', {
|
const response = await sudoscientist.post('/auth/signin',{
|
||||||
username: username,
|
username: username,
|
||||||
password: password
|
password: password
|
||||||
|
})
|
||||||
|
if (response.status === 401) {
|
||||||
|
dispatch({ type: 'USER_LOGIN', payload: null })
|
||||||
|
}
|
||||||
|
if (response.status === 200) {
|
||||||
|
var v = document.cookie.match('(^|;) ?DataCookie=([^;]*)(;|$)');
|
||||||
|
var DataCookie = v ? v[2] : null;
|
||||||
|
dispatch({ type: 'USER_LOGIN', payload: DataCookie})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const userSignup = (username, password, email) => async (dispatch) => {
|
||||||
|
const response = await sudoscientist.post('/auth/register', {
|
||||||
|
username: username,
|
||||||
|
password: password,
|
||||||
|
email: email
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
export default axios.create({
|
export default axios.create({
|
||||||
baseURL: 'https://api.sudoscientist.com/v1/api/',
|
baseURL: process.env.REACT_APP_API_PROTO + process.env.REACT_APP_API_DOMAIN + process.env.REACT_APP_API_PATH,
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React, { Component } from 'react';
|
||||||
import Cookies from 'universal-cookie';
|
import Cookies from 'universal-cookie';
|
||||||
|
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { userLogin, loadCookieToState } from '../actions';
|
import { userLogin, userSignup, loadCookieToState } from '../actions';
|
||||||
|
|
||||||
class AuthMenu extends Component {
|
class AuthMenu extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
|
@ -18,6 +18,8 @@ class AuthMenu extends Component {
|
||||||
user_authed: true,
|
user_authed: true,
|
||||||
where_in_auth_menu: "loggedIn",
|
where_in_auth_menu: "loggedIn",
|
||||||
username: data.username,
|
username: data.username,
|
||||||
|
admin: data.admin,
|
||||||
|
verified: data.verified,
|
||||||
exp: data.exp,
|
exp: data.exp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,10 +107,18 @@ class AuthMenu extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCreateAccount() {
|
handleCreateAccount() {
|
||||||
|
this.props.userSignup(this.state.username, this.state.password, this.state.email)
|
||||||
|
.then(res => {
|
||||||
this.setState(state => ({
|
this.setState(state => ({
|
||||||
where_in_auth_menu: "requestPasswordForCreation",
|
where_in_auth_menu: "requestUsername",
|
||||||
auth_menu_visible: true,
|
auth_menu_visible: false,
|
||||||
}));
|
}))
|
||||||
|
this.props.close()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
authMenu() {
|
authMenu() {
|
||||||
|
@ -188,10 +198,21 @@ class AuthMenu extends Component {
|
||||||
case 'loggedIn':
|
case 'loggedIn':
|
||||||
return (
|
return (
|
||||||
<div className="ui menu dropdown" style={{display: "inline"}}>
|
<div className="ui menu dropdown" style={{display: "inline"}}>
|
||||||
|
{ this.state.admin &&
|
||||||
<div className="ui left icon input">
|
<div className="ui left icon input">
|
||||||
<i className="edit icon"></i>
|
<i className="edit icon"></i>
|
||||||
<button onClick={() => { document.location.href = "/newpost/"; }} className="fluid ui positive button">Create Post!</button>
|
<button onClick={() => { document.location.href = "/newpost/"; }} className="fluid ui positive button">Create Post!</button>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
<div className="ui left icon input">
|
||||||
|
<i className="sign-out icon"></i>
|
||||||
|
<button onClick={() => {
|
||||||
|
var cookies = new Cookies();
|
||||||
|
cookies.remove('DataCookie', { path: '/', domain: process.env.REACT_APP_API_DOMAIN });
|
||||||
|
window.location.reload();
|
||||||
|
}} className="fluid ui negative button">Sign Out</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
|
@ -208,5 +229,5 @@ class AuthMenu extends Component {
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
null,
|
null,
|
||||||
{ userLogin, loadCookieToState }
|
{ userLogin, userSignup, loadCookieToState }
|
||||||
)(AuthMenu);
|
)(AuthMenu);
|
||||||
|
|
|
@ -9,7 +9,6 @@ class NavBar extends Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
user_authed: false,
|
user_authed: false,
|
||||||
auth_menu_visible: false,
|
auth_menu_visible: false,
|
||||||
user_or_login: 'Login'
|
|
||||||
}
|
}
|
||||||
this.handleLoginDropdown = this.handleLoginDropdown.bind(this)
|
this.handleLoginDropdown = this.handleLoginDropdown.bind(this)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,12 @@ export default (state = initialState, action) => {
|
||||||
return {...state, ...action.data}
|
return {...state, ...action.data}
|
||||||
case 'USER_LOGIN':
|
case 'USER_LOGIN':
|
||||||
if (action.payload) {
|
if (action.payload) {
|
||||||
var data = JSON.parse(atob(action.payload.data.split('.')[1]))
|
var data = JSON.parse(atob(action.payload.split('.')[1]))
|
||||||
return {...state, ...{
|
return {...state, ...{
|
||||||
user_authed: true,
|
user_authed: true,
|
||||||
username: data.username,
|
username: data.username,
|
||||||
|
admin: data.admin,
|
||||||
|
verified: data.verified,
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
else return;
|
else return;
|
||||||
|
|
|
@ -5,3 +5,16 @@ I will primarily post about technology, personal projects, and other sudo-scient
|
||||||
|
|
||||||
The backend for this blog is written in golang and the source can be [found here](https://git.minhas.io/Asara/sudoscientist-go-backend).
|
The backend for this blog is written in golang and the source can be [found here](https://git.minhas.io/Asara/sudoscientist-go-backend).
|
||||||
The frontend for this blog is written using react-redux and can be [found here](https://git.minhas.io/Asara/sudoscientist-js-frontend).
|
The frontend for this blog is written using react-redux and can be [found here](https://git.minhas.io/Asara/sudoscientist-js-frontend).
|
||||||
|
|
||||||
|
|
||||||
|
## Connect with me
|
||||||
|
|
||||||
|
### Communication
|
||||||
|
Matrix: `@Asara:devvul.com`
|
||||||
|
|
||||||
|
Email: `amarpreet@minhas.io`
|
||||||
|
|
||||||
|
### Lightning Network
|
||||||
|
Pubkey: `0214b1f6b48998b9eb19d8a756af39a027202cecfe608450109465bbccf3bb74ed`
|
||||||
|
|
||||||
|
Node: `redwingxusk66wrrm4yyqyuyndvum4jsnloroxqmie6wv4wefadqgsqd.onion:9735`
|
||||||
|
|
Reference in a new issue