Skip to content

Commit 645e0d6

Browse files
committed
Spring Boot Email Verification
1 parent 66fccab commit 645e0d6

File tree

19 files changed

+604
-0
lines changed

19 files changed

+604
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
target
3+
*.iml
4+
out
5+
.DS_Store
6+
data
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM maven:3.5-jdk-8
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3'
2+
services:
3+
hk-mysql:
4+
container_name: hk-mysql
5+
image: mysql/mysql-server:5.7
6+
environment:
7+
MYSQL_DATABASE: test
8+
MYSQL_ROOT_PASSWORD: hellokoding
9+
MYSQL_ROOT_HOST: '%'
10+
ports:
11+
- "3306:3306"
12+
restart: always
13+
14+
app:
15+
build: .
16+
volumes:
17+
- .:/app
18+
- ~/.m2:/root/.m2
19+
working_dir: /app
20+
ports:
21+
- "8080:8080"
22+
command: mvn clean spring-boot:run
23+
depends_on:
24+
- hk-mysql
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.hellokoding.springboot</groupId>
5+
<artifactId>email.verification</artifactId>
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.1.4.RELEASE</version>
10+
</parent>
11+
12+
<properties>
13+
<java.version>1.8</java.version>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-freemarker</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-data-jpa</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>mysql</groupId>
31+
<artifactId>mysql-connector-java</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.hibernate</groupId>
35+
<artifactId>hibernate-java8</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.sun.mail</groupId>
39+
<artifactId>javax.mail</artifactId>
40+
<version>1.6.0</version>
41+
</dependency>
42+
</dependencies>
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-maven-plugin</artifactId>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.hellokoding.account;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class WebApplication {
8+
public static void main(String[] args) throws Exception {
9+
SpringApplication.run(WebApplication.class, args);
10+
}
11+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.hellokoding.account.model;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
@ConfigurationProperties(prefix = "mail")
8+
public class MailProperties {
9+
public static class SMTP {
10+
String host;
11+
String port;
12+
String username;
13+
String password;
14+
15+
public String getHost() {
16+
return host;
17+
}
18+
19+
public void setHost(String host) {
20+
this.host = host;
21+
}
22+
23+
public String getPort() {
24+
return port;
25+
}
26+
27+
public void setPort(String port) {
28+
this.port = port;
29+
}
30+
31+
public String getUsername() {
32+
return username;
33+
}
34+
35+
public void setUsername(String username) {
36+
this.username = username;
37+
}
38+
39+
public String getPassword() {
40+
return password;
41+
}
42+
43+
public void setPassword(String password) {
44+
this.password = password;
45+
}
46+
}
47+
48+
private SMTP smtp;
49+
private String from;
50+
private String fromName;
51+
private String verificationapi;
52+
53+
public SMTP getSmtp() {
54+
return smtp;
55+
}
56+
57+
public void setSmtp(SMTP smtp) {
58+
this.smtp = smtp;
59+
}
60+
61+
public String getFrom() {
62+
return from;
63+
}
64+
65+
public void setFrom(String from) {
66+
this.from = from;
67+
}
68+
69+
public String getFromName() {
70+
return fromName;
71+
}
72+
73+
public void setFromName(String fromName) {
74+
this.fromName = fromName;
75+
}
76+
77+
public String getVerificationapi() {
78+
return verificationapi;
79+
}
80+
81+
public void setVerificationapi(String verificationapi) {
82+
this.verificationapi = verificationapi;
83+
}
84+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.hellokoding.account.model;
2+
3+
import javax.persistence.*;
4+
5+
@Entity
6+
public class User {
7+
@Id
8+
@GeneratedValue(strategy = GenerationType.IDENTITY)
9+
private Long id;
10+
11+
private String email;
12+
13+
private Boolean isActive;
14+
15+
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL)
16+
private VerificationToken verificationToken;
17+
18+
public Long getId() {
19+
return id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public String getEmail() {
27+
return email;
28+
}
29+
30+
public void setEmail(String email) {
31+
this.email = email;
32+
}
33+
34+
public Boolean getIsActive() {
35+
return isActive;
36+
}
37+
38+
public void setIsActive(Boolean isActive) {
39+
this.isActive = isActive;
40+
}
41+
42+
public VerificationToken getVerificationToken() {
43+
return verificationToken;
44+
}
45+
46+
public void setVerificationToken(VerificationToken verificationToken) {
47+
this.verificationToken = verificationToken;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.hellokoding.account.model;
2+
3+
import javax.validation.constraints.Email;
4+
import javax.validation.constraints.NotEmpty;
5+
6+
public class VerificationForm {
7+
@NotEmpty
8+
@Email
9+
private String email;
10+
11+
public String getEmail() {
12+
return email;
13+
}
14+
15+
public void setEmail(String email) {
16+
this.email = email;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.hellokoding.account.model;
2+
3+
import javax.persistence.*;
4+
import java.time.LocalDateTime;
5+
import java.util.UUID;
6+
7+
@Entity
8+
public class VerificationToken {
9+
public static final String STATUS_PENDING = "PENDING";
10+
public static final String STATUS_VERIFIED = "VERIFIED";
11+
12+
@Id
13+
@GeneratedValue(strategy = GenerationType.IDENTITY)
14+
private Long id;
15+
16+
private String token;
17+
private String status;
18+
private LocalDateTime expiredDateTime;
19+
private LocalDateTime issuedDateTime;
20+
private LocalDateTime confirmedDateTime;
21+
22+
@OneToOne(cascade = CascadeType.ALL)
23+
@JoinColumn(name = "user_id")
24+
private User user;
25+
26+
public VerificationToken(){
27+
this.token = UUID.randomUUID().toString();
28+
this.issuedDateTime = LocalDateTime.now();
29+
this.expiredDateTime = this.issuedDateTime.plusDays(1);
30+
this.status = STATUS_PENDING;
31+
}
32+
33+
public Long getId() {
34+
return id;
35+
}
36+
37+
public void setId(Long id) {
38+
this.id = id;
39+
}
40+
41+
public String getToken() {
42+
return token;
43+
}
44+
45+
public void setToken(String token) {
46+
this.token = token;
47+
}
48+
49+
public String getStatus() {
50+
return status;
51+
}
52+
53+
public void setStatus(String status) {
54+
this.status = status;
55+
}
56+
57+
public LocalDateTime getExpiredDateTime() {
58+
return expiredDateTime;
59+
}
60+
61+
public void setExpiredDateTime(LocalDateTime expiredDateTime) {
62+
this.expiredDateTime = expiredDateTime;
63+
}
64+
65+
public LocalDateTime getIssuedDateTime() {
66+
return issuedDateTime;
67+
}
68+
69+
public void setIssuedDateTime(LocalDateTime issuedDateTime) {
70+
this.issuedDateTime = issuedDateTime;
71+
}
72+
73+
public LocalDateTime getConfirmedDateTime() {
74+
return confirmedDateTime;
75+
}
76+
77+
public void setConfirmedDateTime(LocalDateTime confirmedDateTime) {
78+
this.confirmedDateTime = confirmedDateTime;
79+
}
80+
81+
public User getUser() {
82+
return user;
83+
}
84+
85+
public void setUser(User user) {
86+
this.user = user;
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.hellokoding.account.repository;
2+
3+
import com.hellokoding.account.model.User;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
import java.util.List;
7+
8+
public interface UserRepository extends JpaRepository<User, String> {
9+
List<User> findByEmail(String email);
10+
}

0 commit comments

Comments
 (0)