From 6e31e9dc124a30dc778a691810c79d1539ed0e67 Mon Sep 17 00:00:00 2001 From: BIT Student Date: Thu, 23 Nov 2017 18:10:05 +0100 Subject: [PATCH 1/2] logout pro --- src/components/app.js | 4 ++-- src/components/loginComponents/register.js | 26 ++-------------------- src/components/navMenu.js | 15 ++++++++----- src/services/authenticationService.js | 16 ++++++------- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/components/app.js b/src/components/app.js index 782183b..1580a56 100644 --- a/src/components/app.js +++ b/src/components/app.js @@ -10,13 +10,13 @@ class App extends React.Component { this.authenticationService = new AuthenticationService(); } - + render() { if (this.authenticationService.isAuthenticated()) { return (
- +
); } diff --git a/src/components/loginComponents/register.js b/src/components/loginComponents/register.js index a0d15e3..dfe478b 100644 --- a/src/components/loginComponents/register.js +++ b/src/components/loginComponents/register.js @@ -29,9 +29,7 @@ class Register extends React.Component { this.setState({ [event.target.name]: event.target.value, badName: "", - badUsername: "", - badEmail: "", badPass: "", badSecondPass: "", @@ -39,10 +37,8 @@ class Register extends React.Component { }); } - serverErrorHandler(e) { - this.setState({ badUsername: e.response.data.error.message }); @@ -52,10 +48,8 @@ class Register extends React.Component { const { username, name, email, password1, password2 } = this.state; event.preventDefault(); - if (name === "") { this.setState({ badName: "This field is required" }); return; } if (username === "") { this.setState({ badUsername: "This field is required" }); return; } - if (!validateEmail(email)) { this.setState({ badEmail: "Email address is bad!" }); return; } if (password1.length < 6) { this.setState({ badPass: "Password must be at least 6 characters long" }); return; } if (password1 === password2) { @@ -78,7 +72,6 @@ class Register extends React.Component { const { name, email, password1, password2, username, badEmail, badPass, badSecondPass, badUsername, badName } = this.state; - return (
@@ -86,7 +79,6 @@ class Register extends React.Component {

REGISTER TO BITBOOK

-

Beogradski institut za tehnologiju – BIT je škola za programiranje osnovana u Beogradu, s ciljem da svoje polaznike uči praktičnim i primenljivim znanjima u IT industriji. Tehnički deo programa je FrontEnd Stack, najčešće tražen od strane poslodavaca. Pored tehničkog obrazovanja, u BITu se uči i kako funkcioniše IT industrija i kako pronaći svoje mesto u njoj. @@ -124,23 +116,9 @@ class Register extends React.Component {

{badSecondPass}
- - -
-
- - -
-
{badPass}
-
- -
-
{badSecondPass}
- -
- - + + diff --git a/src/components/navMenu.js b/src/components/navMenu.js index a9216ec..3b84549 100644 --- a/src/components/navMenu.js +++ b/src/components/navMenu.js @@ -1,15 +1,20 @@ import React from "react"; import { Link } from "react-router-dom"; import MainFeedPage from "./mainFeedPage"; +import comObj from "../services/communicationService"; // import PostPage from "./postPage"; import ProfilePage from "./profilePage"; + class NavMenu extends React.Component { constructor(props) { super(props); } - + logout() { + comObj.clearID(); + + } render() { @@ -24,21 +29,21 @@ class NavMenu extends React.Component { diff --git a/src/services/authenticationService.js b/src/services/authenticationService.js index 46e63b6..d9132b4 100644 --- a/src/services/authenticationService.js +++ b/src/services/authenticationService.js @@ -2,10 +2,10 @@ import comObj from "./communicationService"; import { redirect } from "../components/redirect"; class AuthenticationService { constructor() { - + this.bindThisAndThats(); } - bindThisAndThats(){ + bindThisAndThats() { this.login = this.login.bind(this); this.register = this.register.bind(this); this.successLogin = this.successLogin.bind(this); @@ -14,7 +14,7 @@ class AuthenticationService { successLogin(a) { comObj.setID(a.sessionId); console.log(a); - // redirect("/"); + redirect("/"); } failLogin(a) { console.log("Sranje si!"); @@ -23,15 +23,15 @@ class AuthenticationService { login(dataObj) { if (comObj.getID()) { alert("Vec postoji ulogovan korisnik"); return; } comObj.post("login", dataObj, this.successLogin, this.failLogin); - + } - successRegister(a){ + successRegister(a) { redirect("/"); - + } - failRegister(error){ + failRegister(error) { console.log(error.response.data.error.message); - + } register(dataObj, callbackFail) { comObj.post("register", dataObj, this.succesRegister, callbackFail); From 45c0f9d4f6d9316e8c5d4f10865c940ea876da41 Mon Sep 17 00:00:00 2001 From: BIT Student Date: Fri, 24 Nov 2017 10:18:14 +0100 Subject: [PATCH 2/2] data service done --- src/components/profilePage.js | 2 ++ src/services/dataService.js | 11 ++++++++++- src/services/{dataServiceDTO.js => profileDTO.js} | 0 3 files changed, 12 insertions(+), 1 deletion(-) rename src/services/{dataServiceDTO.js => profileDTO.js} (100%) diff --git a/src/components/profilePage.js b/src/components/profilePage.js index 6752de6..e1ec67c 100644 --- a/src/components/profilePage.js +++ b/src/components/profilePage.js @@ -1,4 +1,5 @@ import React from "react"; +import dataObj from "../services/dataService"; // MainPage = Feed Page class ProfilePage extends React.Component { @@ -7,6 +8,7 @@ class ProfilePage extends React.Component { } render() { + dataObj.getProfile(); return (
diff --git a/src/services/dataService.js b/src/services/dataService.js index 10d3f45..7f68410 100644 --- a/src/services/dataService.js +++ b/src/services/dataService.js @@ -1,6 +1,15 @@ import comObj from "./communicationService"; +import ProfileDTO from "./profileDTO"; class DataService { constructor(){ } -} \ No newline at end of file + + getProfile(callback, failCallback){ + comObj.get("profile", a=> callback(new ProfileDTO(a)), a=> failCallback(a)); + } +} + +const dataObj = new DataService(); + +export default dataObj; \ No newline at end of file diff --git a/src/services/dataServiceDTO.js b/src/services/profileDTO.js similarity index 100% rename from src/services/dataServiceDTO.js rename to src/services/profileDTO.js