Commit 44ee5a1a authored by Quxl's avatar Quxl
parents 56b35611 6e69308f
...@@ -63,6 +63,14 @@ ...@@ -63,6 +63,14 @@
<artifactId>activation</artifactId> <artifactId>activation</artifactId>
<version>1.1</version> <version>1.1</version>
</dependency> </dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
...@@ -12,12 +12,15 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -12,12 +12,15 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; 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.MailUtil;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.common.web.ServletUtil; import com.egolm.common.web.ServletUtil;
import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member; import com.egolm.film.bean.Fc_member;
import com.egolm.film.common.EmailService; import com.egolm.film.common.EmailService;
import com.egolm.film.common.MemberService;
import com.egolm.film.common.Messages; import com.egolm.film.common.Messages;
import com.egolm.film.config.Common;
import com.egolm.film.config.XException;
import com.egolm.film.config.interceptor.LocaleSessionInterceptor; import com.egolm.film.config.interceptor.LocaleSessionInterceptor;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -48,34 +51,65 @@ public class MemberOpenApiController { ...@@ -48,34 +51,65 @@ public class MemberOpenApiController {
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email"), @ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email"),
}) })
public Object register(HttpServletRequest request, String username, String password, String email) { public Object register(HttpServletRequest request, String username, String password, String email) {
XException.assertNotBlank(messages.get("err.email_null"), email);
XException.assertNotBlank(messages.get("err.name_null"), username);
XException.assertNotBlank(messages.get("err.pwd_null"), password);
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
String salt = Common.getGenerateString(6);
String encodePwd = Common.encodePassword(password, salt);
Fc_member member = new Fc_member(); Fc_member member = new Fc_member();
member.setSalt(salt);
member.setUsername(username); member.setUsername(username);
member.setPassword(memberService.encodePassword(password)); member.setPassword(encodePwd);
member.setEmail(email); member.setEmail(email);
member.setCreate_ip(ServletUtil.remoteIp(request)); member.setCreate_ip(ServletUtil.remoteIp(request));
member.setCreate_time(System.currentTimeMillis()); member.setCreate_time(System.currentTimeMillis());
member.setLang(locale == null ? "zh" : locale.getLanguage()); member.setLang(locale == null ? "zh" : locale.getLanguage());
member.setState(1); member.setState(1);
if(memberService.exists(email)) {
throw new XException(messages.get("err.user_exists"));
}
memberService.saveMember(member); memberService.saveMember(member);
return Rjx.jsonOk(); return Rjx.jsonOk();
} }
@ResponseBody @ResponseBody
@PostMapping("getPassword") @PostMapping("resetPassword")
@ApiOperation("找回密码") @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) { public Object resetPassword(String email) {
XException.assertNotBlank(messages.get("err.email_null"), email);
int code = (int) ((Math.random() * 9 + 1) * 10000000); int code = (int) ((Math.random() * 9 + 1) * 10000000);
String newPassword = String.valueOf(code); String password = String.valueOf(code);
Fc_member member = memberService.getMemberByEmail(email); Fc_member member = memberService.getMemberByEmail(email);
memberService.changePassword(member.getAddress(), newPassword); String encodePwd = Common.encodePassword(password, member.getSalt());
memberService.changePassword(member.getId(), encodePwd);
String name = member.getUsername();
String subject = messages.get("email.getPassword.subject"); String subject = messages.get("email.getPassword.subject");
String content = messages.get("email.getPassword.subject", member.getRealname(), newPassword); String content = messages.get("email.getPassword.content", name == null ? "" : name, password);
emailService.send(subject, content, email); emailService.send(subject, content, email);
return Rjx.jsonOk(); return Rjx.jsonOk();
} }
public static void main(String[] args) {
/**
* com.egolm.film.email.smtp.host=mail.egolm.com
com.egolm.film.email.smtp.port=25
com.egolm.film.email.smtp.is_auth=true
com.egolm.film.email.smtp.from=qu.xinliang@egolm.com
com.egolm.film.email.smtp.password=Liang12345
*/
String host = "mail.egolm.com";
Integer port = 25;
Boolean is_auth = true;
String content = "测试邮件";
String from = "qu.xinliang@egolm.com";
String password = "Liang12345";
String to = "747539993@qq.com";
String subject = "测试邮件";
MailUtil.sendBySmtp(host, port, is_auth, from, password, subject, content, null, to);
}
@ResponseBody @ResponseBody
@PostMapping("setLocale") @PostMapping("setLocale")
@ApiOperation("设置语言环境") @ApiOperation("设置语言环境")
...@@ -90,7 +124,7 @@ public class MemberOpenApiController { ...@@ -90,7 +124,7 @@ public class MemberOpenApiController {
@PostMapping("getLocale") @PostMapping("getLocale")
@ApiOperation("获取当前语言环境") @ApiOperation("获取当前语言环境")
public Object getLocale(HttpServletRequest request) { public Object getLocale(HttpServletRequest request) {
return Rjx.jsonOk().setMessage(LocaleContextHolder.getLocale().toString()); return Rjx.jsonOk().set("locale", LocaleContextHolder.getLocale().toString()).set("msg.test", messages.get("msg.test"));
} }
} }
package com.egolm.film.api.member; package com.egolm.film.api.member;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -7,6 +11,14 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -7,6 +11,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.film.api.member.model.ApplyModel; import com.egolm.film.api.member.model.ApplyModel;
import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member_film;
import com.egolm.film.bean.Fc_member_film_director;
import com.egolm.film.bean.Fc_member_film_issuer;
import com.egolm.film.bean.Fc_member_film_playactor;
import com.egolm.film.bean.Fc_member_film_show;
import com.egolm.film.login.service.MemberTokenService;
import com.egolm.film.model.LoginToken;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -18,11 +30,20 @@ import io.swagger.annotations.ApiOperation; ...@@ -18,11 +30,20 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping("member/apply") @RequestMapping("member/apply")
public class MemberApplyController { public class MemberApplyController {
@Autowired
private MemberService memberService;
@Autowired
private MemberTokenService tokenService;
@ResponseBody @ResponseBody
@PostMapping("list") @PostMapping("list")
@ApiOperation("申报项目查询") @ApiOperation("申报项目查询")
public Object list() { public Object list() {
return Rjx.jsonOk(); LoginToken loginToken = tokenService.getToken();
Integer member_id = (Integer)loginToken.getId();
List<Map<String, Object>> list = memberService.queryListByMemberID(member_id);
return Rjx.jsonOk().setData(list);
} }
@ResponseBody @ResponseBody
...@@ -35,16 +56,24 @@ public class MemberApplyController { ...@@ -35,16 +56,24 @@ public class MemberApplyController {
@ResponseBody @ResponseBody
@PostMapping("get") @PostMapping("get")
@ApiOperation("获取申报详情") @ApiOperation("获取申报详情")
@ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "id")}) @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "long", required = true, name = "id")})
public Object get(String id) { public Object get(Long id) {
return Rjx.jsonOk(); Fc_member_film memberFilm = memberService.queryMemberFilmById(id);
List<Fc_member_film_director> directorList = memberService.queryMemberFilmDirectorList(memberFilm.getId());
List<Fc_member_film_issuer> issuerList = memberService.queryMemberFilmIssuerList(memberFilm.getId());
List<Fc_member_film_playactor> playactorList = memberService.queryMemberFilmPlayactorList(memberFilm.getId());
List<Fc_member_film_show> showList = memberService.queryMemberFilmShowList(memberFilm.getId());
return Rjx.jsonOk().setData(memberFilm).set("directorList", directorList).set("issuerList", issuerList).set("playactorList", playactorList).set("showList", showList);
} }
@ResponseBody @ResponseBody
@PostMapping("doApply") @PostMapping("doApply")
@ApiOperation("提交申报") @ApiOperation("提交申报")
@ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "id")}) @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "id")})
public Object doApply(String id) { public Object doApply(Long id) {
LoginToken loginToken = tokenService.getToken();
Integer member_id = (Integer)loginToken.getId();
memberService.doApply(member_id, id);
return Rjx.jsonOk(); return Rjx.jsonOk();
} }
......
package com.egolm.film.api.member; package com.egolm.film.api.member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; 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.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member;
import com.egolm.film.login.service.MemberTokenService;
import com.egolm.film.model.LoginToken;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -17,11 +22,20 @@ import io.swagger.annotations.ApiOperation; ...@@ -17,11 +22,20 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping("member/info") @RequestMapping("member/info")
public class MemberInfoController { public class MemberInfoController {
@Autowired
private MemberTokenService tokenService;
@Autowired
private MemberService memberService;
@ResponseBody @ResponseBody
@PostMapping("query") @PostMapping("query")
@ApiOperation("查询会员基本信息") @ApiOperation("查询会员基本信息")
public Object query() { public Object query() {
return Rjx.jsonOk(); LoginToken loginToken = tokenService.getToken();
Integer id = (Integer)loginToken.getId();
Fc_member member = memberService.getMemberById(id);
return Rjx.jsonOk().setData(member);
} }
@ResponseBody @ResponseBody
...@@ -35,6 +49,9 @@ public class MemberInfoController { ...@@ -35,6 +49,9 @@ public class MemberInfoController {
@ApiImplicitParam(paramType = "query", dataType = "string", required = false, name = "tel"), @ApiImplicitParam(paramType = "query", dataType = "string", required = false, name = "tel"),
}) })
public Object save(String email, String realname, String address, String company, String tel) { public Object save(String email, String realname, String address, String company, String tel) {
LoginToken loginToken = tokenService.getToken();
Integer id = (Integer)loginToken.getId();
memberService.updateMember(id, email, realname, address, company, tel);
return Rjx.jsonOk(); return Rjx.jsonOk();
} }
......
...@@ -6,6 +6,11 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -6,6 +6,11 @@ import io.swagger.annotations.ApiModelProperty;
@ApiModel @ApiModel
public class ApplyModel { public class ApplyModel {
/**
* 会员影片表主键
*/
private String id;
/** /**
* 基本信息 * 基本信息
*/ */
...@@ -519,4 +524,12 @@ public class ApplyModel { ...@@ -519,4 +524,12 @@ public class ApplyModel {
this.film_apply_country = film_apply_country; this.film_apply_country = film_apply_country;
} }
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
} }
package com.egolm.film.api.member.service;
import java.util.List;
import java.util.Map;
import com.egolm.film.bean.Fc_member;
import com.egolm.film.bean.Fc_member_film;
import com.egolm.film.bean.Fc_member_film_director;
import com.egolm.film.bean.Fc_member_film_issuer;
import com.egolm.film.bean.Fc_member_film_playactor;
import com.egolm.film.bean.Fc_member_film_show;
public interface MemberService {
Fc_member getMemberByEmail(String email);
void changePassword(Integer id, String newPassword);
void saveMember(Fc_member member);
Fc_member getMemberById(Integer id);
void mergeMember(Fc_member member);
void updateMember(Integer id, String email, String realname, String address, String company, String tel);
List<Map<String, Object>> queryListByMemberID(Integer member_id);
boolean exists(String email);
Fc_member_film queryMemberFilmById(Long id);
List<Fc_member_film_director> queryMemberFilmDirectorList(Long member_film_id);
List<Fc_member_film_issuer> queryMemberFilmIssuerList(Long member_film_id);
List<Fc_member_film_playactor> queryMemberFilmPlayactorList(Long member_film_id);
List<Fc_member_film_show> queryMemberFilmShowList(Long member_film_id);
void doApply(Integer member_id, Long member_film_id);
}
package com.egolm.film.api.member.service.impl;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member;
import com.egolm.film.bean.Fc_member_film;
import com.egolm.film.bean.Fc_member_film_director;
import com.egolm.film.bean.Fc_member_film_issuer;
import com.egolm.film.bean.Fc_member_film_playactor;
import com.egolm.film.bean.Fc_member_film_show;
@Service
public class MemberServiceImpl implements MemberService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public void changePassword(Integer id, String newPassword) {
String sql = "update fc_member set password = ? where id = ?";
jdbcTemplate.executeUpdate(sql, newPassword, id);
}
@Override
public Fc_member getMemberByEmail(String email) {
String sql = "select * from fc_member where email = ?";
return jdbcTemplate.queryForBean(sql, Fc_member.class, email);
}
@Override
public void saveMember(Fc_member member) {
jdbcTemplate.save(member);
}
@Override
public Fc_member getMemberById(Integer id) {
String sql = "select * from fc_member where id = ?";
return jdbcTemplate.queryForBean(sql, Fc_member.class, id);
}
@Override
public void mergeMember(Fc_member member) {
jdbcTemplate.merge(member);
}
@Override
public void updateMember(Integer id, String email, String realname, String address, String company, String tel) {
String sql = "update fc_member set email = ?, realname = ?, address = ?, company = ?, tel = ? where id = ?";
jdbcTemplate.executeUpdate(sql, email, realname, address, company, tel, id);
}
@Override
public List<Map<String, Object>> queryListByMemberID(Integer member_id) {
String sql = "select * from fc_member_film where member_id = ?";
return jdbcTemplate.queryForList(sql, member_id);
}
@Override
public boolean exists(String email) {
return jdbcTemplate.queryForInt("select count(*) from fc_member where email = ?", email) > 0;
}
@Override
public Fc_member_film queryMemberFilmById(Long id) {
return jdbcTemplate.queryForBean("select * from fc_member_film where id = ?", Fc_member_film.class, id);
}
@Override
public List<Fc_member_film_director> queryMemberFilmDirectorList(Long member_film_id) {
return jdbcTemplate.queryForBeans("select * from fc_member_film_director where film_id = ?", Fc_member_film_director.class, member_film_id);
}
@Override
public List<Fc_member_film_issuer> queryMemberFilmIssuerList(Long member_film_id) {
return jdbcTemplate.queryForBeans("select * from fc_member_film_issuer where film_id = ?", Fc_member_film_issuer.class, member_film_id);
}
@Override
public List<Fc_member_film_playactor> queryMemberFilmPlayactorList(Long member_film_id) {
return jdbcTemplate.queryForBeans("select * from fc_member_film_playactor where film_id = ?", Fc_member_film_playactor.class, member_film_id);
}
@Override
public List<Fc_member_film_show> queryMemberFilmShowList(Long member_film_id) {
return jdbcTemplate.queryForBeans("select * from fc_member_film_show where film_id = ?", Fc_member_film_show.class, member_film_id);
}
@Override
public void doApply(Integer member_id, Long member_film_id) {
jdbcTemplate.executeUpdate("update fc_member_film set state = ?, apply_state = ? where id = ? and member_id = ?", 2, 2, member_film_id, member_id);
}
}
package com.egolm.film.bean;
import javax.persistence.Entity;
/**
* @author 曲欣亮
* @since 2018-10-10
* @version v-1.0
*/
@Entity(name="test")
public class Test implements java.io.Serializable {
private static final long serialVersionUID = 1L;
/**
* 电影编号
*/
private String film_no;
/**
* 导入时影片类型名称
*/
private String film_type_name;
/**
* 报名性质
*/
private String enroll_type_name;
/**
* 最佳男演员
*/
private String section_award_1;
/**
* 最佳女演员
*/
private String section_award_2;
/**
* 最佳影片
*/
private String section_award_3;
/**
* 最佳导演
*/
private String section_award_4;
/**
* 最佳编剧
*/
private String section_award_5;
/**
* 最佳摄影
*/
private String section_award_6;
/**
* 评选奖项7
*/
private String section_award_7;
/**
* 评选奖项8
*/
private String section_award_8;
private Long id;
/**
* 英文名称
*/
private String en_name;
/**
* 中文片名
*/
private String cn_name;
/**
* 该片已参加过的电影节及所获奖项
*/
private String prize;
/**
* 无参数构造方法
*/
public Test () {
super();
}
/**
* 全参数构造方法
* @param film_no 电影编号
* @param film_type_name 导入时影片类型名称
* @param enroll_type_name 报名性质
* @param section_award_1 最佳男演员
* @param section_award_2 最佳女演员
* @param section_award_3 最佳影片
* @param section_award_4 最佳导演
* @param section_award_5 最佳编剧
* @param section_award_6 最佳摄影
* @param section_award_7 评选奖项7
* @param section_award_8 评选奖项8
* @param id
* @param en_name 英文名称
* @param cn_name 中文片名
* @param prize 该片已参加过的电影节及所获奖项
*/
public Test(String film_no, String film_type_name, String enroll_type_name, String section_award_1, String section_award_2, String section_award_3, String section_award_4, String section_award_5, String section_award_6, String section_award_7, String section_award_8, Long id, String en_name, String cn_name, String prize) {
this.film_no = film_no;
this.film_type_name = film_type_name;
this.enroll_type_name = enroll_type_name;
this.section_award_1 = section_award_1;
this.section_award_2 = section_award_2;
this.section_award_3 = section_award_3;
this.section_award_4 = section_award_4;
this.section_award_5 = section_award_5;
this.section_award_6 = section_award_6;
this.section_award_7 = section_award_7;
this.section_award_8 = section_award_8;
this.id = id;
this.en_name = en_name;
this.cn_name = cn_name;
this.prize = prize;
}
public void setFilm_no(String film_no) {
this.film_no = film_no;
}
public String getFilm_no() {
return film_no;
}
public void setFilm_type_name(String film_type_name) {
this.film_type_name = film_type_name;
}
public String getFilm_type_name() {
return film_type_name;
}
public void setEnroll_type_name(String enroll_type_name) {
this.enroll_type_name = enroll_type_name;
}
public String getEnroll_type_name() {
return enroll_type_name;
}
public void setSection_award_1(String section_award_1) {
this.section_award_1 = section_award_1;
}
public String getSection_award_1() {
return section_award_1;
}
public void setSection_award_2(String section_award_2) {
this.section_award_2 = section_award_2;
}
public String getSection_award_2() {
return section_award_2;
}
public void setSection_award_3(String section_award_3) {
this.section_award_3 = section_award_3;
}
public String getSection_award_3() {
return section_award_3;
}
public void setSection_award_4(String section_award_4) {
this.section_award_4 = section_award_4;
}
public String getSection_award_4() {
return section_award_4;
}
public void setSection_award_5(String section_award_5) {
this.section_award_5 = section_award_5;
}
public String getSection_award_5() {
return section_award_5;
}
public void setSection_award_6(String section_award_6) {
this.section_award_6 = section_award_6;
}
public String getSection_award_6() {
return section_award_6;
}
public void setSection_award_7(String section_award_7) {
this.section_award_7 = section_award_7;
}
public String getSection_award_7() {
return section_award_7;
}
public void setSection_award_8(String section_award_8) {
this.section_award_8 = section_award_8;
}
public String getSection_award_8() {
return section_award_8;
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setEn_name(String en_name) {
this.en_name = en_name;
}
public String getEn_name() {
return en_name;
}
public void setCn_name(String cn_name) {
this.cn_name = cn_name;
}
public String getCn_name() {
return cn_name;
}
public void setPrize(String prize) {
this.prize = prize;
}
public String getPrize() {
return prize;
}
}
package com.egolm.film.common;
import com.egolm.film.bean.Fc_member;
public interface MemberService {
String encodePassword(String password);
Fc_member getMemberByEmail(String email);
void changePassword(String id, String newPassword);
void saveMember(Fc_member member);
}
...@@ -20,7 +20,8 @@ public class DefaultMessages implements Messages { ...@@ -20,7 +20,8 @@ public class DefaultMessages implements Messages {
public String get(String name, String... args) { public String get(String name, String... args) {
try { try {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
return messageSource.getMessage(name, args, locale == null ? Locale.CHINA : locale); locale = locale == null ? Locale.CHINA : locale;
return messageSource.getMessage(name, args, locale);
} catch (NoSuchMessageException e) { } catch (NoSuchMessageException e) {
return name; return name;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -17,7 +17,7 @@ public class EmailServiceImpl implements EmailService { ...@@ -17,7 +17,7 @@ public class EmailServiceImpl implements EmailService {
@Override @Override
public void send(String subject, String content, String... emailAddress) { public void send(String subject, String content, String... emailAddress) {
MailUtil.sendBySmtp(host, port, is_auth, content, password, subject, content, null, emailAddress); MailUtil.sendBySmtp(host, port, is_auth, from, 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 = ?";
jdbcTemplate.executeUpdate(sql, this.encodePassword(newPassword), id);
}
@Override
public Fc_member getMemberByEmail(String email) {
String sql = "select * from fc_member where email = ?";
return jdbcTemplate.queryForBean(sql, Fc_member.class, email);
}
@Override
public String encodePassword(String password) {
return StringUtil.toMD5HexString(password);
}
@Override
public void saveMember(Fc_member member) {
jdbcTemplate.save(member);
}
}
package com.egolm.film.config;
import java.util.Random;
import com.egolm.common.StringUtil;
public class Common {
public static final String SOURCES="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
public static String getGenerateString(int length) {
Random random = new Random();
char[] text = new char[length];
for (int i = 0; i < length; i++) {
text[i] = SOURCES.charAt(random.nextInt(SOURCES.length()));
}
return new String(text);
}
public static String encodePassword(String password, String salt) {
return StringUtil.toMD5HexString(StringUtil.toMD5HexString(password + salt).toLowerCase().substring(4, 24)).toLowerCase();
}
}
package com.egolm.film.config;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
@Configuration
public class LocaleConfig {
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("i18n/messages");
messageSource.setDefaultEncoding("utf-8");
messageSource.setAlwaysUseMessageFormat(true);
messageSource.setCacheSeconds(-1);
return messageSource;
}
}
...@@ -19,6 +19,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -19,6 +19,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import com.egolm.film.config.interceptor.AdminLoginInterceptor; import com.egolm.film.config.interceptor.AdminLoginInterceptor;
import com.egolm.film.config.interceptor.LocaleSessionInterceptor; import com.egolm.film.config.interceptor.LocaleSessionInterceptor;
import com.egolm.film.config.interceptor.MemberLoginInterceptor;
import com.egolm.film.config.interceptor.UserLoginInterceptor; import com.egolm.film.config.interceptor.UserLoginInterceptor;
@Configuration @Configuration
...@@ -31,7 +32,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { ...@@ -31,7 +32,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
private UserLoginInterceptor userLoginInterceptor; private UserLoginInterceptor userLoginInterceptor;
@Autowired @Autowired
private UserLoginInterceptor memberLoginInterceptor; private MemberLoginInterceptor memberLoginInterceptor;
@Autowired @Autowired
private LocaleSessionInterceptor localeSessionInterceptor; private LocaleSessionInterceptor localeSessionInterceptor;
...@@ -42,6 +43,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { ...@@ -42,6 +43,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
registry.addInterceptor(adminLoginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login"); registry.addInterceptor(adminLoginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login");
registry.addInterceptor(userLoginInterceptor).addPathPatterns("/user/**").excludePathPatterns("/user/login"); registry.addInterceptor(userLoginInterceptor).addPathPatterns("/user/**").excludePathPatterns("/user/login");
registry.addInterceptor(memberLoginInterceptor).addPathPatterns("/member/**").excludePathPatterns("/member/login"); registry.addInterceptor(memberLoginInterceptor).addPathPatterns("/member/**").excludePathPatterns("/member/login");
} }
@Override @Override
......
...@@ -36,7 +36,7 @@ public class MemberLoginController { ...@@ -36,7 +36,7 @@ public class MemberLoginController {
} else { } else {
LoginToken token = tokenService.doLogin(username, password); LoginToken token = tokenService.doLogin(username, password);
if(token != null) { if(token != null) {
return Rjx.jsonOk().setData(token); return Rjx.jsonOk();
} else { } else {
throw new XException(messages.get("sys.err.user_or_pwd")); throw new XException(messages.get("sys.err.user_or_pwd"));
} }
......
package com.egolm.film.login.service.impl; package com.egolm.film.login.service.impl;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil; import com.egolm.film.api.member.service.MemberService;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.film.bean.Fc_member;
import com.egolm.film.common.Messages; import com.egolm.film.common.Messages;
import com.egolm.film.config.Common;
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;
...@@ -23,35 +21,29 @@ public class MemberTokenServiceImpl implements MemberTokenService { ...@@ -23,35 +21,29 @@ public class MemberTokenServiceImpl implements MemberTokenService {
private Messages messages; private Messages messages;
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private MemberService memberService;
@Override @Override
public LoginToken doLogin(String username, String password) { public LoginToken doLogin(String email, String password) {
HttpSession session = WebMvcConfig.getSession(); HttpSession session = WebMvcConfig.getSession();
String md5String = StringUtil.toMD5HexString(password); Fc_member member = memberService.getMemberByEmail(email);
String loginSql = "select * from fc_member where username = ? and password = ?"; Integer state = member.getState();
List<Map<String, Object>> list = this.jdbcTemplate.queryForList(loginSql, username, md5String);
if(list != null) {
if(list.size() == 1) {
Map<String,Object> map = list.get(0);
Integer state = (Integer)map.get("state");
if(state == 1) { if(state == 1) {
Integer adminid = (Integer)map.get("adminid"); String salt = member.getSalt();
LoginToken token = new LoginToken(adminid); String dbPwd = member.getPassword();
String encodePassword = Common.encodePassword(password, salt);
if(encodePassword.equals(dbPwd)) {
Integer id = member.getId();
LoginToken token = new LoginToken(id);
session.setAttribute(TOKEN_NAME, token); session.setAttribute(TOKEN_NAME, token);
return token; return token;
} else if(state == 2) {
throw new XException(messages.get("sys.err.user_disabled"));
} else { } else {
throw new XException(messages.get("sys.err"));
}
} else if(list.size() == 0) {
throw new XException(messages.get("sys.err.user_pwd_err")); throw new XException(messages.get("sys.err.user_pwd_err"));
} else {
throw new XException(messages.get("sys.err"));
} }
} else if(state == 2) {
throw new XException(messages.get("sys.err.user_disabled"));
} else { } else {
throw new XException(messages.get("sys.err.user_pwd_err")); throw new XException(messages.get("sys.err"));
} }
} }
......
...@@ -24,7 +24,7 @@ public class UserTokenServiceImpl implements UserTokenService { ...@@ -24,7 +24,7 @@ public class UserTokenServiceImpl implements UserTokenService {
@Override @Override
public LoginToken doLogin(String username, String password) { public LoginToken doLogin(String username, String password) {
HttpSession session = WebMvcConfig.getSession(); HttpSession session = WebMvcConfig.getSession();
String md5String = StringUtil.toMD5HexString(password); String md5String = StringUtil.toMD5HexString(password).toLowerCase();
String loginSql = "select * from fc_user where username = ? and password = ?"; String loginSql = "select * from fc_user where username = ? and password = ?";
List<Map<String, Object>> list = this.jdbcTemplate.queryForList(loginSql, username, md5String); List<Map<String, Object>> list = this.jdbcTemplate.queryForList(loginSql, username, md5String);
if(list != null) { if(list != null) {
......
spring.datasource.url=jdbc:mysql://10.10.0.111:3306/film_dev?useSSL=false&useUnicode=true&characterEncoding=utf8 spring.datasource.url=jdbc:mysql://10.10.0.111:3306/film_critic_2018?useSSL=false&useUnicode=true&characterEncoding=utf8
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=egolm#2018 spring.datasource.password=egolm#2018
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.driver-class-name=com.mysql.jdbc.Driver
......
spring.datasource.url=jdbc:mysql://10.10.0.111:3306/film_dev?useSSL=false&useUnicode=true&characterEncoding=utf8 spring.datasource.url=jdbc:mysql://10.10.0.111:3306/film_critic_2018?useSSL=false&useUnicode=true&characterEncoding=utf8
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=egolm#2018 spring.datasource.password=egolm#2018
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.driver-class-name=com.mysql.jdbc.Driver
......
...@@ -13,12 +13,8 @@ spring.http.encoding.force=true ...@@ -13,12 +13,8 @@ spring.http.encoding.force=true
spring.http.encoding.enabled=true spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8 spring.http.encoding.charset=utf-8
spring.messages.basename=classpath:i18n/messages com.egolm.film.email.smtp.host=mail.egolm.com
spring.messages.cache-seconds=3600
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.port=25
com.egolm.film.email.smtp.is_auth=true com.egolm.film.email.smtp.is_auth=true
com.egolm.film.email.smtp.from=15601712556@163.com com.egolm.film.email.smtp.from=qu.xinliang@egolm.com
com.egolm.film.email.smtp.password=Liang12345 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_pwd_err=\u7528\u6237\u6216\u5BC6\u7801\u9519\u8BEF
sys.err.user_pwd_null=\u7528\u6237\u540D\u548C\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
msg.hello=\u60A8\u597D
msg.your_pwd=\u60A8\u7684\u5BC6\u7801\u662F
\ No newline at end of file
msg.test=Test
email.getPassword.subject=China Film Festival [retrieve password] email
email.getPassword.content=Hello {0}, Your password is: [{1}]
err=System error
err.user_disabled=User disabled
err.user_pwd_err=User or password error
err.user_pwd_null=User and passowrd can not be null
err.user_exists=User already exists
err.email_null=The mailbox can not be empty
err.name_null=The username can not be empty
err.pwd_null=The password can not be empty
msg.test=\u6D4B\u8BD5
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}]
err=\u7CFB\u7EDF\u9519\u8BEF
err.user_disabled=\u7528\u6237\u5DF2\u7ECF\u7981\u7528
err.user_pwd_err=\u7528\u6237\u6216\u5BC6\u7801\u9519\u8BEF
err.user_pwd_null=\u7528\u6237\u540D\u548C\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
err.user_exists=\u7528\u6237\u5DF2\u5B58\u5728
err.email_null=\u90AE\u7BB1\u4E0D\u80FD\u4E3A\u7A7A
err.name_null=\u59D3\u540D\u4E0D\u80FD\u4E3A\u7A7A
err.pwd_null=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
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