From 494b30b7c5f9972cafd63fa1797b6e36c72794fa Mon Sep 17 00:00:00 2001 From: Asara Date: Sun, 19 Jan 2020 00:33:49 -0500 Subject: [PATCH] Fix up new user registration --- src/actions/index.js | 15 +++++++++++++++ src/components/AuthMenu.js | 20 ++++++++++++++------ src/components/NavBar.js | 1 - src/static/about.md | 13 +++++++++++++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/actions/index.js b/src/actions/index.js index 66b71ab..108b5cc 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -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 }) }; diff --git a/src/components/AuthMenu.js b/src/components/AuthMenu.js index 72e358d..33de590 100644 --- a/src/components/AuthMenu.js +++ b/src/components/AuthMenu.js @@ -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.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: "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); diff --git a/src/components/NavBar.js b/src/components/NavBar.js index 9819c5c..05b32d9 100644 --- a/src/components/NavBar.js +++ b/src/components/NavBar.js @@ -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) } diff --git a/src/static/about.md b/src/static/about.md index 6941316..d7b2d5e 100644 --- a/src/static/about.md +++ b/src/static/about.md @@ -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`