-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from zzsZhou/version2.1.0
version2.1.0
- Loading branch information
Showing
74 changed files
with
2,864 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"accounts":[],"createTime":"2020-03-26T10:46:52Z","defaultAccountAddress":"","defaultOntid":"did:ont:ARR7Rk4hpvnkAAWkyHGtrF2H3htHWrKFby","identities":[{"controls":[{"address":"ARR7Rk4hpvnkAAWkyHGtrF2H3htHWrKFby","algorithm":"ECDSA","enc-alg":"aes-256-gcm","hash":"sha256","id":"keys-1","key":"KDCGqt8JbwcN6wKQasQcUrDjjIUy152SfE1dIVvQjYGmuhzd74dnLnLhjgfJAkJY","parameters":{"curve":"P-256"},"publicKey":"034044d1ab03d42543e806c4242fe0ab42f0df530c7548f2078e00a79b087892bb","salt":"hf/9mY5kH9567GZQYnn4hw=="}],"isDefault":true,"label":"c7b82a36","lock":false,"ontid":"did:ont:ARR7Rk4hpvnkAAWkyHGtrF2H3htHWrKFby"},{"controls":[{"address":"Ae6XnePYWiBUALD2c2EdnuDAAWEsqf2JGr","algorithm":"ECDSA","enc-alg":"aes-256-gcm","hash":"sha256","id":"keys-1","key":"zgNPyJb3UtIA2jdHoS2I6RgnYPRc50cC89gIN9frbnZMtp+pMSm9iR3Oxd9/kIBQ","parameters":{"curve":"P-256"},"publicKey":"0376104dd7bba89580540f9e923a32ad9470af8759774c578936d96004fc492218","salt":"oNyhAmy2RLtv64wmnAlK6g=="}],"isDefault":false,"label":"06c59f9d","lock":false,"ontid":"did:ont:Ae6XnePYWiBUALD2c2EdnuDAAWEsqf2JGr"}],"name":"com.github.ontio","scrypt":{"dkLen":64,"n":16384,"p":8,"r":8},"version":"1.0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
back-end-projects/Explorer/src/main/java/com/github/ontio/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package com.github.ontio.controller; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import com.github.ontio.exception.ExplorerException; | ||
import com.github.ontio.model.common.ResponseBean; | ||
import com.github.ontio.model.dao.User; | ||
import com.github.ontio.model.dao.UserAddress; | ||
import com.github.ontio.model.dto.login.CallBackDto; | ||
import com.github.ontio.model.dto.login.CallBackResponse; | ||
import com.github.ontio.model.dto.login.QrCodeDto; | ||
import com.github.ontio.service.IUserService; | ||
import com.github.ontio.util.ConstantParam; | ||
import com.github.ontio.util.ErrorInfo; | ||
import com.github.ontio.util.Helper; | ||
import com.github.ontio.util.JwtUtil; | ||
import io.swagger.annotations.ApiImplicitParam; | ||
import io.swagger.annotations.ApiImplicitParams; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.Pattern; | ||
import java.util.List; | ||
|
||
/** | ||
* @author zhouq | ||
* @version 1.0 | ||
* @date 2020/3/24 | ||
*/ | ||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v2/users/") | ||
@Validated | ||
public class UserController { | ||
|
||
private final String CLASS_NAME = this.getClass().getSimpleName(); | ||
|
||
private final IUserService userService; | ||
|
||
|
||
@ApiOperation(value = "Web Query login qrcode") | ||
@GetMapping(value = "/web_login_qrcode") | ||
public ResponseBean queryWebQrCode() { | ||
ResponseBean rs = userService.queryWebQrCode(); | ||
return rs; | ||
} | ||
|
||
@ApiOperation(value = "ONTO APP Query login qrcode") | ||
@GetMapping(value = "/login_qrcode/{qrcode_id}") | ||
public QrCodeDto queryQrCode(@PathVariable("qrcode_id") String qrcodeId) { | ||
QrCodeDto rs = userService.queryQrCode(qrcodeId); | ||
return rs; | ||
} | ||
|
||
|
||
@ApiOperation(value = "Query login user info") | ||
@GetMapping(value = "/login_user_info") | ||
public ResponseBean queryLoginUserInfo(@RequestParam("code") String code) { | ||
ResponseBean rs = userService.queryLoginUserInfo(code); | ||
return rs; | ||
} | ||
|
||
|
||
@ApiOperation(value = "ONTO User login") | ||
@PostMapping(value = "/login") | ||
public CallBackResponse userLogin(@RequestBody JSONObject jsonObject) { | ||
log.info("###{}.{} begin...param:{}", CLASS_NAME, Helper.currentMethod(), jsonObject); | ||
CallBackDto callBackDto = new CallBackDto(); | ||
callBackDto.setSigner(jsonObject.getString("signer")); | ||
callBackDto.setSignedTx(jsonObject.getString("signedTx")); | ||
CallBackDto.CallbackExtraData callbackExtraData = CallBackDto.CallbackExtraData.builder() | ||
.id(jsonObject.getJSONObject("extraData").getString("id")) | ||
.build(); | ||
callBackDto.setExtraData(callbackExtraData); | ||
CallBackResponse rs = userService.login(callBackDto); | ||
return rs; | ||
} | ||
|
||
|
||
@ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "ONT_EXP_TOKEN", value = "login token", required = true)}) | ||
@ApiOperation(value = "Query user addresses") | ||
@GetMapping(value = "/addresses") | ||
public ResponseBean queryUserAddresses(@RequestParam("ont_id") @Pattern(regexp = "did:ont:[A-Za-z0-9]{34}", message = "Incorrect ONT ID format") String ontId) { | ||
log.info("###{}.{} begin...ontId:{}", CLASS_NAME, Helper.currentMethod(), ontId); | ||
checkToken(ontId); | ||
ResponseBean rs = userService.queryUserAddresses(ontId); | ||
refreshToken(ontId); | ||
return rs; | ||
} | ||
|
||
|
||
@ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "ONT_EXP_TOKEN", value = "login token", required = true)}) | ||
@ApiOperation(value = "Add or Update user addresses") | ||
@PostMapping(value = "/addresses") | ||
public ResponseBean addOrUpdateUserAddresses(@RequestParam("ont_id") @Pattern(regexp = "did:ont:[A-Za-z0-9]{34}", message = "Incorrect ONT ID format") String ontId, | ||
@RequestBody @Valid List<UserAddress> userAddresses) { | ||
log.info("###{}.{} begin...ontId:{}", CLASS_NAME, Helper.currentMethod(), ontId); | ||
checkToken(ontId); | ||
ResponseBean rs = userService.addOrUpdateUserAddresses(userAddresses, ontId); | ||
refreshToken(ontId); | ||
return rs; | ||
} | ||
|
||
|
||
@ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "ONT_EXP_TOKEN", value = "login token", required = true)}) | ||
@ApiOperation(value = "Delete user address") | ||
@DeleteMapping(value = "/addresses") | ||
public ResponseBean delUserAddress(@RequestParam("ont_id") @Pattern(regexp = "did:ont:[A-Za-z0-9]{34}", message = "Incorrect ONT ID format") String ontId, | ||
@RequestBody JSONObject jsonObject) { | ||
log.info("###{}.{} begin...ontId:{}", CLASS_NAME, Helper.currentMethod(), ontId); | ||
checkToken(ontId); | ||
ResponseBean rs = userService.delUserAddress(jsonObject.getString("address"), ontId); | ||
refreshToken(ontId); | ||
return rs; | ||
} | ||
|
||
|
||
@ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "ONT_EXP_TOKEN", value = "login token", required = true)}) | ||
@ApiOperation(value = "Update user information") | ||
@PostMapping | ||
public ResponseBean updateUser(@RequestParam("ont_id") @Pattern(regexp = "did:ont:[A-Za-z0-9]{34}", message = "Incorrect ONT ID format") String ontId, | ||
@RequestBody @Validated User user) { | ||
log.info("###{}.{} begin...ontId:{}", CLASS_NAME, Helper.currentMethod(), ontId); | ||
checkToken(ontId); | ||
user.setOntId(ontId); | ||
ResponseBean rs = userService.updateUser(user); | ||
refreshToken(ontId); | ||
return rs; | ||
} | ||
|
||
|
||
private void checkToken(String ontId) { | ||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | ||
String token = request.getHeader(ConstantParam.HTTPHEADER_TOKEN); | ||
if (Helper.isEmptyOrNull(token)) { | ||
throw new ExplorerException(ErrorInfo.TOKEN_EMPTY); | ||
} | ||
if (!JwtUtil.verifyToken(token)) { | ||
throw new ExplorerException(ErrorInfo.TOKEN_EXPIRED); | ||
} else if (!JwtUtil.getClaim(token, ConstantParam.JWT_LOGINID).asString().equals(ontId)) { | ||
throw new ExplorerException(ErrorInfo.TOKEN_UNMATCH); | ||
} | ||
} | ||
|
||
private void refreshToken(String ontId) { | ||
String newToken = JwtUtil.signToken(ontId); | ||
HttpServletResponse resp = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); | ||
resp.setHeader(ConstantParam.HTTPHEADER_TOKEN, newToken); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/AddressBlacklistMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.github.ontio.mapper; | ||
|
||
import com.github.ontio.model.dao.AddressBlacklist; | ||
import tk.mybatis.mapper.common.Mapper; | ||
|
||
public interface AddressBlacklistMapper extends Mapper<AddressBlacklist> { | ||
} |
7 changes: 7 additions & 0 deletions
7
back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/OepLogoMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.github.ontio.mapper; | ||
|
||
import com.github.ontio.model.dao.OepLogo; | ||
import tk.mybatis.mapper.common.Mapper; | ||
|
||
public interface OepLogoMapper extends Mapper<OepLogo> { | ||
} |
12 changes: 12 additions & 0 deletions
12
back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/UserAddressMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.ontio.mapper; | ||
|
||
import com.github.ontio.model.dao.UserAddress; | ||
import tk.mybatis.mapper.common.Mapper; | ||
|
||
import java.util.List; | ||
|
||
public interface UserAddressMapper extends Mapper<UserAddress> { | ||
|
||
int saveUserAddress(List<UserAddress> userAddresses); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/UserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.github.ontio.mapper; | ||
|
||
import com.github.ontio.model.dao.User; | ||
import tk.mybatis.mapper.common.Mapper; | ||
|
||
public interface UserMapper extends Mapper<User> { | ||
|
||
int saveUser(User user); | ||
|
||
} |
Oops, something went wrong.