Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/account #12

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,496 changes: 4,496 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "socialites",
"version": "1.0.0",
"description": "The application uses: - `maven` to build the project - `thymeleaf` for templating - `flyway` to manage `postgres` db migrations - `selenium` for feature testing - `faker` to generate fake names for testing - `junit4` for unit testing - `spring-security` for authentication and user management",
"main": "index.js",
"dependencies": {
"@relume_io/relume-tailwind": "^0.2.0",
"@relume_io/relume-ui": "^0.2.2",
"autoprefixer": "^10.4.19",
"tailwindcss": "^3.4.4"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"postcss-cli": "^11.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import java.util.HashSet;
import java.util.Set;

@EnableWebSecurity

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.makersacademy.acebook.controller;

import com.makersacademy.acebook.model.Event;
import com.makersacademy.acebook.model.User;
import com.makersacademy.acebook.repository.EventRepository;
import com.makersacademy.acebook.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

@CrossOrigin
@Controller
public class LandingPageController {

@Autowired
private UserRepository userRepository;

@Autowired
private EventRepository eventRepository;

@GetMapping("/")
public String listUsersAndEvents(Model model) {
List<User> users = userRepository.findAll();
List<Event> events = StreamSupport.stream(eventRepository.findAll().spliterator(), false)
.collect(Collectors.toList());
model.addAttribute("users", users);
model.addAttribute("events", events);
return "landingpage";
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
package com.makersacademy.acebook.controller;

import com.makersacademy.acebook.model.User;
import com.makersacademy.acebook.repository.UserRepository;
import com.makersacademy.acebook.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
@CrossOrigin
@Controller
@RequestMapping("/account")
public class UserController {

@Autowired
private UserRepository userRepository;
private UserService userService;

// @GetMapping("/")
// public String listUsers(Model model) {
// List<User> users = userRepository.findAll();
// model.addAttribute("users", users);
// return "users";
// }
@GetMapping
public String accountPage(@AuthenticationPrincipal UserDetails currentUser, Model model) {
User user = userService.findByUsername(currentUser.getUsername());
model.addAttribute("user", user);
return "account";
}

@PostMapping
public String updateAccount(@AuthenticationPrincipal UserDetails currentUser, User updatedUser) {
User user = userService.findByUsername(currentUser.getUsername());
user.setUsername(updatedUser.getUsername());
if (!updatedUser.getPassword().isEmpty()) {
user.setPassword(updatedUser.getPassword()); // The password will be encoded in the service
}
user.setEmail(updatedUser.getEmail());
user.setProfilePictureUrl(updatedUser.getProfilePictureUrl());
userService.save(user);
return "redirect:/account";
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import com.makersacademy.acebook.model.ThirdPartyEvent;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.DefaultAsyncHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public UserService(UserRepository userRepository) {
}

public void save(User user) {
// Do not encode the password here
userRepository.save(user);
}

Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/templates/account.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Account Page</title>
</head>
<body>
<h1>Account Information</h1>
<form th:action="@{/account}" th:object="${user}" method="post">
<div>
<label>Username:</label>
<input type="text" th:field="*{username}" />
</div>
<div>
<label>Password:</label>
<input type="password" th:field="*{password}" placeholder="Leave blank to keep current password"/>
</div>
<div>
<label>Email:</label>
<input type="email" th:field="*{email}" />
</div>
<div>
<label>Profile Picture URL:</label>
<input type="text" th:field="*{profilePictureUrl}" />
</div>
<div>
<button type="submit">Update</button>
</div>
</form>
</body>
</html>
27 changes: 27 additions & 0 deletions src/main/resources/templates/landingpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>User List</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>

</head>
<body>
<div th:replace="fragments/nav :: navbar"></div>


<section class="px-[5%] py-16 md:py-24 lg:py-28">
<h1 class="text-3xl font-bold md:text-7xl lg:text-8xl mb-8">Events</h1>
<ul>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4">
<li th:each="event : ${events}" class="mb-4">
<div class="text-lg"><strong>Title:</strong> <span th:text="${event.title}"></span></div>
<div class="text-lg"><strong>Description:</strong> <span th:text="${event.description}"></span></div>
<div class="text-lg"><strong>Date:</strong> <span th:text="${#dates.format(event.scheduledDate, 'yyyy-MM-dd')}"></span></div>
<div class="text-lg"><strong>Time:</strong> <span th:text="${event.scheduledStartTime}"></span></div>
</li>
</div>
</ul>
</section>
</body>
</html>
37 changes: 0 additions & 37 deletions src/main/resources/templates/users.html

This file was deleted.

Loading