Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
ab3812c6
Commit
ab3812c6
authored
Jun 09, 2016
by
Aleksandr Sharaban
Committed by
Matija Obreza
Aug 02, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Email validation
parent
ca8539f4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
7 deletions
+43
-7
pom.xml
pom.xml
+8
-1
src/main/java/org/genesys2/server/service/UserService.java
src/main/java/org/genesys2/server/service/UserService.java
+1
-1
src/main/java/org/genesys2/server/service/impl/UserServiceImpl.java
...ava/org/genesys2/server/service/impl/UserServiceImpl.java
+12
-2
src/main/java/org/genesys2/server/servlet/controller/UserProfileController.java
...sys2/server/servlet/controller/UserProfileController.java
+12
-2
src/main/java/org/genesys2/server/servlet/controller/rest/UsersController.java
...esys2/server/servlet/controller/rest/UsersController.java
+7
-1
src/main/webapp/WEB-INF/jsp/user/edit.jsp
src/main/webapp/WEB-INF/jsp/user/edit.jsp
+3
-0
No files found.
pom.xml
View file @
ab3812c6
...
...
@@ -69,7 +69,8 @@
<commons.fileupload.version>
1.2.2
</commons.fileupload.version>
<commons.io.version>
2.4
</commons.io.version>
<commons.lang.version>
2.6
</commons.lang.version>
<commons.logging.version>
1.1.1
</commons.logging.version>
<commons.logging.version>
1.2
</commons.logging.version>
<commons.validator.version>
1.4.0
</commons.validator.version>
<jstl.version>
1.2
</jstl.version>
<servlet-api.version>
2.5
</servlet-api.version>
...
...
@@ -162,6 +163,12 @@
<version>
1.10
</version>
</dependency>
<dependency>
<groupId>
commons-validator
</groupId>
<artifactId>
commons-validator
</artifactId>
<version>
${commons.validator.version}
</version>
</dependency>
<!-- Logging dependencies -->
<dependency>
<groupId>
org.slf4j
</groupId>
...
...
src/main/java/org/genesys2/server/service/UserService.java
View file @
ab3812c6
...
...
@@ -64,7 +64,7 @@ public interface UserService {
UserWrapper
getWrappedById
(
long
userId
)
throws
UserException
;
@PreAuthorize
(
"hasRole('ADMINISTRATOR') || principal.user.id == #userId"
)
User
updateData
(
long
userId
,
String
name
,
String
email
);
User
updateData
(
long
userId
,
String
name
,
String
email
)
throws
UserException
;
User
getSystemUser
(
String
string
);
...
...
src/main/java/org/genesys2/server/service/impl/UserServiceImpl.java
View file @
ab3812c6
...
...
@@ -29,6 +29,7 @@ import org.apache.commons.collections4.ListUtils;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.validator.routines.EmailValidator
;
import
org.genesys2.server.exception.NoUserFoundException
;
import
org.genesys2.server.exception.NotUniqueUserException
;
import
org.genesys2.server.exception.UserException
;
...
...
@@ -75,6 +76,8 @@ public class UserServiceImpl implements UserService {
private
final
List
<
UserRole
>
availableRoles
=
ListUtils
.
unmodifiableList
(
Arrays
.
asList
(
UserRole
.
values
()));
private
EmailValidator
emailValidator
=
EmailValidator
.
getInstance
();
/**
* Set number of milliseconds for user account lockout
*/
...
...
@@ -250,8 +253,15 @@ public class UserServiceImpl implements UserService {
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR') || principal.user.id == #userId"
)
@Transactional
(
readOnly
=
false
)
public
User
updateData
(
long
userId
,
String
name
,
String
email
)
{
@Transactional
(
readOnly
=
false
,
rollbackFor
=
NotUniqueUserException
.
class
)
public
User
updateData
(
long
userId
,
String
name
,
String
email
)
throws
UserException
{
if
(!
emailValidator
.
isValid
(
email
))
{
throw
new
UserException
();
}
if
(
userPersistence
.
findByEmail
(
email
)
!=
null
)
{
throw
new
NotUniqueUserException
(
new
Throwable
(),
email
);
}
final
User
user
=
userPersistence
.
findOne
(
userId
);
user
.
setName
(
name
);
user
.
setEmail
(
email
);
...
...
src/main/java/org/genesys2/server/servlet/controller/UserProfileController.java
View file @
ab3812c6
...
...
@@ -19,6 +19,7 @@ package org.genesys2.server.servlet.controller;
import
java.util.List
;
import
org.apache.commons.lang.StringUtils
;
import
org.genesys2.server.exception.NotUniqueUserException
;
import
org.genesys2.server.exception.UserException
;
import
org.genesys2.server.model.impl.User
;
import
org.genesys2.server.service.EMailVerificationService
;
...
...
@@ -36,6 +37,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
@Controller
@RequestMapping
(
"/profile"
)
...
...
@@ -163,13 +165,21 @@ public class UserProfileController extends BaseController {
@RequestMapping
(
value
=
"/{uuid:.+}/update"
,
method
=
{
RequestMethod
.
POST
})
@PreAuthorize
(
"hasRole('ADMINISTRATOR') || principal.user.uuid == #uuid"
)
public
String
update
(
ModelMap
model
,
@PathVariable
(
"uuid"
)
String
uuid
,
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
"email"
)
String
email
,
@RequestParam
(
"pwd1"
)
String
pwd1
,
@RequestParam
(
"pwd2"
)
String
pwd2
)
{
@RequestParam
(
"pwd1"
)
String
pwd1
,
@RequestParam
(
"pwd2"
)
String
pwd2
,
RedirectAttributes
redirectAttributes
)
{
final
User
user
=
userService
.
getUserByUuid
(
uuid
);
if
(
user
==
null
)
{
throw
new
ResourceNotFoundException
();
}
userService
.
updateData
(
user
.
getId
(),
name
,
email
);
try
{
userService
.
updateData
(
user
.
getId
(),
name
,
email
);
}
catch
(
NotUniqueUserException
e
)
{
redirectAttributes
.
addFlashAttribute
(
"emailError"
,
"User with e-mail address "
+
e
.
getEmail
()
+
" already exists"
);
return
"redirect:/profile/"
+
user
.
getUuid
()
+
"/edit"
;
}
catch
(
UserException
e
)
{
redirectAttributes
.
addFlashAttribute
(
"emailError"
,
"E-mail address is incorrect"
);
return
"redirect:/profile/"
+
user
.
getUuid
()
+
"/edit"
;
}
if
(
StringUtils
.
isNotBlank
(
pwd1
))
{
if
(
pwd1
.
equals
(
pwd2
))
{
...
...
src/main/java/org/genesys2/server/servlet/controller/rest/UsersController.java
View file @
ab3812c6
...
...
@@ -115,7 +115,13 @@ public class UsersController extends RestController {
throw
new
ResourceNotFoundException
();
}
userService
.
updateData
(
user
.
getId
(),
userData
.
getName
(),
userData
.
getEmail
());
try
{
userService
.
updateData
(
user
.
getId
(),
userData
.
getName
(),
userData
.
getEmail
());
}
catch
(
NotUniqueUserException
e
)
{
LOG
.
warn
(
"User with e-mail address "
+
e
.
getEmail
()
+
" already exists"
);
}
catch
(
UserException
e
)
{
LOG
.
warn
(
"E-mail address is incorrect"
);
}
if
(
StringUtils
.
isNotBlank
(
userData
.
getPwd1
()))
{
if
(
userData
.
getPwd1
().
equals
(
userData
.
getPwd2
()))
{
...
...
src/main/webapp/WEB-INF/jsp/user/edit.jsp
View file @
ab3812c6
...
...
@@ -12,6 +12,9 @@
<spring:message
code=
"userprofile.update.title"
/>
</h1>
<c:if
test=
"
${
not
empty
emailError
}
"
>
<div
class=
"alert alert-danger"
>
${emailError}
</div>
</c:if>
<form
role=
"form"
class=
"form-horizontal validate"
action=
"
<c:url
value=
"/profile/${user.uuid}/update"
/>
"
method=
"post"
>
<div
class=
"form-group"
>
<label
for=
"name"
class=
"col-lg-2 control-label"
><spring:message
code=
"registration.full-name"
/></label>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment