Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
d13a75e6
提交
d13a75e6
authored
12月 25, 2020
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update paypal
上级
369cc629
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
91 行增加
和
59 行删除
+91
-59
PaypalConfig.java
...ain/java/com/example/afrishop_v3/config/PaypalConfig.java
+2
-0
PaypalContoller.java
.../com/example/afrishop_v3/controllers/PaypalContoller.java
+30
-3
UserController.java
...a/com/example/afrishop_v3/controllers/UserController.java
+59
-56
没有找到文件。
src/main/java/com/example/afrishop_v3/config/PaypalConfig.java
浏览文件 @
d13a75e6
...
...
@@ -6,6 +6,7 @@ import com.paypal.base.rest.PayPalRESTException;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -34,6 +35,7 @@ public class PaypalConfig {
return
new
OAuthTokenCredential
(
clientId
,
clientSecret
,
paypalSdkConfig
());
}
@Primary
@Bean
public
APIContext
apiContext
()
throws
PayPalRESTException
{
APIContext
apiContext
=
new
APIContext
(
authTokenCredential
().
getAccessToken
());
...
...
src/main/java/com/example/afrishop_v3/controllers/PaypalContoller.java
浏览文件 @
d13a75e6
...
...
@@ -15,7 +15,11 @@ import com.paypal.base.rest.APIContext;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -38,7 +42,7 @@ import java.util.Optional;
@RestController
@RequestMapping
(
value
=
"/paypal"
)
@Transactional
public
class
PaypalContoller
extends
Controller
{
public
class
PaypalContoller
extends
Controller
implements
BeanPostProcessor
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
PaypalContoller
.
class
);
...
...
@@ -62,9 +66,9 @@ public class PaypalContoller extends Controller {
private
final
BonusRepository
bonusRepository
;
private
final
PostRepository
postRepository
;
private
final
UserRepository
userRepository
;
private
final
DefaultListableBeanFactory
defaultListableBeanFactory
;
public
PaypalContoller
(
APIContext
apiContext
,
TbCfOrderRepository
orderRepository
,
TbCfFinanceRepository
financeRepository
,
NetworkRepository
networkRepository
,
BonusRepository
bonusRepository
,
PostRepository
postRepository
,
UserRepository
userRepository
)
{
public
PaypalContoller
(
APIContext
apiContext
,
TbCfOrderRepository
orderRepository
,
TbCfFinanceRepository
financeRepository
,
NetworkRepository
networkRepository
,
BonusRepository
bonusRepository
,
PostRepository
postRepository
,
UserRepository
userRepository
,
DefaultListableBeanFactory
defaultListableBeanFactory
)
{
this
.
apiContext
=
apiContext
;
this
.
orderRepository
=
orderRepository
;
this
.
financeRepository
=
financeRepository
;
...
...
@@ -72,6 +76,7 @@ public class PaypalContoller extends Controller {
this
.
bonusRepository
=
bonusRepository
;
this
.
postRepository
=
postRepository
;
this
.
userRepository
=
userRepository
;
this
.
defaultListableBeanFactory
=
defaultListableBeanFactory
;
}
...
...
@@ -83,6 +88,7 @@ public class PaypalContoller extends Controller {
*/
@PostMapping
(
"/payment/{orderId}"
)
public
Result
payment
(
@PathVariable
(
"orderId"
)
String
orderId
)
{
logger
.
info
(
"APIContext--->"
+
apiContext
.
getAccessToken
());
Result
result
=
new
Result
();
//==========================支付信息校验==========================
...
...
@@ -381,4 +387,25 @@ public class PaypalContoller extends Controller {
return
null
;
}
@Override
public
Object
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
boolean
containsBean
=
defaultListableBeanFactory
.
containsBean
(
"apiContext"
);
if
(
containsBean
)
{
BeanDefinition
apiContext
=
defaultListableBeanFactory
.
getBeanDefinition
(
"apiContext"
);
//移除bean的定义和实例
defaultListableBeanFactory
.
removeBeanDefinition
(
"apiContext"
);
//注册新的bean定义和实例
defaultListableBeanFactory
.
registerBeanDefinition
(
"apiContext"
,
apiContext
);
}
return
bean
;
}
@Override
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
return
bean
;
}
}
src/main/java/com/example/afrishop_v3/controllers/UserController.java
浏览文件 @
d13a75e6
...
...
@@ -43,50 +43,51 @@ public class UserController extends Controller {
this
.
encoder
=
encoder
;
this
.
emailHelper
=
emailHelper
;
}
//Update email or phone number
@PutMapping
(
"bindPhoneOrEmail"
)
public
Result
bindPhoneOrEmail
(
@RequestParam
(
value
=
"email"
,
required
=
false
)
String
email
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"phone"
,
required
=
false
)
String
phone
)
{
public
Result
bindPhoneOrEmail
(
@RequestParam
(
value
=
"email"
,
required
=
false
)
String
email
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"phone"
,
required
=
false
)
String
phone
)
{
TbCfUserInfo
user
=
this
.
user
.
user
();
if
(
StringUtils
.
isNotBlank
(
email
)
)
{
if
(
StringUtils
.
isNotBlank
(
email
))
{
boolean
detect
=
StringUtils
.
isNotBlank
(
code
)
&&
code
.
equals
(
user
.
getVerificationCode
());
if
(
isEmailValid
(
email
)
&&
detect
)
{
boolean
detect
=
StringUtils
.
isNotBlank
(
code
)
&&
code
.
equals
(
user
.
getVerificationCode
());
if
(
isEmailValid
(
email
)
&&
detect
)
{
boolean
b
=
repository
.
existsByEmailAndUserIdNot
(
email
,
user
.
getUserId
());
if
(
b
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Email is already taken"
);
if
(
b
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Email is already taken"
);
}
if
(
email
.
equals
(
user
.
getEmail
())
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Same email address"
);
if
(
email
.
equals
(
user
.
getEmail
()))
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Same email address"
);
}
if
(
user
.
getEmail
()
!=
null
&&
user
.
getEmail
().
equals
(
user
.
getFirebaseUid
()))
{
if
(
user
.
getEmail
()
!=
null
&&
user
.
getEmail
().
equals
(
user
.
getFirebaseUid
()))
{
user
.
setFirebaseUid
(
email
);
}
user
.
setEmail
(
email
);
}
else
return
new
Result
(
ResultCodeEnum
.
ILLEGAL_ARGUMENT
.
getCode
(),
detect
?
"Email address is not valid"
:
"Code verification error"
);
}
else
return
new
Result
(
ResultCodeEnum
.
ILLEGAL_ARGUMENT
.
getCode
(),
detect
?
"Email address is not valid"
:
"Code verification error"
);
}
if
(
StringUtils
.
isNotBlank
(
phone
)
)
{
if
(
StringUtils
.
isNotBlank
(
phone
))
{
if
(
StringUtils
.
isNotBlank
(
code
)
&&
code
.
equals
(
user
.
getVerificationCode
())
)
{
if
(
StringUtils
.
isNotBlank
(
code
)
&&
code
.
equals
(
user
.
getVerificationCode
()))
{
boolean
b
=
repository
.
existsByPhoneAndUserIdNot
(
phone
,
user
.
getUserId
());
if
(
b
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Phone number is already taken"
);
if
(
b
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Phone number is already taken"
);
}
if
(
phone
.
equals
(
user
.
getPhone
())
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Same phone number"
);
if
(
phone
.
equals
(
user
.
getPhone
()))
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Same phone number"
);
}
user
.
setPhone
(
phone
);
user
.
setVerificationCode
(
null
);
}
else
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Code verification error"
);
}
else
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Code verification error"
);
}
...
...
@@ -97,7 +98,7 @@ public class UserController extends Controller {
@GetMapping
(
"/getEmailCode"
)
public
Result
getEmailCode
(
@RequestParam
(
"email"
)
String
email
){
public
Result
getEmailCode
(
@RequestParam
(
"email"
)
String
email
)
{
try
{
EmailTemplateBo
emailTemplateBo
=
new
EmailTemplateBo
();
...
...
@@ -110,8 +111,8 @@ public class UserController extends Controller {
user
.
setVerificationCode
(
String
.
valueOf
(
identifyCode
));
repository
.
save
(
user
);
return
new
Result
(
"Verification code has been sent"
);
}
catch
(
Exception
e
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
e
.
getMessage
());
}
catch
(
Exception
e
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
e
.
getMessage
());
}
}
...
...
@@ -129,7 +130,7 @@ public class UserController extends Controller {
//先从缓存中获取用户的发送次数
Integer
sentCount
=
user
.
getSentCount
();
if
(
sentCount
==
null
)
{
if
(
sentCount
==
null
)
{
//Set count if not available
user
.
setSentCount
(-
1
);
sentCount
=
-
1
;
...
...
@@ -147,7 +148,7 @@ public class UserController extends Controller {
long
diffMinutes
=
diff
/
(
60
*
1000
)
%
60
;
if
(
diffMinutes
>
15
&&
sentCount
>=
3
)
{
if
(
diffMinutes
>
15
&&
sentCount
>=
3
)
{
sentCount
=
-
1
;
user
.
setSentCount
(
sentCount
);
}
...
...
@@ -155,13 +156,13 @@ public class UserController extends Controller {
boolean
canSend
=
sentCount
<
3
;
if
(
canSend
)
{
if
(
canSend
)
{
result
.
setMessage
(
"Verification code has been sent"
);
//发送验证码
String
code
=
SMSUtil
.
yzCode
(
phone
);
user
.
setCodeSentTime
(
date
);
user
.
setVerificationCode
(
code
);
user
.
setSentCount
(
user
.
getSentCount
()
+
1
);
user
.
setSentCount
(
user
.
getSentCount
()
+
1
);
repository
.
save
(
user
);
logger
.
info
(
"用户["
+
phone
+
"]获取验证码成功,"
+
"验证码:"
+
code
);
}
else
{
...
...
@@ -179,11 +180,11 @@ public class UserController extends Controller {
}
@PutMapping
(
"updatePassword"
)
public
Result
updatePassword
(
@RequestBody
ResetBody
body
){
public
Result
updatePassword
(
@RequestBody
ResetBody
body
)
{
if
(
body
==
null
||
body
.
getNewPassword
()
==
null
||
body
.
getOldPassword
()
==
null
||
body
.
getOldPassword
().
isEmpty
()
||
body
.
getNewPassword
().
isEmpty
())
{
if
(
body
==
null
||
body
.
getNewPassword
()
==
null
||
body
.
getOldPassword
()
==
null
||
body
.
getOldPassword
().
isEmpty
()
||
body
.
getNewPassword
().
isEmpty
())
{
//Validate reset password body
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Empty body"
);
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Empty body"
);
}
...
...
@@ -192,20 +193,21 @@ public class UserController extends Controller {
boolean
matches
=
encoder
.
matches
(
body
.
getOldPassword
(),
user
.
getPassword
());
if
(
!
matches
)
{
if
(!
matches
)
{
//Valid old password is required
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Old password does not match"
);
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Old password does not match"
);
}
boolean
matches1
=
encoder
.
matches
(
body
.
getNewPassword
(),
user
.
getPassword
());
if
(
matches1
)
{
if
(
matches1
)
{
//Can't match old password
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Can’t change to the same password as last time"
);
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Can’t change to the same password as last time"
);
}
user
.
setPassword
(
encoder
.
encode
(
body
.
getNewPassword
()));
user
.
setToken
(
null
);
repository
.
save
(
user
);
...
...
@@ -216,24 +218,24 @@ public class UserController extends Controller {
@PutMapping
public
Result
updateUser
(
@RequestBody
TbCfUserInfo
info
)
{
TbCfUserInfo
user
=
this
.
user
.
user
();
//return if body is null
//return if body is null
if
(
info
==
null
)
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Empty body"
);
if
(
StringUtils
.
isNotBlank
(
info
.
getAvatar
())
)
{
if
(
StringUtils
.
isNotBlank
(
info
.
getAvatar
()))
{
//set avatar image url
user
.
setAvatar
(
info
.
getAvatar
());
}
if
(
info
.
getBirthday
()
!=
null
)
{
if
(
info
.
getBirthday
()
!=
null
)
{
//only supported format received
user
.
setBirthday
(
info
.
getBirthday
());
}
if
(
StringUtils
.
isNotBlank
(
info
.
getNick
())
)
{
if
(
StringUtils
.
isNotBlank
(
info
.
getNick
()))
{
user
.
setNick
(
info
.
getNick
());
}
if
(
info
.
getSex
()
!=
null
)
{
if
(
info
.
getSex
()
!=
null
)
{
user
.
setSex
(
info
.
getSex
());
}
...
...
@@ -246,24 +248,24 @@ public class UserController extends Controller {
}
@GetMapping
(
"/userById/{id}"
)
public
Result
userById
(
@PathVariable
(
"id"
)
String
id
){
public
Result
userById
(
@PathVariable
(
"id"
)
String
id
)
{
Optional
<
TbCfUserInfo
>
byId
=
repository
.
findById
(
id
);
return
byId
.
map
(
userInfo
->
new
Result
<>(
userInfo
,
"Success"
)).
orElseGet
(()
->
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Not found !"
));
}
@GetMapping
(
"/sendNotification/{id}"
)
public
Result
sendFcm
(
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
"content"
)
String
content
,
@RequestParam
(
"title"
)
String
title
)
{
public
Result
sendFcm
(
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
"content"
)
String
content
,
@RequestParam
(
"title"
)
String
title
)
{
Optional
<
TbCfUserInfo
>
byId
=
repository
.
findById
(
id
);
if
(
byId
.
isPresent
()
&&
byId
.
get
().
hasFcm
()
)
{
if
(
byId
.
isPresent
()
&&
byId
.
get
().
hasFcm
())
{
TbCfUserInfo
userInfo
=
byId
.
get
();
sendNotification
(
userInfo
.
getFcm
(),
title
,
content
);
logger
.
info
(
"Notification sent to "
+
userInfo
.
display
());
sendNotification
(
userInfo
.
getFcm
(),
title
,
content
);
logger
.
info
(
"Notification sent to "
+
userInfo
.
display
());
return
new
Result
();
}
return
new
Result
(
ResultCodeEnum
.
SUCCESS
.
getCode
(),
"No firebase messaging token found"
);
return
new
Result
(
ResultCodeEnum
.
SUCCESS
.
getCode
(),
"No firebase messaging token found"
);
}
...
...
@@ -271,14 +273,15 @@ public class UserController extends Controller {
public
Result
getUserByCode
(
@PathVariable
(
"code"
)
String
code
)
{
Optional
<
TbCfUserInfo
>
byCode
=
repository
.
findByCode
(
code
);
boolean
present
=
byCode
.
isPresent
();
return
new
Result
<>(
present
?
byCode
.
get
()
:
null
,
present
?
1
:
0
,
present
?
"Successfully"
:
"Invitation code not found"
);
return
new
Result
<>(
present
?
byCode
.
get
()
:
null
,
present
?
1
:
0
,
present
?
"Successfully"
:
"Invitation code not found"
);
}
@PostMapping
(
value
=
"/edit/slogan"
)
public
Result
editSlogan
(
@RequestBody
TbCfUserInfo
tbCfUserInfo
)
{
//decode user from token
TbCfUserInfo
user
=
this
.
user
.
user
();
//Check not null
if
(
user
!=
null
&&
tbCfUserInfo
!=
null
)
{
if
(
user
!=
null
&&
tbCfUserInfo
!=
null
)
{
user
.
setSlogan
(
tbCfUserInfo
.
getSlogan
());
repository
.
save
(
user
);
}
...
...
@@ -288,7 +291,7 @@ public class UserController extends Controller {
@GetMapping
(
"/queryCollectionByUserId"
)
public
Result
queryCollectionByUserId
(
@RequestParam
(
value
=
"pageNo"
,
defaultValue
=
"0"
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"12"
)
Integer
pageSize
)
{
public
Result
queryCollectionByUserId
(
@RequestParam
(
value
=
"pageNo"
,
defaultValue
=
"0"
)
Integer
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"12"
)
Integer
pageSize
)
{
System
.
err
.
println
(
user
.
userId
());
Page
<
TbCfItemCollection
>
allByUserId
=
itemCollectionRepository
.
findAllByUserId
(
user
.
userId
(),
PageRequest
.
of
(
pageNo
,
pageSize
));
...
...
@@ -300,19 +303,19 @@ public class UserController extends Controller {
String
userId
=
user
.
userId
();
boolean
exists
=
itemCollectionRepository
.
existsByUserIdAndItemItemId
(
userId
,
itemId
);
if
(
exists
)
{
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Favorite item already exists !!!"
);
}
else
{
if
(
exists
)
{
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Favorite item already exists !!!"
);
}
else
{
Optional
<
TbCfStationItem
>
itemOptional
=
itemRepository
.
findById
(
itemId
);
if
(
itemOptional
.
isPresent
()
)
{
if
(
itemOptional
.
isPresent
()
)
{
TbCfItemCollection
tbCfItemCollection
=
new
TbCfItemCollection
();
tbCfItemCollection
.
setUserId
(
userId
);
tbCfItemCollection
.
setId
(
uid
());
tbCfItemCollection
.
setItem
(
itemOptional
.
get
());
itemCollectionRepository
.
save
(
tbCfItemCollection
);
return
new
Result
<>(
tbCfItemCollection
);
}
else
{
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Item not found"
);
}
else
{
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Item not found"
);
}
}
}
...
...
@@ -320,12 +323,12 @@ public class UserController extends Controller {
@DeleteMapping
(
"/delCollection"
)
public
Result
delCollection
(
@RequestBody
String
[]
collectionIds
)
{
//Check if body is not null
if
(
collectionIds
==
null
)
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Empty body"
);
if
(
collectionIds
==
null
)
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Empty body"
);
//Check if body is not empty
if
(
collectionIds
.
length
==
0
)
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Empty body"
);
if
(
collectionIds
.
length
==
0
)
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Empty body"
);
String
userId
=
user
.
userId
();
itemCollectionRepository
.
deleteAllByItemItemIdInAndUserId
(
collectionIds
,
userId
);
return
new
Result
();
itemCollectionRepository
.
deleteAllByItemItemIdInAndUserId
(
collectionIds
,
userId
);
return
new
Result
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论