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) => {
|
||||
dispatch({ type: 'LOAD_COOKIE', data })
|
||||
};
|
||||
|
|
|
@ -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) {
|
||||
|
@ -105,10 +105,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: "loggedIn",
|
||||
auth_menu_visible: false,
|
||||
}))
|
||||
this.props.close()
|
||||
}
|
||||
)
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
|
||||
authMenu() {
|
||||
|
@ -208,5 +216,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)
|
||||
}
|
||||
|
|
|
@ -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