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
|
||||
update .env files
|
||||
npm start
|
||||
```
|
||||
|
|
9715
package-lock.json
generated
9715
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -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"
|
||||
|
|
|
@ -20,9 +20,25 @@ export const fetchUserProfile = (user) => 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,
|
||||
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) {
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
|
@ -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.setState(state => ({
|
||||
where_in_auth_menu: "requestPasswordForCreation",
|
||||
auth_menu_visible: true,
|
||||
}));
|
||||
this.props.userSignup(this.state.username, this.state.password, this.state.email)
|
||||
.then(res => {
|
||||
this.setState(state => ({
|
||||
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);
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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`
|
||||
|
|
Reference in a new issue