Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
d35bd969
提交
d35bd969
authored
11月 13, 2020
作者:
Whispa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commit commit
上级
9f4ee85d
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
195 行增加
和
37 行删除
+195
-37
AuthController.java
...a/com/example/afrishop_v3/controllers/AuthController.java
+106
-20
Controller.java
.../java/com/example/afrishop_v3/controllers/Controller.java
+6
-0
ItemController.java
...a/com/example/afrishop_v3/controllers/ItemController.java
+1
-1
UserController.java
...a/com/example/afrishop_v3/controllers/UserController.java
+48
-1
TbCfItemCollection.java
...va/com/example/afrishop_v3/models/TbCfItemCollection.java
+24
-14
TbCfItemCollectionRepository.java
.../afrishop_v3/repository/TbCfItemCollectionRepository.java
+10
-1
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/AuthController.java
浏览文件 @
d35bd969
...
@@ -154,27 +154,10 @@ public class AuthController extends Controller {
...
@@ -154,27 +154,10 @@ public class AuthController extends Controller {
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Invalid email"
);
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Invalid email"
);
}
}
if
(
password
==
null
||
password
.
isEmpty
())
{
String
validatePassword
=
validatePassword
(
password
);
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Password is Empty"
);
}
if
(!
isPasswordValid
(
password
))
{
String
string
=
"Password is not strong"
;
if
(!
isPasswordValidDigit
(
password
))
{
if
(
validatePassword
!=
null
){
string
+=
", a digit must occur at least once"
;
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
validatePassword
);
}
if
(!
isPasswordValidUpperCase
(
password
))
{
string
+=
", an upper case letter must occur at least once"
;
}
if
(!
isPasswordValidLength
(
password
))
{
string
+=
", at least eight characters though"
;
}
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
string
);
}
}
boolean
byEmail
=
userRepository
.
existsByFirebaseUid
(
email
);
boolean
byEmail
=
userRepository
.
existsByFirebaseUid
(
email
);
...
@@ -217,6 +200,104 @@ public class AuthController extends Controller {
...
@@ -217,6 +200,104 @@ public class AuthController extends Controller {
}
}
private
String
validatePassword
(
String
password
){
if
(
password
==
null
||
password
.
isEmpty
())
{
return
"Password is Empty"
;
}
if
(!
isPasswordValid
(
password
))
{
String
string
=
"Password is not strong"
;
if
(!
isPasswordValidDigit
(
password
))
{
string
+=
", a digit must occur at least once"
;
}
if
(!
isPasswordValidUpperCase
(
password
))
{
string
+=
", an upper case letter must occur at least once"
;
}
if
(!
isPasswordValidLength
(
password
))
{
string
+=
", at least eight characters though"
;
}
return
string
;
}
return
null
;
}
@PostMapping
(
"/signup/phone"
)
public
Result
<?>
registerUserPhone
(
@RequestBody
TbCfUserInfo
signUpRequest
)
{
try
{
// boolean byAccount = userRepository.existsByAccount(signUpRequest.getEmail());
// if ( byAccount ) {
// return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(),"Error: Username is already taken!");
// }
String
phone
=
signUpRequest
.
getPhone
();
String
password
=
signUpRequest
.
getPassword
();
phone
=
phone
==
null
?
""
:
phone
.
trim
();
if
(
phone
.
isEmpty
())
{
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Email is empty"
);
}
if
(!
isPhoneValid
(
phone
))
{
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Invalid phone"
);
}
String
validatePassword
=
validatePassword
(
password
);
if
(
validatePassword
!=
null
){
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
validatePassword
);
}
boolean
byEmail
=
userRepository
.
existsByFirebaseUid
(
phone
);
boolean
byEmail2
=
userRepository
.
existsByAccount
(
phone
);
if
(
byEmail
||
byEmail2
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Error: Phone is already in use!"
);
}
//signUpRequest.setFirebaseUid(phone);
signUpRequest
.
setAccount
(
phone
);
signUpRequest
.
setUserId
(
IdUtil
.
createIdbyUUID
());
fillUserNecessayInfo
(
signUpRequest
);
signUpRequest
.
setPassword
(
encoder
.
encode
(
password
));
signUpRequest
.
setLastLoginTime
(
new
Date
());
fixCode
(
signUpRequest
);
signUpRequest
.
setUserType
(
UserTypeEnum
.
PHONE
.
getCode
());
TbCfUserInfo
userInfo
=
userRepository
.
save
(
signUpRequest
);
//addToNetwork(signUpRequest);
fixCoupon
(
signUpRequest
);
return
authenticateUser
(
new
LoginRequest
(
userInfo
.
getAccount
(),
password
,
userInfo
.
getFcm
()));
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
return
new
Result
<>(
ResultCodeEnum
.
SERVICE_ERROR
.
getCode
(),
e
.
getMessage
());
}
}
@PostMapping
(
value
=
"/register/user"
)
@PostMapping
(
value
=
"/register/user"
)
public
Result
checkFirebase
(
@RequestBody
TbCfUserInfo
user
)
{
public
Result
checkFirebase
(
@RequestBody
TbCfUserInfo
user
)
{
//Data to be userInfoVo
//Data to be userInfoVo
...
@@ -314,6 +395,11 @@ public class AuthController extends Controller {
...
@@ -314,6 +395,11 @@ public class AuthController extends Controller {
//addToNetwork(user);
//addToNetwork(user);
user
.
setLastLoginTime
(
new
Date
());
user
.
setLastLoginTime
(
new
Date
());
if
(
user
.
getAccount
()
==
null
){
user
.
setAccount
(
user
.
getEmail
()
==
null
?
user
.
getEmail
()
:
user
.
getPhone
());
}
userRepository
.
save
(
user
);
userRepository
.
save
(
user
);
//注册成功 创建token
//注册成功 创建token
...
...
src/main/java/com/example/afrishop_v3/controllers/Controller.java
浏览文件 @
d35bd969
...
@@ -40,6 +40,12 @@ abstract class Controller {
...
@@ -40,6 +40,12 @@ abstract class Controller {
return
validRex
(
email
,
"^[\\w.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"
);
return
validRex
(
email
,
"^[\\w.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"
);
}
}
static
boolean
isPhoneValid
(
String
phone
)
{
return
validRex
(
phone
,
"^(\\+\\d{1,3}( )?)?((\\(\\d{3}\\))|\\d{3})[- .]?\\d{3}[- .]?\\d{4}$"
+
"|^(\\+\\d{1,3}( )?)?(\\d{3}[ ]?){2}\\d{3}$"
+
"|^(\\+\\d{1,3}( )?)?(\\d{3}[ ]?)(\\d{2}[ ]?){2}\\d{2}$"
);
}
static
boolean
isPasswordVeryStrong
(
String
password
)
{
static
boolean
isPasswordVeryStrong
(
String
password
)
{
return
validRex
(
password
,
"^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$"
);
return
validRex
(
password
,
"^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$"
);
}
}
...
...
src/main/java/com/example/afrishop_v3/controllers/ItemController.java
浏览文件 @
d35bd969
...
@@ -185,7 +185,7 @@ public class ItemController {
...
@@ -185,7 +185,7 @@ public class ItemController {
List
<
TbCfItemParam
>
itemParamList
=
itemParamRepository
.
findAllByItemId
(
itemId
);
List
<
TbCfItemParam
>
itemParamList
=
itemParamRepository
.
findAllByItemId
(
itemId
);
map
.
put
(
"score"
,
item
.
getTotalScore
());
map
.
put
(
"score"
,
item
.
getTotalScore
());
map
.
put
(
"isCollection"
,
userId
!=
null
&&
!
userId
.
isEmpty
()
&&
collectionRepository
.
existsByUserIdAndItemId
(
userId
,
itemId
));
map
.
put
(
"isCollection"
,
userId
!=
null
&&
!
userId
.
isEmpty
()
&&
collectionRepository
.
existsByUserIdAndItemI
temI
d
(
userId
,
itemId
));
map
.
put
(
"optionList"
,
categoryList
);
map
.
put
(
"optionList"
,
categoryList
);
map
.
put
(
"itemDetail"
,
skusList
);
map
.
put
(
"itemDetail"
,
skusList
);
map
.
put
(
"itemInfo"
,
item
);
map
.
put
(
"itemInfo"
,
item
);
...
...
src/main/java/com/example/afrishop_v3/controllers/UserController.java
浏览文件 @
d35bd969
...
@@ -3,7 +3,11 @@ package com.example.afrishop_v3.controllers;
...
@@ -3,7 +3,11 @@ package com.example.afrishop_v3.controllers;
import
com.example.afrishop_v3.base.Result
;
import
com.example.afrishop_v3.base.Result
;
import
com.example.afrishop_v3.enums.ResultCodeEnum
;
import
com.example.afrishop_v3.enums.ResultCodeEnum
;
import
com.example.afrishop_v3.models.ResetBody
;
import
com.example.afrishop_v3.models.ResetBody
;
import
com.example.afrishop_v3.models.TbCfItemCollection
;
import
com.example.afrishop_v3.models.TbCfStationItem
;
import
com.example.afrishop_v3.models.TbCfUserInfo
;
import
com.example.afrishop_v3.models.TbCfUserInfo
;
import
com.example.afrishop_v3.repository.TbCfItemCollectionRepository
;
import
com.example.afrishop_v3.repository.TbCfStationItemRepository
;
import
com.example.afrishop_v3.repository.UserRepository
;
import
com.example.afrishop_v3.repository.UserRepository
;
import
com.example.afrishop_v3.security.services.AuthenticationUser
;
import
com.example.afrishop_v3.security.services.AuthenticationUser
;
import
com.example.afrishop_v3.util.*
;
import
com.example.afrishop_v3.util.*
;
...
@@ -16,19 +20,24 @@ import org.springframework.web.bind.annotation.*;
...
@@ -16,19 +20,24 @@ import org.springframework.web.bind.annotation.*;
import
java.net.URLDecoder
;
import
java.net.URLDecoder
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
@RestController
@RestController
@RequestMapping
(
"user"
)
@RequestMapping
(
"user"
)
public
class
UserController
extends
Controller
{
public
class
UserController
extends
Controller
{
private
final
UserRepository
repository
;
private
final
UserRepository
repository
;
private
final
TbCfItemCollectionRepository
itemCollectionRepository
;
private
final
TbCfStationItemRepository
itemRepository
;
private
final
AuthenticationUser
user
;
private
final
AuthenticationUser
user
;
private
final
PasswordEncoder
encoder
;
private
final
PasswordEncoder
encoder
;
private
final
EmailHelper
emailHelper
;
private
final
EmailHelper
emailHelper
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
public
UserController
(
UserRepository
repository
,
AuthenticationUser
user
,
PasswordEncoder
encoder
,
EmailHelper
emailHelper
)
{
public
UserController
(
UserRepository
repository
,
TbCfItemCollectionRepository
itemCollectionRepository
,
TbCfStationItemRepository
itemRepository
,
AuthenticationUser
user
,
PasswordEncoder
encoder
,
EmailHelper
emailHelper
)
{
this
.
repository
=
repository
;
this
.
repository
=
repository
;
this
.
itemCollectionRepository
=
itemCollectionRepository
;
this
.
itemRepository
=
itemRepository
;
this
.
user
=
user
;
this
.
user
=
user
;
this
.
encoder
=
encoder
;
this
.
encoder
=
encoder
;
this
.
emailHelper
=
emailHelper
;
this
.
emailHelper
=
emailHelper
;
...
@@ -251,4 +260,42 @@ public class UserController extends Controller {
...
@@ -251,4 +260,42 @@ public class UserController extends Controller {
return
new
Result
<>(
user
);
return
new
Result
<>(
user
);
}
}
@GetMapping
(
"/queryCollectionByUserId"
)
public
Result
queryCollectionByUserId
()
{
List
<
TbCfItemCollection
>
list
=
itemCollectionRepository
.
findAllByUserId
(
user
.
userId
());
return
new
Result
<>(
list
);
}
@PutMapping
(
"/itemCollection/{itemId}"
)
public
Result
itemCollection
(
@PathVariable
(
"itemId"
)
String
itemId
)
{
String
userId
=
user
.
userId
();
boolean
exists
=
itemCollectionRepository
.
existsByUserIdAndItemItemId
(
userId
,
itemId
);
if
(
exists
){
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Favorite item already exists !!!"
);
}
else
{
Optional
<
TbCfStationItem
>
itemOptional
=
itemRepository
.
findById
(
itemId
);
if
(
itemOptional
.
isPresent
()
)
{
TbCfItemCollection
tbCfItemCollection
=
new
TbCfItemCollection
();
tbCfItemCollection
.
setUserId
(
userId
);
tbCfItemCollection
.
setItem
(
itemOptional
.
get
());
itemCollectionRepository
.
save
(
tbCfItemCollection
);
return
new
Result
<>(
tbCfItemCollection
);
}
else
{
return
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Item not found"
);
}
}
}
@DeleteMapping
(
"/delCollection"
)
public
Result
delCollection
(
@RequestBody
String
[]
collectionIds
)
{
String
userId
=
user
.
userId
();
itemCollectionRepository
.
deleteAllByIdInAndUserId
(
collectionIds
,
userId
);
return
new
Result
();
}
}
}
src/main/java/com/example/afrishop_v3/models/TbCfItemCollection.java
浏览文件 @
d35bd969
...
@@ -4,6 +4,8 @@ import lombok.Data;
...
@@ -4,6 +4,8 @@ import lombok.Data;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
java.util.Date
;
import
java.util.Date
;
/**
/**
...
@@ -29,7 +31,11 @@ public class TbCfItemCollection {
...
@@ -29,7 +31,11 @@ public class TbCfItemCollection {
/**
/**
* 商品
* 商品
*/
*/
private
String
itemId
;
//private String itemId;
@ManyToOne
@JoinColumn
(
columnDefinition
=
"item_id"
,
name
=
"item_id"
)
private
TbCfStationItem
item
;
/**
/**
* 删除
* 删除
*/
*/
...
@@ -63,25 +69,29 @@ public class TbCfItemCollection {
...
@@ -63,25 +69,29 @@ public class TbCfItemCollection {
this
.
userId
=
userId
;
this
.
userId
=
userId
;
}
}
public
void
setItem
(
TbCfStationItem
item
)
{
this
.
item
=
item
;
}
/**
/**
* 获取:用户
* 获取:用户
*/
*/
public
String
getUserId
()
{
public
String
getUserId
()
{
return
userId
;
return
userId
;
}
}
/**
//
/**
* 设置:商品
//
* 设置:商品
*/
//
*/
public
void
setItemId
(
String
itemId
)
{
//
public void setItemId(String itemId) {
this
.
itemId
=
itemId
;
//
this.itemId = itemId;
}
//
}
//
/**
//
/**
* 获取:商品
//
* 获取:商品
*/
//
*/
public
String
getItemId
()
{
//
public String getItemId() {
return
itemId
;
//
return itemId;
}
//
}
/**
/**
* 设置:删除
* 设置:删除
*/
*/
...
...
src/main/java/com/example/afrishop_v3/repository/TbCfItemCollectionRepository.java
浏览文件 @
d35bd969
...
@@ -2,7 +2,16 @@ package com.example.afrishop_v3.repository;
...
@@ -2,7 +2,16 @@ package com.example.afrishop_v3.repository;
import
com.example.afrishop_v3.models.TbCfItemCollection
;
import
com.example.afrishop_v3.models.TbCfItemCollection
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Collection
;
import
java.util.List
;
public
interface
TbCfItemCollectionRepository
extends
PagingAndSortingRepository
<
TbCfItemCollection
,
String
>
{
public
interface
TbCfItemCollectionRepository
extends
PagingAndSortingRepository
<
TbCfItemCollection
,
String
>
{
boolean
existsByUserIdAndItemId
(
String
userId
,
String
itemId
);
boolean
existsByUserIdAndItemItemId
(
String
userId
,
String
itemId
);
List
<
TbCfItemCollection
>
findAllByUserId
(
String
userId
);
@Transactional
void
deleteAllByIdInAndUserId
(
String
[]
ids
,
String
userId
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论