0% found this document useful (0 votes)
5 views2 pages

Church Backend Code

The document outlines a Java application structure for user authentication, including entities, repositories, services, and controllers. It defines a User entity with roles, a repository for user data access, and services for user creation and login functionality using JWT for token generation. Additionally, it includes security configurations and a data initializer for setting up default users.

Uploaded by

rajipriya9808
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Church Backend Code

The document outlines a Java application structure for user authentication, including entities, repositories, services, and controllers. It defines a User entity with roles, a repository for user data access, and services for user creation and login functionality using JWT for token generation. Additionally, it includes security configurations and a data initializer for setting up default users.

Uploaded by

rajipriya9808
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

User.

java
@Entity
public class User {
@Id @GeneratedValue
private Long id;
private String username;
private String password;
private Role role;
}

[Link]

public enum Role {


SUPER_PLUS_ADMIN,
SUPER_ADMIN,
TEMP
}

[Link]

public interface UserRepository extends JpaRepository<User, Long> {


Optional<User> findByUsername(String username);
}

[Link]

public String generateToken(String username, String role) { ... }


public Claims validateToken(String token) { ... }

[Link]

public String login(String username, String password) {


User user = [Link](username).orElseThrow();
if (![Link](password, [Link]())) throw new RuntimeException();
return [Link]([Link](), [Link]().name());
}

[Link]
public User createUser(String username, String password, Role role) {
User u = new User();
[Link](username);
[Link]([Link](password));
[Link](role);
return [Link](u);
}

[Link]

@PostMapping("/login")
public String login(@RequestBody LoginRequest req) {
return [Link]([Link](), [Link]());
}
[Link]
@PostMapping("/create")
public User createUser(@RequestBody UserRequest req) {
return [Link]([Link](), [Link](), [Link]([Link]()));
}

[Link]

if (authHeader == null) throw new RuntimeException("Missing Token");


Claims claims = [Link](token);

[Link]

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

[Link]

if([Link]("gobi").isEmpty()){
[Link]([Link]("gobi"));
}

You might also like