Skip to content

Commit

Permalink
feat: basic profile display
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzow committed Mar 4, 2023
1 parent 690f7af commit 600ef2f
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
package net.daw.alist.controllers;

import net.daw.alist.models.User;
import net.daw.alist.repositories.UserRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Optional;

@Controller
public class ProfileController {

@GetMapping("/profile")
public String profile() {
return "profile";
@Autowired
UserRepository userRepository;

@GetMapping("/user/{username}")
public String profile(Model model, HttpServletResponse httpResponse, @PathVariable String username) throws IOException {
Optional<User> user = userRepository.findByUsername(username);
if (user.isPresent()) {
model.addAttribute("user", user.get());
return "profile";
}
httpResponse.sendRedirect("/error");
return "error";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.http.HttpResponse;
import java.sql.SQLException;
import java.util.Optional;

@AllArgsConstructor
Expand All @@ -25,7 +26,7 @@ public String register() {
}

@PostMapping("/register")
public String registerPost(Model model, RegistrationRequest request) {
public String registerPost(Model model, RegistrationRequest request) throws SQLException, IOException {
String result = registrationService.register(request);
if (result.equals("Success")){
model.addAttribute("notVerified", true);
Expand Down
5 changes: 4 additions & 1 deletion back/src/main/java/net/daw/alist/models/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public void setContent(String content) {
}

public void setImage(String imagePath) throws IOException, SQLException {
if (imagePath == null) {
imagePath = "static/images/notFound.jpg";
}
this.image = pathToImage(imagePath);
this.imagePath = imagePath;
this.imagePath = imagePath.replace("static", "");
}

public Date getDate() {
Expand Down
5 changes: 4 additions & 1 deletion back/src/main/java/net/daw/alist/models/PostItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ public void setDescription(String description) {
}

public void setImage(String imagePath) throws IOException, SQLException {
if (imagePath == null) {
imagePath = "static/images/notFound.jpg";
}
this.image = pathToImage(imagePath);
this.imagePath = imagePath;
this.imagePath = imagePath.replace("static", "");
}

public String getDescription() {
Expand Down
19 changes: 16 additions & 3 deletions back/src/main/java/net/daw/alist/models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public void setLocked(boolean locked) {
this.locked = locked;
}

private String bio = "";

@Lob
@JsonIgnore
private Blob image;
Expand All @@ -70,15 +72,15 @@ public User(
String password,
String email,
UserRole role
) {
) throws SQLException, IOException {
this.date = new Date();
this.username = username;
this.password = password;
this.email = email;
this.role = role;
enabled = false; //Change this if you want to turn off email verification
locked = false;
// TODO: default image
setImage("static/images/defaultProfilePicture.jpg");
if (role.equals(UserRole.ADMIN)) {
enabled = true;
}
Expand All @@ -100,9 +102,16 @@ public void setRole(UserRole role) {
this.role = role;
}

public void setBio(String bio) {
this.bio = bio;
}

public void setImage(String imagePath) throws IOException, SQLException {
if (imagePath == null) {
imagePath = "static/images/notFound.jpg";
}
this.image = pathToImage(imagePath);
this.imagePath = imagePath;
this.imagePath = imagePath.replace("static", "");
}

public void setFollows(List<User> follows) {
Expand Down Expand Up @@ -143,6 +152,10 @@ public UserRole getRole() {
return role;
}

public String getBio() {
return bio;
}

public Blob getImage() {
return image;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ public void init() throws IOException, SQLException {

User cr7Lover = new User("CR7Lover", passwordEncoder.encode("1234"), "cr7@alist.com", USER);
cr7Lover.setImage("static/images/example/cr7_2.jpg");
cr7Lover.setBio("CR7 BEST PLAYER IN THE WORLD CR7 BEST PLAYER IN THE WORLD CR7 BEST PLAYER IN THE WORLD");
User manolo = new User("Manolo", passwordEncoder.encode("1234"), "manolo@alist.com", USER);
manolo.setImage("static/images/example/manolo.jpg");
manolo.setBio("IM MANOLO AND I LIKE MACARONI");
User peepo = new User("Peepo", passwordEncoder.encode("1234"), "peepo@alist.com", USER);
peepo.setImage("static/images/example/peepo.jpg");
peepo.setBio("Bedge");
User shanks = new User("Shanks", passwordEncoder.encode("1234"), "shanks@alist.com", USER);
shanks.setImage("static/images/example/shanks.jpg");
shanks.setBio("PEAK PIECE");
User admin = new User("admin", passwordEncoder.encode("1234"), "admin@alist.com", ADMIN);
admin.setImage("static/images/example/admin.jpg");
admin.setBio("banned :)");

userRepository.save(peepo);
userRepository.save(shanks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.sql.SQLException;
import java.time.LocalDateTime;

@Service
Expand All @@ -20,15 +22,15 @@ public class RegistrationService {
private final ConfirmationTokenService confirmationTokenService;
private final EmailService emailSender;

public String register(RegistrationRequest request) {
public String register(RegistrationRequest request) throws SQLException, IOException {

String token = userService.register(
new User(
request.getUsername(),
request.getPassword(),
request.getEmail(),
UserRole.USER
)
new User(
request.getUsername(),
request.getPassword(),
request.getEmail(),
UserRole.USER
)
);

if(token.startsWith("token=")){
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions back/src/main/resources/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"
integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w=="
crossorigin="anonymous" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="styles/navbar.css">
<script src="scripts/bootstrap/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" type="text/css" href="/styles/navbar.css">
<script src="/scripts/bootstrap/bootstrap.bundle.min.js"></script>
</head>

<body>
<nav class="navbar navbar-expand-lg bg-black">
<div class="d-none d-md-block container-fluid">
<div class="d-flex justify-content-evenly align-items-center m-auto">
<a class="navbar-brand" href="/">
<img src="images/alistLogo.svg" alt="" width="80" height="30">
<img src="/images/alistLogo.svg" alt="" width="80" height="30">
</a>
<a>
<i class="fa-regular fa-compass fa-xl"></i>
Expand All @@ -37,7 +37,7 @@
<div class="hamburger-container d-sm-block d-md-none">
<div class="d-flex justify-content-end align-items-center">
<a class="navbar-brand ps-2 m-auto flex-grow-1" href="/">
<img class="" src="images/alistLogo.svg" alt="Alist logo" width="101.33 " height="38">
<img class="" src="/images/alistLogo.svg" alt="Alist logo" width="101.33 " height="38">
</a>
<div class="collapse no-transition" id="collapseNav">
<div class="icon-container d-flex justify-content-evenly align-items-center ps-2 pe-2 gap-3">
Expand Down
25 changes: 9 additions & 16 deletions back/src/main/resources/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="images/favicon.ico">
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"
integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w=="
crossorigin="anonymous" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="styles/bootstrap/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="styles/styles.css">
<link rel="stylesheet" type="text/css" href="styles/profile.css">
<link rel="stylesheet" type="text/css" href="/styles/bootstrap/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/styles/styles.css">
<link rel="stylesheet" type="text/css" href="/styles/profile.css">
<title>Alist | Profile</title>
</head>

Expand All @@ -21,11 +21,11 @@
<main class="row">
<div class="profile-container col-md-4 text-white">
<div class="profile-pic text-center pt-3">
<img src="images/profile_picture.jpg" alt="profilePic" class="prof-pic rounded-circle ">
<img src={{user.imagePath}} alt="profilePic" class="prof-pic rounded-circle ">
</div>
<div class="row text-inherit m-0 d-flex align-items-center">
<div class="col prof-name fs-2">
Username
{{user.username}}
</div>
<div class="col btn-setting">
<div class="dropdown">
Expand All @@ -36,23 +36,16 @@
</div>
<div class="row fs-5">
<div class="col">
4k <br><small>Following</small>
{{user.follows.size}} <br><small>Following</small>
</div>
<div class="col">
10k <br> <small>Followers</small>
{{user.followers.size}} <br> <small>Followers</small>
</div>
</div>
<hr>
<div class="bio-container">
<p>
(づ。◕‿‿◕。)づ
<br>
-Spits facts daily
<br>
-Best opinions all around
<br>
-Don't hate pls
@gledrian.dev_
{{user.bio}}
</p>
</div>
</div>
Expand Down

0 comments on commit 600ef2f

Please sign in to comment.