Skip to content

Commit 92c2b88

Browse files
committed
leeang11/05
1 parent be50ed4 commit 92c2b88

File tree

12 files changed

+304
-24
lines changed

12 files changed

+304
-24
lines changed

code/backend/src/main/java/edu/bu/cs673/secondhand/controller/UserControllerLegacy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ResultVo signIn(@RequestBody User userModel) {
4242
}
4343
if (userService.userSignIn(userModel)) {
4444
userService.insertActiveCode(userModel.getEmail());
45-
userService.sendVerificationEmail(userModel);
45+
userService.sendSignUpEmail(userModel);
4646
System.out.println(userModel.getEmail()+"Email has been sent");
4747
return ResultVo.success(userModel);
4848
}

code/backend/src/main/java/edu/bu/cs673/secondhand/controller/adminController.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import jakarta.servlet.http.Cookie;
1414
import jakarta.servlet.http.HttpServletResponse;
1515
import org.springframework.web.bind.annotation.*;
16-
17-
import javax.servlet.http.HttpSession;
1816
import javax.validation.constraints.NotEmpty;
1917
import javax.validation.constraints.NotNull;
2018

@@ -124,7 +122,7 @@ public ResultVo idleList(@CookieValue("adminId")
124122
return ResultVo.success(idleItemService.adminGetIdleList(status,p,n));
125123
}
126124

127-
@GetMapping("updateIdleStatus")
125+
@PostMapping("updateIdleStatus")
128126
public ResultVo updateIdleStatus(@CookieValue("adminId")
129127
@NotNull(message = "Login fail, try again.")
130128
@NotEmpty(message = "Login fail, try again.")
@@ -164,7 +162,7 @@ public ResultVo orderList(@CookieValue("adminId")
164162
return ResultVo.success(orderService.getAllOrder(p,n));
165163
}
166164

167-
@GetMapping("deleteOrder")
165+
@DeleteMapping("deleteOrder")
168166
public ResultVo deleteOrder(@CookieValue("adminId")
169167
@NotNull(message = "Login fail, try again.")
170168
@NotEmpty(message = "Login fail, try again.")
@@ -199,7 +197,7 @@ public ResultVo userList(@CookieValue("adminId")
199197
return ResultVo.success(userService.getUserByStatus(status,p,n));
200198
}
201199

202-
@GetMapping("updateUserStatus")
200+
@PostMapping("updateUserStatus")
203201
public ResultVo updateUserStatus(@CookieValue("adminId")
204202
@NotNull(message = "Login fail, try again.")
205203
@NotEmpty(message = "Login fail, try again.")

code/backend/src/main/java/edu/bu/cs673/secondhand/service/UserServiceLegacy.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Email: qyyh@bu.edu,la1993@bu.edu
99
DateTime: 11/3/24-14:03
1010
*****/
11+
1112
public interface UserServiceLegacy {
1213

1314
/**
@@ -81,4 +82,32 @@ public interface UserServiceLegacy {
8182
public boolean verifyCode(User user);
8283

8384
public boolean insertActiveCode(String email);
85+
86+
/**
87+
* Sends a simple email message.
88+
* @param to The recipient's email address.
89+
* @param subject The subject of the email.
90+
* @param text The body of the email.
91+
*/
92+
void sendSimpleMessage(String to, String subject, String text);
93+
94+
/**
95+
* Sends a sign-up email to the user with a link to complete the sign-up process.
96+
* @param user The activation token for the sign-up process.
97+
*/
98+
void sendSignUpEmail(User user);
99+
100+
/**
101+
* Sends an activation email to the user.
102+
* @param email The recipient's email address.
103+
* @param activationToken The activation token for the user.
104+
*/
105+
void sendActivationEmail(String email, String activationToken);
106+
107+
/**
108+
* Sends a password reset email to the user with a link to reset their password.
109+
* @param email The recipient's email address.
110+
* @param resetToken The token for resetting the password.
111+
*/
112+
void sendPasswordResetEmail(String email, String resetToken);
84113
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package edu.bu.cs673.secondhand.service.impl;
2+
3+
import edu.bu.cs673.secondhand.service.EmailService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.mail.SimpleMailMessage;
7+
import org.springframework.mail.javamail.JavaMailSender;
8+
import org.springframework.stereotype.Service;
9+
10+
/**
11+
* EmailService is responsible for sending emails related to user actions
12+
* such as sign-up, activation, and password reset.
13+
* Author: YQ
14+
* TODO: STILL NEED TO DEVELOP A REGISTER LINK AND RESET PASSWORD LINK
15+
*/
16+
@Service
17+
public class EmailServiceImpl implements EmailService {
18+
19+
@Autowired
20+
private JavaMailSender mailSender; // Mail sender for sending emails
21+
22+
@Value("${app.url}")
23+
private String appUrl; // Base URL of the application
24+
25+
@Value("${spring.mail.username}")
26+
private String fromEmail; // Email address from which the emails will be sent
27+
28+
/**
29+
* Sends a simple email message.
30+
* @param to The recipient's email address.
31+
* @param subject The subject of the email.
32+
* @param text The body of the email.
33+
*/
34+
@Override
35+
public void sendSimpleMessage(String to, String subject, String text) {
36+
SimpleMailMessage message = new SimpleMailMessage();
37+
message.setFrom(fromEmail); // Set the sender's email
38+
message.setTo(to); // Set the recipient's email
39+
message.setSubject(subject); // Set the subject
40+
message.setText(text); // Set the body text
41+
mailSender.send(message); // Send the email
42+
}
43+
44+
/**
45+
* Sends a sign-up email to the user with a link to complete the sign-up process.
46+
* @param to The recipient's email address.
47+
* @param token The activation token for the sign-up process.
48+
*/
49+
@Override
50+
public void sendSignUpEmail(String to, String token) {
51+
String subject = "Complete Your Sign-Up for SecondHand";
52+
String text = "Please click on the following link to complete your sign-up: "
53+
+ appUrl + "/api/users/complete-signup?email=" + to + "&token=" + token
54+
+ "\n\nThis link will expire in 24 hours.";
55+
sendSimpleMessage(to, subject, text); // Send the sign-up email
56+
}
57+
58+
/**
59+
* Sends an activation email to the user.
60+
* @param email The recipient's email address.
61+
* @param activationToken The activation token for the user.
62+
*/
63+
@Override
64+
public void sendActivationEmail(String email, String activationToken) {
65+
// Implement this method if needed
66+
String subject = "Activate Your Account for SecondHand";
67+
String text = "Please click on the following link to activate your account: "
68+
+ appUrl + "/api/users/activate?email=" + email + "&token=" + activationToken
69+
+ "\n\nThis link will expire in 24 hours.";
70+
sendSimpleMessage(email, subject, text); // Send the activation email
71+
}
72+
73+
/**
74+
* Sends a password reset email to the user with a link to reset their password.
75+
* @param email The recipient's email address.
76+
* @param resetToken The token for resetting the password.
77+
*/
78+
@Override
79+
public void sendPasswordResetEmail(String email, String resetToken) {
80+
String subject = "Reset Your Password for SecondHand";
81+
String text = "Please click on the following link to reset your password: "
82+
+ appUrl + "/api/users/reset-password?email=" + email + "&resetToken=" + resetToken
83+
+ "\n\nThis link will expire in 1 hour.";
84+
sendSimpleMessage(email, subject, text); // Send the password reset email
85+
}
86+
}

code/backend/src/main/java/edu/bu/cs673/secondhand/service/impl/UserServiceLegacyImpl.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import edu.bu.cs673.secondhand.vo.PageVo;
88
import jakarta.annotation.Resource;
99
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.beans.factory.annotation.Value;
11+
import org.springframework.mail.SimpleMailMessage;
12+
import org.springframework.mail.javamail.JavaMailSender;
1013
import org.springframework.stereotype.Service;
1114

1215
import java.util.List;
@@ -19,6 +22,15 @@
1922
@Service
2023
public class UserServiceLegacyImpl implements UserServiceLegacy {
2124

25+
@Autowired
26+
private JavaMailSender mailSender; // Mail sender for sending emails
27+
28+
@Value("${app.url}")
29+
private String appUrl; // Base URL of the application
30+
31+
@Value("${spring.mail.username}")
32+
private String fromEmail; // Email address from which the emails will be sent
33+
2234
@Resource
2335
private UserMapperLegacy userDao;
2436
/**
@@ -154,10 +166,63 @@ public boolean insertActiveCode(String email) {
154166
userDao.insertActiveCodeByEmail(code,email);
155167
return true;
156168
}
157-
158169
private String generateVerificationCode() {
159170
return String.format("%06d", new Random().nextInt(999999));
160171
}
161172

162173

174+
@Override
175+
public void sendSimpleMessage(String to, String subject, String text) {
176+
SimpleMailMessage message = new SimpleMailMessage();
177+
message.setFrom(fromEmail); // Set the sender's email
178+
message.setTo(to); // Set the recipient's email
179+
message.setSubject(subject); // Set the subject
180+
message.setText(text); // Set the body text
181+
mailSender.send(message); // Send the email
182+
}
183+
184+
/**
185+
* Sends a sign-up email to the user with a link to complete the sign-up process.
186+
* @param user The recipient's email address.
187+
*/
188+
@Override
189+
public void sendSignUpEmail(User user) {
190+
String code = userDao.findActiveCodeByEmail(user.getEmail());
191+
String subject = "Complete Your Sign-Up for SecondHand";
192+
String text = "Please click on the following link to complete your sign-up: "
193+
+ "Your active Code =====" + code
194+
+ "\n\nThis code will expire in 24 hours.";
195+
sendSimpleMessage(user.getEmail(), subject, text); // Send the sign-up email
196+
}
197+
198+
/**
199+
* Sends an activation email to the user.
200+
* @param email The recipient's email address.
201+
* @param activationToken The activation token for the user.
202+
*/
203+
@Override
204+
public void sendActivationEmail(String email, String activationToken) {
205+
// Implement this method if needed
206+
207+
String subject = "Activate Your Account for SecondHand";
208+
String text = "Please click on the following link to activate your account: "
209+
+ "/api/users/activate?email=" + email + "&token=" + activationToken
210+
+ "\n\nThis link will expire in 24 hours.";
211+
sendSimpleMessage(email, subject, text); // Send the activation email
212+
}
213+
214+
/**
215+
* Sends a password reset email to the user with a link to reset their password.
216+
* @param email The recipient's email address.
217+
* @param resetToken The token for resetting the password.
218+
*/
219+
@Override
220+
public void sendPasswordResetEmail(String email, String resetToken) {
221+
String subject = "Reset Your Password for SecondHand";
222+
String text = "Please click on the following link to reset your password: "
223+
+ "/api/users/reset-password?email=" + email + "&resetToken=" + resetToken
224+
+ "\n\nThis link will expire in 1 hour.";
225+
sendSimpleMessage(email, subject, text); // Send the password reset email
226+
}
227+
163228
}

code/backend/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ logging.level.org.apache.ibatis=DEBUG
1414
spring.mail.host=smtp.gmail.com
1515
spring.mail.port=587
1616
spring.mail.username=yueyihanqi@gmail.com
17-
spring.mail.password=jqjm wekm ubuq gbcr
17+
spring.mail.password=xwgx fmmc wuas jenr
1818
spring.mail.properties.mail.smtp.auth=true
1919
spring.mail.properties.mail.smtp.starttls.enable=true
2020
spring.mail.properties.mail.debug=true

code/backend/src/main/resources/mappers/IdleItemMapper.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@
7171
</foreach>
7272
</where>
7373
</sql>
74+
75+
<select id="countIdleItemByStatus" resultType="int">
76+
select COUNT(*) from sh_idle_item
77+
where idle_status = #{status}
78+
</select>
79+
80+
7481
<sql id="Base_Column_List">
7582
id, idle_name, idle_details, picture_list, idle_price, idle_place, idle_label, release_time,
7683
idle_status, user_id

code/backend/src/main/resources/mappers/UserMapperLegacy.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
<select id="getUserByNumber" resultMap="BaseResultMap">
4343
select
4444
<include refid="Base_Column_List"/>
45-
from sh_user where account_number = #{searchValue} and user_status = #{mode}
45+
from sh_user where account_number = #{searchValue} or user_status = #{mode}
4646
</select>
4747
<select id="getNormalUser" resultMap="BaseResultMap">
4848
select
4949
<include refid="Base_Column_List"/>
50-
from sh_user where user_status is null or user_status = 0 order by id desc limit #{begin}, #{nums}
50+
from sh_user where user_status is null order by id desc limit #{begin}, #{nums}
5151
</select>
5252
<select id="getBanUser" resultMap="BaseResultMap">
5353
select
@@ -69,7 +69,7 @@
6969
useGeneratedKeys="true">
7070
insert into sh_user (account_number, email, user_password, nickname,
7171
avatar, sign_in_time)
72-
values (#{accountNumber,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{userPassword,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR},
72+
values (#{email,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{userPassword,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR},
7373
#{avatar,jdbcType=VARCHAR}, #{signInTime,jdbcType=TIMESTAMP})
7474
</insert>
7575
<insert id="insertSelective" keyColumn="id" keyProperty="id"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package edu.bu.cs673.secondhand.service;
2+
3+
import edu.bu.cs673.secondhand.domain.User;
4+
import edu.bu.cs673.secondhand.service.UserServiceLegacy;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.TestMethodOrder;
8+
import org.junit.jupiter.api.MethodOrderer;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import jakarta.annotation.Resource;
11+
12+
import static org.junit.jupiter.api.Assertions.*;
13+
14+
@SpringBootTest
15+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
16+
class UserServiceLegacyImplTest {
17+
18+
@Resource
19+
private UserServiceLegacy userService;
20+
21+
@BeforeEach
22+
void setUp() {
23+
System.out.println("Setting up UserServiceLegacy tests.");
24+
}
25+
26+
@Test
27+
@org.junit.jupiter.api.Order(1)
28+
void createUser() {
29+
User user = new User();
30+
user.setNickname("anglee1993");
31+
user.setEmail("la1994@bu.edu");
32+
user.setUserPassword("123456");
33+
boolean success = userService.userSignIn(user);
34+
assertTrue(success);
35+
assertNotNull(user.getId());
36+
}
37+
38+
// @Test
39+
// @org.junit.jupiter.api.Order(2)
40+
// void login() {
41+
// User user = new User();
42+
// user.setEmail("la1993@bu.edu");
43+
// user.setUserPassword("123456");
44+
//
45+
// userService.userLogin(user.getEmail(),user.getUserPassword());
46+
// Long userId = user.getId();
47+
// User fetchedUser = userService.getUserById(userId);
48+
//
49+
// assertNotNull(fetchedUser);
50+
// assertEquals(userId, fetchedUser.getId());
51+
// assertEquals("testuser2", fetchedUser.getUsername());
52+
// }
53+
}

code/frontend/src/components/page/login-admin.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="login-body">
55
<div class="login-title">Admin Management</div>
66
<el-form ref="form" :model="userForm">
7-
<el-input placeholder="Please enter admin account" v-model="userForm.email" class="login-input">
7+
<el-input placeholder="Please enter admin account" v-model="userForm.accountNumber" class="login-input">
88
<template slot="prepend">
99
<div class="el-icon-user-solid"></div>
1010
</template>
@@ -38,21 +38,21 @@ export default {
3838
data() {
3939
return {
4040
userForm: {
41-
email: '',
41+
accountNumber: '',
4242
adminPassword: ''
4343
}
4444
};
4545
},
4646
methods: {
4747
login() {
4848
// verify login email
49-
if (!this.userForm.email.endsWith('@bu.edu')) {
49+
if (!this.userForm.accountNumber.endsWith('@bu.edu')) {
5050
this.$message.error('Please use your BU email');
5151
return;
5252
}
5353
this.$api
5454
.adminLogin({
55-
email: this.userForm.email,
55+
accountNumber: this.userForm.accountNumber,
5656
adminPassword: this.userForm.adminPassword
5757
})
5858
.then((res) => {

0 commit comments

Comments
 (0)