From 101dc0504d704715775e3306991b9e79bddde7ab Mon Sep 17 00:00:00 2001 From: Antti Pilto Date: Sat, 13 Aug 2016 19:48:09 +0300 Subject: [PATCH] login feature removal --- README.md | 5 +- package.json | 3 +- src/components/App/App.jsx | 31 +------- .../ChooseCharacters/CharacterGroup.jsx | 1 - .../ChooseCharacters/ChooseCharacters.jsx | 6 +- .../GameContainer/GameContainer.jsx | 2 - src/components/Navbar/Navbar.jsx | 12 --- src/utils/AuthService.js | 75 ------------------- src/utils/jwtHelper.js | 21 ------ 9 files changed, 8 insertions(+), 148 deletions(-) delete mode 100644 src/utils/AuthService.js delete mode 100644 src/utils/jwtHelper.js diff --git a/README.md b/README.md index 8e41478..9fce9bb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# Nothing interesting here -Early alpha of Kana Quiz remade with React.js and Auth0 +# Kana Quiz 2 +Kana Quiz remade with React.js. +See live at http://simplemedia.org/kana/ diff --git a/package.json b/package.json index 51d3d45..93dee9f 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,9 @@ "webpack-dev-server": "^1.14.1" }, "dependencies": { - "auth0-lock": "^10.0.0", - "jwt-decode": "^2.1.0", "postcss": "^5.1.0", "react": "^15.2.1", + "react-addons-css-transition-group": "^15.3.0", "react-dom": "^15.2.1", "react-toggle-switch": "^2.1.2" } diff --git a/src/components/App/App.jsx b/src/components/App/App.jsx index ac8f7ab..e6bb4e1 100644 --- a/src/components/App/App.jsx +++ b/src/components/App/App.jsx @@ -1,38 +1,21 @@ import React, { Component } from 'react'; -import AuthService from '../../utils/AuthService' import './App.scss'; import Navbar from '../Navbar/Navbar'; import GameContainer from '../GameContainer/GameContainer'; import { removeHash } from '../../data/helperFuncs'; const options = {}; -const auth = new AuthService(__AUTH0_CLIENT_ID__, __AUTH0_DOMAIN__, options); class App extends Component { constructor(props) { super(props); this.state = { - isAuthenticated: this.isAuthenticated(), gameState: 'chooseCharacters' } - auth.on('profile_updated', (newProfile) => { - this.setState({isAuthenticated: this.isAuthenticated()}); - }) - this.logout = this.logout.bind(this); - this.getNickName = this.getNickName.bind(this); this.startGame = this.startGame.bind(this); this.endGame = this.endGame.bind(this); } - isAuthenticated() { - removeHash(); - return auth.loggedIn() && auth.getProfile() && auth.getProfile().hasOwnProperty('user_id'); - } - - getNickName() { - return auth.loggedIn() && auth.getProfile() && auth.getProfile().hasOwnProperty('nickname')?auth.getProfile().nickname:''; - } - startGame() { this.setState({gameState: 'game'}); } @@ -41,34 +24,22 @@ class App extends Component { this.setState({gameState: 'chooseCharacters'}); } - logout() { - auth.logout(); - this.setState({isAuthenticated: this.isAuthenticated()}); - } - render() { - let loginButton = !this.state.isAuthenticated ? -

Log in to save your progress!

: ''; return (
-
-
{loginButton}
) } diff --git a/src/components/ChooseCharacters/CharacterGroup.jsx b/src/components/ChooseCharacters/CharacterGroup.jsx index 3a48ba9..bc807aa 100644 --- a/src/components/ChooseCharacters/CharacterGroup.jsx +++ b/src/components/ChooseCharacters/CharacterGroup.jsx @@ -55,7 +55,6 @@ class CharacterGroup extends Component { {this.state.shownChars} - 0 % ); } diff --git a/src/components/ChooseCharacters/ChooseCharacters.jsx b/src/components/ChooseCharacters/ChooseCharacters.jsx index 2572453..5a9fc74 100644 --- a/src/components/ChooseCharacters/ChooseCharacters.jsx +++ b/src/components/ChooseCharacters/ChooseCharacters.jsx @@ -96,7 +96,7 @@ class ChooseCharacters extends Component {
-

Welcome to Kana Quiz{this.props.isAuthenticated && this.props.nickName !== '' && typeof this.props.nickName !== 'undefined'?', '+this.props.nickName:''}!

+

Welcome to Kana Quiz!

Please choose the groups of characters that you'd like to be studying.

@@ -105,7 +105,7 @@ class ChooseCharacters extends Component {
-
Hiragana · ひらがなProgress
+
Hiragana · ひらがな
{this.showGroupRows('hiragana')}
@@ -116,7 +116,7 @@ class ChooseCharacters extends Component {
-
Katakana · カタカナProgress
+
Katakana · カタカナ
{this.showGroupRows('katakana')}
diff --git a/src/components/GameContainer/GameContainer.jsx b/src/components/GameContainer/GameContainer.jsx index a7fd99c..c7ba1da 100644 --- a/src/components/GameContainer/GameContainer.jsx +++ b/src/components/GameContainer/GameContainer.jsx @@ -40,8 +40,6 @@ class GameContainer extends Component { { this.props.gameState==='chooseCharacters' ? Back to menu } - let profileButton = this.props.isAuthenticated ? - Log out : - Log in; return (
) } } - // - -//
{this.props.profile.hasOwnProperty('user_id')?this.props.profile.name+' is logged in':'not logged in'}
- // export default Navbar; \ No newline at end of file diff --git a/src/utils/AuthService.js b/src/utils/AuthService.js deleted file mode 100644 index 8adfdce..0000000 --- a/src/utils/AuthService.js +++ /dev/null @@ -1,75 +0,0 @@ -import { EventEmitter } from 'events' -import { isTokenExpired } from './jwtHelper' -import Auth0Lock from 'auth0-lock' - -export default class AuthService extends EventEmitter { - constructor(clientId, domain, options) { - super() - // Configure Auth0 - this.lock = new Auth0Lock(clientId, domain, options) - // Add callback for lock `authenticated` event - this.lock.on('authenticated', this._doAuthentication.bind(this)) - // Add callback for lock `authorization_error` event - this.lock.on('authorization_error', this._authorizationError.bind(this)) - // binds login functions to keep this context - this.login = this.login.bind(this) - } - - _doAuthentication(authResult){ - // Saves the user token - this.setToken(authResult.idToken) - // Async loads the user profile data - this.lock.getProfile(authResult.idToken, (error, profile) => { - if (error) { - console.log('Error loading the Profile', error) - } else { - this.setProfile(profile) - } - }) - } - - _authorizationError(error){ - // Unexpected authentication error - console.log('Authentication Error', error) - } - - login() { - // Call the show method to display the widget. - this.lock.show() - } - - loggedIn(){ - // Checks if there is a saved token and it's still valid - const token = this.getToken() - return !!token && !isTokenExpired(token) - } - - setProfile(profile){ - // Saves profile data to localStorage - localStorage.setItem('profile', JSON.stringify(profile)) - // Triggers profile_updated event to update the UI - this.emit('profile_updated', profile) - } - - getProfile(){ - // Retrieves the profile data from localStorage - const profile = localStorage.getItem('profile') - return profile ? JSON.parse(localStorage.profile) : {} - } - - setToken(idToken){ - // Saves user token to localStorage - localStorage.setItem('id_token', idToken) - } - - getToken(){ - // Retrieves the user token from localStorage - return localStorage.getItem('id_token') - } - - logout(){ - // Clear user token and profile data from localStorage - localStorage.removeItem('id_token'); - localStorage.removeItem('profile'); - } -} diff --git a/src/utils/jwtHelper.js b/src/utils/jwtHelper.js deleted file mode 100644 index 7440b1c..0000000 --- a/src/utils/jwtHelper.js +++ /dev/null @@ -1,21 +0,0 @@ -import decode from 'jwt-decode'; - -export function getTokenExpirationDate(token){ - const decoded = decode(token) - if(!decoded.exp) { - return null - } - - const date = new Date(0) // The 0 here is the key, which sets the date to the epoch - date.setUTCSeconds(decoded.exp) - return date -} - -export function isTokenExpired(token){ - const date = getTokenExpirationDate(token) - const offsetSeconds = 60*60*24*7 - if (date === null) { - return false - } - return !(date.valueOf() > (new Date().valueOf() + (offsetSeconds * 1000))) -}