Skip to content

Commit

Permalink
Added page for creating a new user when logged in; not saving, but ad…
Browse files Browse the repository at this point in the history
…ded validations
  • Loading branch information
surajcm committed Jan 31, 2024
1 parent 03d6a40 commit 30500ea
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
java-version: '21'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Test with Gradle
run: ./gradlew test
- name: Generate reports
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:21.0.1_12-jdk
FROM eclipse-temurin:21.0.2_13-jdk
COPY . .
RUN sed -i '/JAVA_HOME/d' build.sh && chmod +x /start.sh && chmod +x build.sh && chmod +x gradlew
VOLUME ["/tmp/db"]
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.1.4'
id 'net.ltgt.errorprone' version '3.1.0'
id 'com.github.spotbugs' version '6.0.4' apply false
id 'com.github.spotbugs' version '6.0.7' apply false
id 'de.aaschmid.cpd' version '3.3'
id "org.sonarqube" version "4.4.1.3373"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/staticCodeAnalysis.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'jacoco'
//apply plugin: 'com.github.spotbugs'

checkstyle {
toolVersion = '10.12.7'
toolVersion = '10.13.0'
ignoreFailures = false
maxWarnings = 0
checkstyleMain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,29 @@ public String loginMe2() {
*
* @return create challenge page
*/
@PostMapping("/userManagement")
@GetMapping("/userManagement")
public String manageUsers(final Model model) {
logger.info("Into the manageUsers method");
var listUsers = userService.listAll();
model.addAttribute("listusers", listUsers);
return "user/usermanagement";
}

@GetMapping("/user/create")
public String createUser(final Model model) {
logger.info("Into the createUser method");
var roles = userService.listRoles();
var user = new User();
user.setEnabled(true);
model.addAttribute("userForm", user);
model.addAttribute("listRoles", roles);
return "user/createuser";
}

@PostMapping("/users/save")
public String saveUser(final User user) {
logger.info("Into the saveUser method, user is {}", user);
return "redirect:/userManagement";
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quiz.darkhold.login.service;

import com.quiz.darkhold.login.entity.Role;
import com.quiz.darkhold.login.entity.User;

import java.util.List;
Expand All @@ -10,5 +11,7 @@ public interface UserService {
User findByUsername(String username);

List<User> listAll();

List<Role> listRoles();
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quiz.darkhold.login.service;

import com.quiz.darkhold.login.entity.Role;
import com.quiz.darkhold.login.entity.User;
import com.quiz.darkhold.login.repository.RoleRepository;
import com.quiz.darkhold.login.repository.UserRepository;
Expand Down Expand Up @@ -48,4 +49,9 @@ public User findByUsername(final String email) {
public List<User> listAll() {
return userRepository.findAll();
}

@Override
public List<Role> listRoles() {
return (List<Role>) roleRepository.findAll();
}
}
1 change: 1 addition & 0 deletions src/main/resources/static/scripts/options-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function toHome() {
}

function manageUsers() {
document.forms[0].method = 'get';
document.forms[0].action = "/userManagement";
document.forms[0].submit();
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/resources/templates/error.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="darkhold 404 page" />
<meta name="author" content="Suraj" />
<title>Error occurred: Darkhold classroom quiz experience</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="styles/error-styles.css" rel="stylesheet" />
<link href="/styles/error-styles.css" rel="stylesheet" />
<script type="text/javascript" src="/scripts/common-scripts.js"></script>
<script type="text/javascript" src="/scripts/core/bootstrap-5.3.1/bootstrap.min.js"></script>
</head>
<body>
<div th:insert="~{navbar :: navbar}"></div>
<form>
<div class="container">
<div class="body-style">
<div style="width:40%;">
<img src="images/404.png" style="float: right;" />
<img src="/images/404.png" style="float: right;" />
</div>
<div style="width:45%;float:left;margin-left:50px;">
<h1 style="font-weight:bold;font-size:34px;">Page Not Found</h1>
Expand All @@ -28,7 +35,5 @@ <h1 style="font-weight:bold;font-size:34px;">Page Not Found</h1>
</div>
</div>
</form>
<script type="text/javascript" src="scripts/core/popper.min.js"></script>
<script type="text/javascript" src="scripts/core/bootstrap-5.min.js"></script>
</body>
</html>
78 changes: 78 additions & 0 deletions src/main/resources/templates/user/createuser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="darkhold create user page" />
<meta name="author" content="Suraj" />
<title>Getting Started: Darkhold classroom quiz experience</title>
<link href="/styles/error-styles.css" rel="stylesheet" />
<script type="text/javascript" src="/scripts/common-scripts.js"></script>
<script type="text/javascript" src="/scripts/user-management-scripts.js"></script>
<script type="text/javascript" src="/scripts/core/bootstrap-5.3.1/bootstrap.min.js"></script>
</head>
<body>
<main>
<div th:insert="~{navbar :: navbar}"></div>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Create User</h3>
</div>
</div>

<form th:action="@{/users/save}" method="post" th:object="${userForm}">
<div class="border border-secondary rounded p-3">
<div class="input-group mb-3">
<label class="col-sm-4 col-form-label">First Name : </label>
<div class="col-sm-8">
<input type="text" class="form-control" th:field="*{firstName}" required minlength="8" maxlength="90" />
</div>
</div>
<div class="input-group mb-3">
<label class="col-sm-4 col-form-label">Last Name : </label>
<div class="col-sm-8">
<input type="text" class="form-control" th:field="*{lastName}" required minlength="8" maxlength="90" />
</div>
</div>
<div class="input-group mb-3">
<label class="col-sm-4 col-form-label">E-mail : </label>
<div class="col-sm-8">
<input type="email" class="form-control" th:field="*{email}" required minlength="8" maxlength="128" />
</div>
</div>
<div class="input-group mb-3">
<label class="col-sm-4 col-form-label">Password : </label>
<div class="col-sm-8">
<input type="password" class="form-control" th:field="*{password}" required minlength="8" maxlength="20" />
</div>
</div>
<div class="input-group mb-3">
<label class="col-sm-4 col-form-label">Roles : </label>
<div class="col-sm-8">
<th:block th:each="role : ${listRoles}">
<div class="form-check">
<input type="checkbox" th:field="*{roles}" th:text="${role.name}" th:value="${role.id}" class="form-check-input"/>
- <small>[[${role.description}]]</small>
</div>
</th:block>
</div>
</div>
<div class="input-group mb-3">
<label class="col-sm-4 col-form-label">Enabled : </label>
<div class="col-sm-8">
<input type="checkbox" th:field="*{enabled}" />
</div>
</div>
<div class="text-center">
<input type="submit" value="Save" class="btn btn-primary m-3" onclick="saveThisUser();" />
<input type="button" value="Cancel" class="btn border-secondary" />
</div>
</div>
</form>
</div>
</main>
</body>
</html>
1 change: 1 addition & 0 deletions src/main/resources/templates/user/usermanagement.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div th:insert="~{navbar :: navbar}"></div>
<div>
<h2>Manage Users</h2>
<a th:href="@{/user/create}">Create New User</a>
</div>
<div>
<form action="#" method="post">
Expand Down

0 comments on commit 30500ea

Please sign in to comment.