Commit 8543f53a authored by Quxl's avatar Quxl

找回密码,国际化修改

parent 9a30ef67
......@@ -5,6 +5,7 @@ import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -12,6 +13,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.bean.Rjx;
import com.egolm.film.bean.Fc_member;
import com.egolm.film.common.EmailService;
import com.egolm.film.common.MemberService;
import com.egolm.film.common.Messages;
import com.egolm.film.config.interceptor.LocaleSessionInterceptor;
import io.swagger.annotations.Api;
......@@ -24,6 +29,15 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping("open/member")
public class MemberOpenApiController {
@Autowired
private EmailService emailService;
@Autowired
private Messages messages;
@Autowired
private MemberService memberService;
@ResponseBody
@PostMapping("register")
@ApiOperation("会员注册")
......@@ -39,19 +53,22 @@ public class MemberOpenApiController {
@ResponseBody
@PostMapping("getPassword")
@ApiOperation("找回密码")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email"),
})
@ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email")})
public Object getPassword(String email) {
int code = (int) ((Math.random() * 9 + 1) * 10000000);
String newPassword = String.valueOf(code);
Fc_member member = memberService.getMemberByEmail(email);
memberService.changePassword(member.getAddress(), newPassword);
String subject = messages.get("email.getPassword.subject");
String content = messages.get("email.getPassword.subject", member.getRealname(), newPassword);
emailService.send(subject, content, email);
return Rjx.jsonOk();
}
@ResponseBody
@PostMapping("setLocale")
@ApiOperation("设置语言环境")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "i18n_language", defaultValue="zh_CN"),
})
@ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "i18n_language", defaultValue="zh_CN")})
public Object setLocale(HttpSession session, String i18n_language) {
Locale locale = new Locale(i18n_language);
session.setAttribute(LocaleSessionInterceptor.I18N_LANGUAGE_SESSION, locale);
......@@ -64,4 +81,5 @@ public class MemberOpenApiController {
public Object getLocale(HttpServletRequest request) {
return Rjx.jsonOk().setMessage(LocaleContextHolder.getLocale().toString());
}
}
package com.egolm.film.common;
public interface EmailService {
void send(String subject, String content, String... emailAddress);
}
package com.egolm.film.common;
import com.egolm.film.bean.Fc_member;
public interface MemberService {
Fc_member getMemberByEmail(String email);
void changePassword(String id, String newPassword);
}
package com.egolm.film.messages;
package com.egolm.film.common;
public interface Messages {
......
package com.egolm.film.messages;
package com.egolm.film.common.impl;
import java.util.Locale;
......@@ -8,6 +8,7 @@ import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import com.egolm.film.common.Messages;
import com.egolm.film.config.XException;
@Component
......
package com.egolm.film.common.impl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.egolm.common.MailUtil;
import com.egolm.film.common.EmailService;
@Service
public class EmailServiceImpl implements EmailService {
@Value("${com.egolm.film.email.smtp.host}") private String host;
@Value("${com.egolm.film.email.smtp.port}") private Integer port;
@Value("${com.egolm.film.email.smtp.is_auth}") private Boolean is_auth;
@Value("${com.egolm.film.email.smtp.from}") private String from;
@Value("${com.egolm.film.email.smtp.password}") private String password;
@Override
public void send(String subject, String content, String... emailAddress) {
MailUtil.sendBySmtp(host, port, is_auth, content, password, subject, content, null, emailAddress);
}
}
package com.egolm.film.common.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.bean.Fc_member;
import com.egolm.film.common.MemberService;
@Service
public class MemberServiceImpl implements MemberService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public void changePassword(String id, String newPassword) {
String sql = "update fc_member set password = ? where id = ?";
String md5Pwd = StringUtil.toMD5HexString(newPassword);
jdbcTemplate.executeUpdate(sql, md5Pwd, id);
}
@Override
public Fc_member getMemberByEmail(String email) {
String sql = "select * from fc_member where email = ?";
return jdbcTemplate.queryForBean(sql, Fc_member.class, email);
}
}
......@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.common.Messages;
import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException;
import com.egolm.film.login.service.MemberTokenService;
......@@ -18,6 +19,9 @@ import com.egolm.film.model.LoginToken;
@Service
public class MemberTokenServiceImpl implements MemberTokenService {
@Autowired
private Messages messages;
@Autowired
private JdbcTemplate jdbcTemplate;
......@@ -37,17 +41,17 @@ public class MemberTokenServiceImpl implements MemberTokenService {
session.setAttribute(TOKEN_NAME, token);
return token;
} else if(state == 2) {
throw new XException("用户已禁用");
throw new XException(messages.get("sys.err.user_disabled"));
} else {
throw new XException("用户状态未知");
throw new XException(messages.get("sys.err"));
}
} else if(list.size() == 0) {
throw new XException("用户名或密码错误");
throw new XException(messages.get("sys.err.user_or_pwd"));
} else {
throw new XException("用户登陆信息重复,请联系管理员");
throw new XException(messages.get("sys.err"));
}
} else {
throw new XException("用户名或密码错误");
throw new XException(messages.get("sys.err.user_or_pwd"));
}
}
......@@ -69,4 +73,5 @@ public class MemberTokenServiceImpl implements MemberTokenService {
public boolean isLogin() {
return this.getToken() != null;
}
}
......@@ -15,4 +15,10 @@ spring.http.encoding.charset=utf-8
spring.messages.basename=classpath:i18n/messages
spring.messages.cache-seconds=3600
spring.messages.encoding=UTF-8
\ No newline at end of file
spring.messages.encoding=UTF-8
com.egolm.film.email.smtp.host=smtp.163.com
com.egolm.film.email.smtp.port=25
com.egolm.film.email.smtp.is_auth=true
com.egolm.film.email.smtp.from=15601712556@163.com
com.egolm.film.email.smtp.password=Liang12345
email.getPassword.subject=\u4E2D\u56FD\u7535\u5F71\u8282[\u627E\u56DE\u5BC6\u7801]\u90AE\u4EF6
email.getPassword.content={0}, \u60A8\u597D, \u60A8\u7684\u65B0\u5BC6\u7801\u662F: [{1}]
sys.err=\u7CFB\u7EDF\u9519\u8BEF
sys.err.user_disabled=\u7528\u6237\u5DF2\u7ECF\u7981\u7528
sys.err.user_or_pwd=\u7528\u6237\u6216\u5BC6\u7801\u9519\u8BEF
msg.hello=\u60A8\u597D
msg.your_pwd=\u60A8\u7684\u5BC6\u7801\u662F
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment