From e97c393e23f4c015a44b5fef5fd26ae288bc6c0f Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Wed, 10 Jul 2019 11:31:35 +0800
Subject: [PATCH] 天气预报

---
 src/main/java/com/moral/service/impl/AccountServiceImpl.java |   39 ++++++++++++++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/moral/service/impl/AccountServiceImpl.java b/src/main/java/com/moral/service/impl/AccountServiceImpl.java
index d441f1f..243ac98 100644
--- a/src/main/java/com/moral/service/impl/AccountServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/AccountServiceImpl.java
@@ -2,7 +2,6 @@
 
 import static com.moral.common.bean.Constants.IS_DELETE_FALSE;
 import static com.moral.common.bean.Constants.IS_DELETE_TRUE;
-import static com.moral.common.util.Crypto.md5;
 import static com.moral.common.util.ResourceUtil.getValue;
 import static org.apache.commons.lang3.StringUtils.isNumeric;
 import static org.springframework.util.ObjectUtils.isEmpty;
@@ -11,6 +10,7 @@
 
 import javax.annotation.Resource;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -22,6 +22,7 @@
 import com.moral.common.exception.BusinessException;
 import com.moral.common.util.Crypto;
 import com.moral.common.util.ResourceUtil;
+import com.moral.common.util.ValidateUtil;
 import com.moral.entity.Account;
 import com.moral.entity.Organization;
 import com.moral.mapper.AccountMapper;
@@ -50,15 +51,18 @@
 		Map<String, Object> result = new HashMap<String, Object>();
 		Account account = new Account();
 		account.setAccountName((String) parameters.get("account"));
-		account.setPassword(md5((String) parameters.get("password")));
+		String rawPassword = (String) parameters.get("password");
+//		account.setPassword(encoder.encode((String) parameters.get("password")));
 		account = accountMapper.selectOne(account);
-		if (isEmpty(account)) {
+		boolean isValid = account == null ? false:encoder.matches(rawPassword,account.getPassword());
+		if (!isValid) {
 			result.put("msg", "���������������������������������");
 		} else {
 			if (IS_DELETE_FALSE.equals(account.getIsDelete())) {
 				result.put("msg", "���������������");
 				result.put("accountId", account.getId());
 				result.put("orgId", account.getOrganizationId());
+				setOrgIdsByAccount(result);
 			} else {
 				result.put("msg","���������������������������������������������");
 			}
@@ -78,9 +82,9 @@
 	}
 	@Override
 	public void setOrgIdsByAccount(Map<String, Object> parameters) {
-		String accountId = (String) parameters.get("accountId");
+		String accountId = parameters.get("accountId").toString();
 		accountId = accountId.replaceFirst("-", "");
-		if (!isNumeric((String) parameters.get("accountId"))) {
+		if (!isNumeric(accountId)) {
 			throw new BusinessException("accountId ������������������");
 		}
 
@@ -141,6 +145,10 @@
 	@Override
 	@Transactional
 	public Integer saveOrUpdateAccount(Account account) {
+		// ������������
+		if(!StringUtils.isBlank(account.getPassword())){
+			account.setPassword(encoder.encode(account.getPassword()));
+		}
 		if (ObjectUtils.isEmpty(account.getId())) {
 			account.setIsDelete(Constants.IS_DELETE_FALSE);
 			account.setCreateTime(new Date());
@@ -170,8 +178,25 @@
 
 	@Override
 	public Optional<Account> queryAccountByName(String accountName) {
+		Account account = accountMapper.getByAccountName(accountName);
+		return Optional.ofNullable(account);
+	}
+
+	@Override
+	public Account companyLogin(Map<String, Object> parameters) {
+		ValidateUtil.notNull(parameters.get("account"), "param.is.null");
+		ValidateUtil.notNull(parameters.get("password"), "param.is.null");
 		Account account = new Account();
-		account.setAccountName(accountName);
-		return Optional.ofNullable(accountMapper.selectOne(account));
+		account.setIsDelete(Constants.IS_DELETE_FALSE);
+		account.setAccountName(parameters.get("account").toString());
+		account = accountMapper.selectOne(account);
+		if (ObjectUtils.isEmpty(account)) {
+			throw new BusinessException("���������������������������������������");
+		}
+		if (!encoder.matches(parameters.get("password").toString(), account.getPassword())) {
+			throw new BusinessException("���������������������������������");
+		}
+		account.setPassword(parameters.get("password").toString());
+		return account;
 	}
 }

--
Gitblit v1.8.0