Commit 8543f53a authored by Quxl's avatar Quxl

找回密码,国际化修改

parent 9a30ef67
...@@ -5,6 +5,7 @@ import java.util.Locale; ...@@ -5,6 +5,7 @@ import java.util.Locale;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -12,6 +13,10 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -12,6 +13,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.bean.Rjx; 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 com.egolm.film.config.interceptor.LocaleSessionInterceptor;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -24,6 +29,15 @@ import io.swagger.annotations.ApiOperation; ...@@ -24,6 +29,15 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping("open/member") @RequestMapping("open/member")
public class MemberOpenApiController { public class MemberOpenApiController {
@Autowired
private EmailService emailService;
@Autowired
private Messages messages;
@Autowired
private MemberService memberService;
@ResponseBody @ResponseBody
@PostMapping("register") @PostMapping("register")
@ApiOperation("会员注册") @ApiOperation("会员注册")
...@@ -39,19 +53,22 @@ public class MemberOpenApiController { ...@@ -39,19 +53,22 @@ public class MemberOpenApiController {
@ResponseBody @ResponseBody
@PostMapping("getPassword") @PostMapping("getPassword")
@ApiOperation("找回密码") @ApiOperation("找回密码")
@ApiImplicitParams({ @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email")})
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email"),
})
public Object getPassword(String 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(); return Rjx.jsonOk();
} }
@ResponseBody @ResponseBody
@PostMapping("setLocale") @PostMapping("setLocale")
@ApiOperation("设置语言环境") @ApiOperation("设置语言环境")
@ApiImplicitParams({ @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "i18n_language", defaultValue="zh_CN")})
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "i18n_language", defaultValue="zh_CN"),
})
public Object setLocale(HttpSession session, String i18n_language) { public Object setLocale(HttpSession session, String i18n_language) {
Locale locale = new Locale(i18n_language); Locale locale = new Locale(i18n_language);
session.setAttribute(LocaleSessionInterceptor.I18N_LANGUAGE_SESSION, locale); session.setAttribute(LocaleSessionInterceptor.I18N_LANGUAGE_SESSION, locale);
...@@ -64,4 +81,5 @@ public class MemberOpenApiController { ...@@ -64,4 +81,5 @@ public class MemberOpenApiController {
public Object getLocale(HttpServletRequest request) { public Object getLocale(HttpServletRequest request) {
return Rjx.jsonOk().setMessage(LocaleContextHolder.getLocale().toString()); 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 { public interface Messages {
......
package com.egolm.film.messages; package com.egolm.film.common.impl;
import java.util.Locale; import java.util.Locale;
...@@ -8,6 +8,7 @@ import org.springframework.context.NoSuchMessageException; ...@@ -8,6 +8,7 @@ import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.egolm.film.common.Messages;
import com.egolm.film.config.XException; import com.egolm.film.config.XException;
@Component @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; ...@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil; import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.common.Messages;
import com.egolm.film.config.WebMvcConfig; import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException; import com.egolm.film.config.XException;
import com.egolm.film.login.service.MemberTokenService; import com.egolm.film.login.service.MemberTokenService;
...@@ -18,6 +19,9 @@ import com.egolm.film.model.LoginToken; ...@@ -18,6 +19,9 @@ import com.egolm.film.model.LoginToken;
@Service @Service
public class MemberTokenServiceImpl implements MemberTokenService { public class MemberTokenServiceImpl implements MemberTokenService {
@Autowired
private Messages messages;
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
...@@ -37,17 +41,17 @@ public class MemberTokenServiceImpl implements MemberTokenService { ...@@ -37,17 +41,17 @@ public class MemberTokenServiceImpl implements MemberTokenService {
session.setAttribute(TOKEN_NAME, token); session.setAttribute(TOKEN_NAME, token);
return token; return token;
} else if(state == 2) { } else if(state == 2) {
throw new XException("用户已禁用"); throw new XException(messages.get("sys.err.user_disabled"));
} else { } else {
throw new XException("用户状态未知"); throw new XException(messages.get("sys.err"));
} }
} else if(list.size() == 0) { } else if(list.size() == 0) {
throw new XException("用户名或密码错误"); throw new XException(messages.get("sys.err.user_or_pwd"));
} else { } else {
throw new XException("用户登陆信息重复,请联系管理员"); throw new XException(messages.get("sys.err"));
} }
} else { } else {
throw new XException("用户名或密码错误"); throw new XException(messages.get("sys.err.user_or_pwd"));
} }
} }
...@@ -69,4 +73,5 @@ public class MemberTokenServiceImpl implements MemberTokenService { ...@@ -69,4 +73,5 @@ public class MemberTokenServiceImpl implements MemberTokenService {
public boolean isLogin() { public boolean isLogin() {
return this.getToken() != null; return this.getToken() != null;
} }
} }
...@@ -16,3 +16,9 @@ spring.http.encoding.charset=utf-8 ...@@ -16,3 +16,9 @@ spring.http.encoding.charset=utf-8
spring.messages.basename=classpath:i18n/messages spring.messages.basename=classpath:i18n/messages
spring.messages.cache-seconds=3600 spring.messages.cache-seconds=3600
spring.messages.encoding=UTF-8 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