1
0
Fork 0

Merge branch 'fix_register' of Asara/sudoscientist-js-frontend into master

This commit is contained in:
Amarpreet Minhas 2020-01-25 18:27:42 -05:00 committed by Gogs
commit 58a8fa234a
11 changed files with 5395 additions and 4400 deletions

3
.env.development Normal file
View 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
View file

@ -0,0 +1,3 @@
REACT_APP_API_PROTO=https://
REACT_APP_API_DOMAIN=api.sudoscientist.com
REACT_APP_API_PATH=/v1/api/

View file

@ -8,5 +8,6 @@ This project was started using create-react-app
```
npm install
update .env files
npm start
```

9713
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,7 @@
"react-mde": "^7.6.2",
"react-redux": "^7.1.1",
"react-router-dom": "^5.1.2",
"react-scripts": "3.0.0",
"react-scripts": "^3.3.0",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0",
"universal-cookie": "^4.0.2"

View file

@ -23,6 +23,22 @@ export const userLogin = (username, password) => async (dispatch) => {
const response = await sudoscientist.post('/auth/signin',{
username: username,
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) {

View file

@ -1,6 +1,6 @@
import axios from 'axios';
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
});

View file

@ -2,7 +2,7 @@ import React, { Component } from 'react';
import Cookies from 'universal-cookie';
import { connect } from 'react-redux';
import { userLogin, loadCookieToState } from '../actions';
import { userLogin, userSignup, loadCookieToState } from '../actions';
class AuthMenu extends Component {
constructor (props) {
@ -18,6 +18,8 @@ class AuthMenu extends Component {
user_authed: true,
where_in_auth_menu: "loggedIn",
username: data.username,
admin: data.admin,
verified: data.verified,
exp: data.exp,
}
}
@ -105,10 +107,18 @@ class AuthMenu extends Component {
}
handleCreateAccount() {
this.props.userSignup(this.state.username, this.state.password, this.state.email)
.then(res => {
this.setState(state => ({
where_in_auth_menu: "requestPasswordForCreation",
auth_menu_visible: true,
}));
where_in_auth_menu: "requestUsername",
auth_menu_visible: false,
}))
this.props.close()
}
)
.catch(err => {
console.log(err);
})
}
authMenu() {
@ -188,10 +198,21 @@ class AuthMenu extends Component {
case 'loggedIn':
return (
<div className="ui menu dropdown" style={{display: "inline"}}>
{ this.state.admin &&
<div className="ui left icon input">
<i className="edit icon"></i>
<button onClick={() => { document.location.href = "/newpost/"; }} className="fluid ui positive button">Create Post!</button>
</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>
)
default:
@ -208,5 +229,5 @@ class AuthMenu extends Component {
export default connect(
null,
{ userLogin, loadCookieToState }
{ userLogin, userSignup, loadCookieToState }
)(AuthMenu);

View file

@ -9,7 +9,6 @@ class NavBar extends Component {
this.state = {
user_authed: false,
auth_menu_visible: false,
user_or_login: 'Login'
}
this.handleLoginDropdown = this.handleLoginDropdown.bind(this)
}

View file

@ -11,10 +11,12 @@ export default (state = initialState, action) => {
return {...state, ...action.data}
case 'USER_LOGIN':
if (action.payload) {
var data = JSON.parse(atob(action.payload.data.split('.')[1]))
var data = JSON.parse(atob(action.payload.split('.')[1]))
return {...state, ...{
user_authed: true,
username: data.username,
admin: data.admin,
verified: data.verified,
}}
}
else return;

View file

@ -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 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`