|
@@ -2,12 +2,11 @@ package com.lsw.controller.front.user;
|
|
|
|
|
|
import com.jfinal.kit.HashKit;
|
|
|
import com.jfinal.kit.Ret;
|
|
|
-import com.jfinal.kit.StrKit;
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.jfinal.plugin.ehcache.CacheKit;
|
|
|
import com.lsw.commons.utils.Constant;
|
|
|
-import com.lsw.model.work.User;
|
|
|
import com.lsw.model.work.Token;
|
|
|
+import com.lsw.model.work.User;
|
|
|
import org.apache.shiro.crypto.hash.SimpleHash;
|
|
|
import org.apache.shiro.util.SimpleByteSource;
|
|
|
|
|
@@ -23,16 +22,16 @@ public class AppUserService {
|
|
|
Ret ret = Ret.create();
|
|
|
//第一次登录先保存用户信息
|
|
|
User user = dao.findFirst("select * from tb_user where account=?", account);
|
|
|
- if(user==null){
|
|
|
+ if (user == null) {
|
|
|
ret.set("result", false).set("msg", "用户不存在");
|
|
|
return ret;
|
|
|
}
|
|
|
- String v_pass=new SimpleHash("MD5", new SimpleByteSource(pass), new SimpleByteSource(user.getSalt()), 2).toHex();
|
|
|
- if(!v_pass.equals(user.getPassword())){
|
|
|
+ String v_pass = HashKit.sha256(pass+ user.getSalt());
|
|
|
+ if (!v_pass.equals(user.getPassword())) {
|
|
|
ret.set("result", false).set("msg", "密码错误!");
|
|
|
return ret;
|
|
|
}
|
|
|
- if(user.getMSate()==1){
|
|
|
+ if (user.getMSate() == 1) {
|
|
|
ret.set("result", false).set("msg", "该账户被限制登录");
|
|
|
return ret;
|
|
|
}
|
|
@@ -40,8 +39,8 @@ public class AppUserService {
|
|
|
Token token = new Token();
|
|
|
String secret = HashKit.generateSaltForSha256();
|
|
|
token.setSecret(secret);
|
|
|
- //token.setPhone(account);
|
|
|
- token.put("mSate",0);
|
|
|
+ token.setPhone(account);
|
|
|
+ token.put("mSate", 0);
|
|
|
token.save();
|
|
|
user.put("token", secret);
|
|
|
CacheKit.put(Constant.token, account, token);
|
|
@@ -60,7 +59,7 @@ public class AppUserService {
|
|
|
public Token loginBySecret(String secret, String phone) {
|
|
|
Token token = CacheKit.get(Constant.token, phone);
|
|
|
if (token == null) {
|
|
|
- token = Token.dao.findFirst("SELECT u.mSate FROM tb_token t LEFT JOIN tb_app_user u ON u.account = t.phone WHERE t.secret=? AND t.phone=? ORDER BY t.id DESC", secret, phone);
|
|
|
+ token = Token.dao.findFirst("SELECT u.mSate FROM tb_token t LEFT JOIN tb_user u ON u.account = t.phone WHERE t.secret=? AND t.phone=? ORDER BY t.id DESC", secret, phone);
|
|
|
CacheKit.put(Constant.token, phone, token);
|
|
|
}
|
|
|
return token;
|
|
@@ -73,83 +72,64 @@ public class AppUserService {
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean check(String account) {
|
|
|
- User user = dao.findFirst("select * from tb_app_user where account=?", account);
|
|
|
+ User user = dao.findFirst("select * from tb_user where account=?", account);
|
|
|
return user == null ? true : false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 用户注册
|
|
|
- *
|
|
|
- * @param account 手机号
|
|
|
- * @param password 密码
|
|
|
- * @param newsCode 验证码
|
|
|
* @return
|
|
|
*/
|
|
|
- public Ret register(String account, String password, String newsCode) {
|
|
|
+ public Ret register(User user) {
|
|
|
Ret ret = Ret.create();
|
|
|
- boolean check = check(account);
|
|
|
- if (check) {
|
|
|
- String code = CacheKit.get(Constant.code, account);
|
|
|
- if (code == null) {
|
|
|
- ret.set("result", false).set("msg", "验证码超过有效期");
|
|
|
- CacheKit.remove(Constant.code, account);
|
|
|
- return ret;
|
|
|
- }
|
|
|
- if (code.equals(newsCode)) {
|
|
|
- String salt = HashKit.generateSaltForSha256();
|
|
|
- User user = new User();
|
|
|
- user.setAccount(account);
|
|
|
- user.setHeader("/upload/images/header/ls.png");
|
|
|
- user.setSalt(salt);
|
|
|
- //密码加密
|
|
|
- user.setPassword(HashKit.sha256(password + salt));
|
|
|
- user.setMTime(new Date());
|
|
|
- user.save();
|
|
|
- ret.set("result", true);
|
|
|
- } else {
|
|
|
- ret.set("result", false).set("msg", "验证码不正确");
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- ret.set("result", false).set("msg", "手机号已被注册");
|
|
|
+ boolean check = check(user.getAccount());
|
|
|
+ if (!check) {
|
|
|
+ return ret.set("result", false).set("msg", "手机号已被注册");
|
|
|
+ }
|
|
|
+ String code = CacheKit.get(Constant.code, user.getAccount());
|
|
|
+ if (code == null) {
|
|
|
+ CacheKit.remove(Constant.code, user.getAccount());
|
|
|
+ return ret.set("result", false).set("msg", "验证码超过有效期");
|
|
|
+ }
|
|
|
+ System.out.println("code:" + user.get("code"));
|
|
|
+ if (!code.equals(user.get("code"))) {
|
|
|
+ return ret.set("result", false).set("msg", "验证码不正确");
|
|
|
}
|
|
|
+ //默认设置一个头像
|
|
|
+ user.setHeader("/upload/images/header/ls.png");
|
|
|
+ user.setNickName("用户");
|
|
|
+ //密码加密
|
|
|
+ String salt = HashKit.generateSaltForSha256();
|
|
|
+ user.setSalt(salt);
|
|
|
+ //刚注册的企业用户状态:未审核
|
|
|
+ if (user.getMType()==1){
|
|
|
+ user.setMSate(2);
|
|
|
+ }
|
|
|
+ user.setPassword(HashKit.sha256(user.getPassword() + salt));
|
|
|
+ user.setMTime(new Date());
|
|
|
+ user.save();
|
|
|
+ ret.set("result", true);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 找回密码
|
|
|
- *
|
|
|
- * @param account 账号
|
|
|
- * @param password 密码
|
|
|
- * @param newsCode 验证码
|
|
|
* @return
|
|
|
*/
|
|
|
- public Ret findPass(String account, String password, String newsCode) {
|
|
|
+ public Ret edit_pass(User user) {
|
|
|
Ret ret = Ret.create();
|
|
|
- boolean check = check(account);
|
|
|
- if (check) {
|
|
|
- ret.set("result", false).set("msg", "该号码未注册");
|
|
|
- } else {
|
|
|
- String code = CacheKit.get(Constant.code, account);
|
|
|
- if (code == null) {
|
|
|
- ret.set("result", false).set("msg", "验证码超过有效期");
|
|
|
- CacheKit.remove(Constant.code, account);
|
|
|
- return ret;
|
|
|
- }
|
|
|
- if (code.equals(newsCode)) {
|
|
|
- String salt = HashKit.generateSaltForSha256();
|
|
|
- //密码加密
|
|
|
- password = HashKit.sha256(password + salt);
|
|
|
- int row = Db.update("update tb_app_user set password =?,salt=? where account=?", password, salt, account);
|
|
|
- if (row > 0) {
|
|
|
- ret.set("result", true);
|
|
|
- } else {
|
|
|
- ret.set("result", false).set("msg", "找回密码失败");
|
|
|
- }
|
|
|
- } else {
|
|
|
- ret.set("result", false).set("msg", "验证码不正确");
|
|
|
- }
|
|
|
+ String code = CacheKit.get(Constant.code, user.getAccount());
|
|
|
+ if (code == null) {
|
|
|
+ CacheKit.remove(Constant.code, user.getAccount());
|
|
|
+ return ret.set("result", false).set("msg", "验证码超过有效期");
|
|
|
}
|
|
|
+ System.out.println("code:" + user.get("code"));
|
|
|
+ if (!code.equals(user.get("code"))) {
|
|
|
+ return ret.set("result", false).set("msg", "验证码不正确");
|
|
|
+ }
|
|
|
+ //密码加密
|
|
|
+ String salt = HashKit.generateSaltForSha256();
|
|
|
+ Db.update("update tb_user set password =?,salt=? where account=?", HashKit.sha256(user.getPassword() + salt), salt, user.getAccount());
|
|
|
+ ret.set("result", true);
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
}
|