implemented user login restful API
This commit is contained in:
@@ -8,17 +8,17 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Filename: SpringBootMybatisApplication
|
||||
* Revised: Date: 2018-12-08
|
||||
* Revised: Date: 2019-06-10
|
||||
* Revision: Revision: 1.0
|
||||
* <p>
|
||||
* Description: IRext Code Collector Application
|
||||
* Description: IRext private server application
|
||||
* <p>
|
||||
* Revision log:
|
||||
* 2018-12-08: created by strawmanbobi
|
||||
* 2019-06-10: created by strawmanbobi
|
||||
*/
|
||||
|
||||
@MappedTypes(RemoteIndex.class)
|
||||
@MapperScan("net.irext.decoder.mapper")
|
||||
@MapperScan("net.irext.server.service.mapper")
|
||||
@SpringBootApplication
|
||||
public class IRPrivateServerApplication {
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package net.irext.server.service.businesslogic;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.squareup.okhttp.*;
|
||||
import net.irext.server.service.model.UserApp;
|
||||
import net.irext.server.service.request.AppSignInRequest;
|
||||
import net.irext.server.service.response.LoginResponse;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
@@ -15,9 +19,27 @@ import org.springframework.stereotype.Controller;
|
||||
*/
|
||||
@Controller
|
||||
public class UserLoginLogic {
|
||||
private static final MediaType JSON
|
||||
= MediaType.parse("application/json; charset=utf-8");
|
||||
|
||||
public UserApp login(String appKey, String appSecret, Integer appType,
|
||||
String iosId, String androidPackageName, String androidSignature) {
|
||||
public UserApp login(AppSignInRequest appSignInRequest) {
|
||||
String url = "http://irext.net/irext-server/app/app_login";
|
||||
String requestBody = new Gson().toJson(appSignInRequest);
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
RequestBody body = RequestBody.create(JSON, requestBody);
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build();
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
String responseBody = response.body().string();
|
||||
LoginResponse loginResponse = new Gson().fromJson(responseBody, LoginResponse.class);
|
||||
return loginResponse.getEntity();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,11 +34,12 @@ import java.text.SimpleDateFormat;
|
||||
* Revised: Date: 2018-12-16
|
||||
* Revision: Revision: 1.0
|
||||
* <p>
|
||||
* Description: IRext Decode Webservice
|
||||
* Description: IRext decode service
|
||||
* <p>
|
||||
* Revision log:
|
||||
* 2018-12-16: created by strawmanbobi
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/irext-server/decode")
|
||||
@Service("IRDecodeService")
|
||||
@@ -60,10 +61,6 @@ public class IRDecodeService extends AbstractBaseService {
|
||||
@Autowired
|
||||
private IDecodeSessionRepository decodeSessionRepository;
|
||||
|
||||
public IRDecodeService(RemoteIndexMapper remoteIndexMapper) {
|
||||
this.remoteIndexMapper = remoteIndexMapper;
|
||||
}
|
||||
|
||||
@PostMapping("/open")
|
||||
public StringResponse irOpen(HttpServletRequest request, @RequestBody OpenRequest openRequest) {
|
||||
try {
|
||||
|
||||
@@ -8,30 +8,37 @@ import net.irext.server.service.request.AppSignInRequest;
|
||||
import net.irext.server.service.response.LoginResponse;
|
||||
import net.irext.server.service.response.Status;
|
||||
import net.irext.server.service.restapi.base.AbstractBaseService;
|
||||
import net.irext.server.service.utils.LoggerUtil;
|
||||
import net.irext.server.service.utils.MD5Util;
|
||||
import net.irext.server.service.utils.VeDate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Filename: SignInServiceImpl.java
|
||||
* Revised: Date: 2017-04-27
|
||||
* Revision: Revision: 1.0
|
||||
* <p>
|
||||
* Description: Admin service interface implementation
|
||||
* Description: User app login service
|
||||
* <p>
|
||||
* Revision log:
|
||||
* 2017-04-27: created by strawmanbobi
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/irext-server/app")
|
||||
@Service("SignInService")
|
||||
public class SignInService extends AbstractBaseService {
|
||||
|
||||
private static final String TAG = SignInService.class.getSimpleName();
|
||||
|
||||
@Autowired
|
||||
private UserLoginLogic loginLogic;
|
||||
|
||||
@@ -39,7 +46,8 @@ public class SignInService extends AbstractBaseService {
|
||||
private IUserAppRepository userAppRepository;
|
||||
|
||||
@PostMapping("/app_login")
|
||||
public LoginResponse signIn(AppSignInRequest appSignInRequest) {
|
||||
public LoginResponse signIn(HttpServletRequest request, @RequestBody AppSignInRequest appSignInRequest) {
|
||||
LoggerUtil.getInstance().trace(TAG, "signIn API called : " + appSignInRequest.getAppKey());
|
||||
try {
|
||||
LoginResponse response = new LoginResponse();
|
||||
response.setStatus(new Status());
|
||||
@@ -51,12 +59,7 @@ public class SignInService extends AbstractBaseService {
|
||||
return response;
|
||||
}
|
||||
|
||||
UserApp userApp = loginLogic.login(appSignInRequest.getAppKey(),
|
||||
appSignInRequest.getAppSecret(),
|
||||
appSignInRequest.getAppType(),
|
||||
appSignInRequest.getiOSID(),
|
||||
appSignInRequest.getAndroidPackageName(),
|
||||
appSignInRequest.getAndroidSignature());
|
||||
UserApp userApp = loginLogic.login(appSignInRequest);
|
||||
|
||||
if (userApp != null) {
|
||||
// generate token by date time
|
||||
|
||||
@@ -5,4 +5,4 @@ spring.redis.host=localhost
|
||||
spring.redis.port=6379
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/irext?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=root
|
||||
spring.datasource.password=421aWill.
|
||||
Reference in New Issue
Block a user