Skip to content

Commit

Permalink
Merge pull request #44 from wethmiranasinghe/main
Browse files Browse the repository at this point in the history
Logged in User Name Updated
  • Loading branch information
wethmiranasinghe authored Jul 13, 2024
2 parents 99dac52 + 0e51d22 commit 6357b15
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
17 changes: 2 additions & 15 deletions back-end/src/main/java/com/example/demo/registration/LoginDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/**
* Data Transfer Object (DTO) for handling login credentials.
*/
@Setter
@Getter
@Data
// Login Data Transfer Object
public class LoginDTO {
Expand All @@ -22,20 +24,5 @@ public LoginDTO(String email, String password) {
this.password = password;
}

public void setEmail(String email) {
this.email = email;
}

public String getEmail() {
return email;
}

public void setPassword(String password) {
this.password = password;
}

public String getPassword() {
return password;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
public class LoginResponse {
private String token;
private String message;
private String firstName;
private String lastName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,21 @@ public LoginResponse loginUser(LoginDTO loginDTO) {

if (optionalAppUser.isEmpty()) {
System.out.println("User not found with email: " + loginDTO.getEmail()); // Debug log
return new LoginResponse(null, "Email does not exits");
return new LoginResponse(null, "Email does not exits", null, null);
}

AppUser appUser = optionalAppUser.get();

System.out.println("User found, comparing passwords"); // Debug log

if (passwordEncoder.matches(loginDTO.getPassword(), appUser.getPassword())) {
String firstName = appUser.getFirstName();
String lastName = appUser.getLastName();
System.out.println("Password match, login success"); // Debug log
return new LoginResponse("dummy-token", "Login Success");
return new LoginResponse("dummy-token", "Login Success", firstName, lastName);
} else {
System.out.println("Password mismatch"); // Debug log
return new LoginResponse(null, "Password does not match");
return new LoginResponse(null, "Password does not match", null, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authz -> authz
.requestMatchers("/api/v*/registration/**", "/api/v1/news/**", "/api/v1/gallery/**", "/api/v1/files/**" )
.requestMatchers("/api/v*/registration/**", "/api/v*/news/**", "/api/v*/gallery/**", "/api/v*/files/**", "/api/v*/login/**")
.permitAll()
.anyRequest().authenticated()
)
Expand Down
8 changes: 6 additions & 2 deletions front-end/src/Pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cylcleLogo from '../assets/CYCLE-logo.png';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons'; // Import specific icons

export let loggedInUser=false;
export let loggedInUser = { isLoggedIn: false, firstName: '', lastName: '' };

function Login() {
const [email, setEmail] = useState("");
Expand All @@ -30,7 +30,11 @@ function Login() {
if (res.data.message === "Email does not exits") {
alert("Not a registered user. Email not found");
} else if (res.data.message === "Login Success") {
loggedInUser=true;
loggedInUser={
isLoggedIn: true,
firstName: res.data.firstName,
lastName: res.data.lastName
};
navigate('/');
} else {
alert("Login Failed! Password does not match!");
Expand Down
5 changes: 1 addition & 4 deletions front-end/src/components/Header.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
color: white;
text-decoration: none;
}
a:hover {
color: white;
}

h1 {
font-family:'Times New Roman', Times, serif;
Expand Down Expand Up @@ -364,7 +361,7 @@
border-radius: 50%;
padding:10px;
margin: 5px;
transition: transform 0.5s;
transition: transform 0.8s;
}

.userAccountContent :hover {
Expand Down
18 changes: 9 additions & 9 deletions front-end/src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, {useState, useEffect} from 'react';
import {Link, Outlet, useLocation} from 'react-router-dom'; // //Add page routing using router dom
import {Link, useLocation} from 'react-router-dom'; // //Add page routing using router dom

import Switch from "react-switch";
import cylcleLogo from '../assets/CYCLE-logo.png';
import erasmusLogo from '../assets/erasmus-plus-logo.jpg';
import profilePic from '../assets/ProPic_UJ.jpg' //TODO:Take from back end
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faMessage, faBell, faAngleRight, faUser, faFile,faCalendarDays } from '@fortawesome/free-solid-svg-icons';
import { faMessage, faBell, faAngleRight, faUser, faUserCircle, faFile,faCalendarDays } from '@fortawesome/free-solid-svg-icons';
import {loggedInUser} from '../Pages/Login'

function Header(){
Expand Down Expand Up @@ -37,13 +36,14 @@ function Header(){
const [showChat, setShowChat] = useState(false);
const [showNotifications, setShowNotifications] = useState(false);
const [showAccount, setShowAccount] = useState(false);
const [loggedInUserState,setLoggedInUser] = useState(false) // if a user has logged in
const [loggedInUserState,setLoggedInUser] = useState(loggedInUser.isLoggedIn); // if a user has logged in
// Update the visibility of the login button based on the current location
//TODO: if no logged user only

useEffect(() => {
if (location.pathname === '/login' || loggedInUser) {
if (location.pathname === '/login' || loggedInUser.isLoggedIn) {
setIsVisible(false);
if (loggedInUser) {
if (loggedInUser.isLoggedIn) {
setLoggedInUser(true)
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ function Header(){
</li>
<li onClick={showChatInterface}><FontAwesomeIcon icon={faMessage}/></li>
<li onClick={showNotificationInterface}><FontAwesomeIcon icon={faBell}/></li>
<li onClick={showAccountInterface}><img src={profilePic}></img></li>
<li onClick={showAccountInterface}><FontAwesomeIcon icon={faUserCircle}/></li>
</ul>
</div>

Expand All @@ -115,8 +115,8 @@ function Header(){
<div class= {showAccount ? "userAccount-Open" : "userAccount-Close"}>

<div className="userAccountInfo">
<img src={profilePic}></img>
<h3>Dr. Upul Jayasinghe</h3>
<FontAwesomeIcon icon={faUserCircle} size="3x" style={{ marginRight: '10px'}}/>
<h3> {loggedInUser.firstName} {loggedInUser.lastName}</h3>
</div>

<hr></hr>
Expand Down

0 comments on commit 6357b15

Please sign in to comment.