parent
ca6b6dbe24
commit
f5b6fe34ff
@ -0,0 +1,52 @@
|
||||
package au.com.royalpay.payment.manage.appclient.beans;
|
||||
|
||||
import au.com.royalpay.payment.manage.permission.utils.GeekLoginDESUtil;
|
||||
import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
|
||||
import au.com.royalpay.payment.tools.utils.PasswordUtils;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* Created by yixian on 2016-12-14.
|
||||
*/
|
||||
public class ApiClientAccountLoginInfo {
|
||||
@NotEmpty(message = "error.payment.valid.param_missing")
|
||||
private String loginId;
|
||||
@NotEmpty(message = "error.payment.valid.param_missing")
|
||||
private String password;
|
||||
|
||||
public LoginInfo ClientAccountLoginInfo(){
|
||||
LoginInfo info = new LoginInfo();
|
||||
info.setLoginId(loginId);
|
||||
info.setPassword(GeekLoginDESUtil.getDecryptString(password));
|
||||
return info;
|
||||
}
|
||||
|
||||
public String getPasswordHashed(String salt) {
|
||||
return PasswordUtils.hashPwd(password, salt);
|
||||
}
|
||||
|
||||
public String getLoginId() {
|
||||
return loginId.toLowerCase();
|
||||
}
|
||||
|
||||
public void setLoginId(String loginId) {
|
||||
this.loginId = loginId;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApiClientAccountLoginInfo{" +
|
||||
"loginId='" + loginId + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package au.com.royalpay.payment.manage.appclient.web;
|
||||
|
||||
import au.com.royalpay.payment.manage.appclient.beans.ApiClientAccountLoginInfo;
|
||||
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
||||
import au.com.royalpay.payment.manage.signin.core.SignInStatusManager;
|
||||
import au.com.royalpay.payment.manage.signin.events.ClientLoginEvent;
|
||||
import au.com.royalpay.payment.tools.env.RequestEnvironment;
|
||||
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import au.com.royalpay.payment.manage.permission.utils.GeekLoginDESUtil;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @Author DuLingLing
|
||||
* @create 2019/11/27 0027 14:30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1.0/royalpay/client")
|
||||
public class RetailClientController implements ApplicationEventPublisherAware {
|
||||
Logger logger = LoggerFactory.getLogger(getClass());
|
||||
@Resource
|
||||
private SignInStatusManager signInStatusManager;
|
||||
@Resource
|
||||
private ClientManager clientManager;
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.publisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
@PostMapping("/sigIn")
|
||||
public JSONObject signIn(@RequestBody @Valid ApiClientAccountLoginInfo loginInfo) {
|
||||
try {
|
||||
String signKey = signInStatusManager.partnerSignIn(loginInfo.ClientAccountLoginInfo());
|
||||
JSONObject account = signInStatusManager.getCurrentClient(signKey);
|
||||
JSONObject clientAllInfo = clientManager.getClientInfo(account.getInteger("client_id"));
|
||||
publisher.publishEvent(
|
||||
new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "GEEK_PASSWORD"));
|
||||
return convertResponseClientInfo(clientAllInfo);
|
||||
} catch (BadRequestException be) {
|
||||
return responseError(be.getMessage());
|
||||
} catch (Exception e) {
|
||||
return responseError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject convertResponseClientInfo(JSONObject clientAllInfo) {
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("status", "SUCCESS");
|
||||
JSONObject industryInfo = clientManager.findByLookupCode(clientAllInfo.getString("industry"));
|
||||
response.put("clientInfo", new JSONObject() {{
|
||||
put("client_moniker", clientAllInfo.getString("client_moniker"));
|
||||
put("company_name", clientAllInfo.getString("company_name"));
|
||||
put("logo_url", clientAllInfo.getString("client_moniker"));
|
||||
put("credential_code", clientAllInfo.getString("credential_code"));
|
||||
put("industry_code", clientAllInfo.getString("industry"));
|
||||
put("industry_label", industryInfo.getString("lookup_value"));
|
||||
}});
|
||||
return response;
|
||||
}
|
||||
|
||||
private JSONObject responseError(String message) {
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("status", "FAIL");
|
||||
response.put("message", message);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package au.com.royalpay.payment.manage.mappers.system;
|
||||
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
|
||||
|
||||
/**
|
||||
* @Author DuLingLing
|
||||
* @create 2019/11/27 0027 16:20
|
||||
*/
|
||||
@AutoMapper(tablename = "industry_lookup", pkName = "client_id", keyGenerator = Jdbc3KeyGenerator.class)
|
||||
public interface IndustryLookupMapper {
|
||||
@AutoSql(type = SqlType.SELECT)
|
||||
JSONObject findByLookupCode(@Param("lookup_code") String code);
|
||||
}
|
Loading…
Reference in new issue