Fix up new user registration
This commit is contained in:
parent
c869ac07c3
commit
494b30b7c5
4 changed files with 42 additions and 7 deletions
|
@ -33,6 +33,21 @@ export const userLogin = (username, password) => async (dispatch) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
dispatch({ type: 'USER_LOGIN', payload: null })
|
||||||
|
}
|
||||||
|
if (response.status === 200) {
|
||||||
|
dispatch({ type: 'USER_LOGIN', payload: response })
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const loadCookieToState = (data) => async (dispatch) => {
|
export const loadCookieToState = (data) => async (dispatch) => {
|
||||||
dispatch({ type: 'LOAD_COOKIE', data })
|
dispatch({ type: 'LOAD_COOKIE', data })
|
||||||
};
|
};
|
||||||
|
|
|
@ -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) {
|
||||||
|
@ -105,10 +105,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: "loggedIn",
|
||||||
auth_menu_visible: true,
|
auth_menu_visible: false,
|
||||||
}));
|
}))
|
||||||
|
this.props.close()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
authMenu() {
|
authMenu() {
|
||||||
|
@ -208,5 +216,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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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