Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
56ef1ba3
Commit
56ef1ba3
authored
May 07, 2017
by
Liang Ding
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'refs/remotes/origin/2.1.0-dev'
parents
766ebac8
da54d798
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
52 deletions
+58
-52
src/main/java/org/b3log/solo/SoloServletListener.java
src/main/java/org/b3log/solo/SoloServletListener.java
+1
-2
src/main/java/org/b3log/solo/processor/IndexProcessor.java
src/main/java/org/b3log/solo/processor/IndexProcessor.java
+19
-7
src/main/java/org/b3log/solo/service/UserMgmtService.java
src/main/java/org/b3log/solo/service/UserMgmtService.java
+26
-35
src/main/java/org/b3log/solo/util/Skins.java
src/main/java/org/b3log/solo/util/Skins.java
+12
-8
No files found.
src/main/java/org/b3log/solo/SoloServletListener.java
View file @
56ef1ba3
...
@@ -61,7 +61,7 @@ import java.util.Set;
...
@@ -61,7 +61,7 @@ import java.util.Set;
* Solo Servlet listener.
* Solo Servlet listener.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.9.
2.20, Apr 10
, 2017
* @version 1.9.
3.20, May 7
, 2017
* @since 0.3.1
* @since 0.3.1
*/
*/
public
final
class
SoloServletListener
extends
AbstractServletListener
{
public
final
class
SoloServletListener
extends
AbstractServletListener
{
...
@@ -315,7 +315,6 @@ public final class SoloServletListener extends AbstractServletListener {
...
@@ -315,7 +315,6 @@ public final class SoloServletListener extends AbstractServletListener {
final
String
requestURI
=
httpServletRequest
.
getRequestURI
();
final
String
requestURI
=
httpServletRequest
.
getRequestURI
();
String
desiredView
=
Requests
.
mobileSwitchToggle
(
httpServletRequest
);
String
desiredView
=
Requests
.
mobileSwitchToggle
(
httpServletRequest
);
if
(
desiredView
==
null
&&
!
Requests
.
mobileRequest
(
httpServletRequest
)
||
desiredView
!=
null
&&
desiredView
.
equals
(
"normal"
))
{
if
(
desiredView
==
null
&&
!
Requests
.
mobileRequest
(
httpServletRequest
)
||
desiredView
!=
null
&&
desiredView
.
equals
(
"normal"
))
{
desiredView
=
preference
.
getString
(
Skin
.
SKIN_DIR_NAME
);
desiredView
=
preference
.
getString
(
Skin
.
SKIN_DIR_NAME
);
}
else
{
}
else
{
...
...
src/main/java/org/b3log/solo/processor/IndexProcessor.java
View file @
56ef1ba3
...
@@ -52,13 +52,14 @@ import java.io.IOException;
...
@@ -52,13 +52,14 @@ import java.io.IOException;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
/**
/**
* Index processor.
* Index processor.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.2.
2.6, Dec 27, 2015
* @version 1.2.
3.6, May 7, 2017
* @since 0.3.1
* @since 0.3.1
*/
*/
@RequestProcessor
@RequestProcessor
...
@@ -117,13 +118,22 @@ public class IndexProcessor {
...
@@ -117,13 +118,22 @@ public class IndexProcessor {
if
(
null
!=
specifiedSkin
)
{
if
(
null
!=
specifiedSkin
)
{
if
(
"default"
.
equals
(
specifiedSkin
))
{
if
(
"default"
.
equals
(
specifiedSkin
))
{
specifiedSkin
=
preference
.
optString
(
Option
.
ID_C_SKIN_DIR_NAME
);
specifiedSkin
=
preference
.
optString
(
Option
.
ID_C_SKIN_DIR_NAME
);
final
Cookie
cookie
=
new
Cookie
(
"skin"
,
null
);
cookie
.
setMaxAge
(
0
);
cookie
.
setPath
(
"/"
);
response
.
addCookie
(
cookie
);
}
}
}
else
{
}
else
{
specifiedSkin
=
preference
.
optString
(
Option
.
ID_C_SKIN_DIR_NAME
);
specifiedSkin
=
preference
.
optString
(
Option
.
ID_C_SKIN_DIR_NAME
);
}
}
Templates
.
MAIN_CFG
.
setServletContextForTemplateLoading
(
SoloServletListener
.
getServletContext
(),
"/skins/"
+
specifiedSkin
);
final
Set
<
String
>
skinDirNames
=
Skins
.
getSkinDirNames
();
request
.
setAttribute
(
Keys
.
TEMAPLTE_DIR_NAME
,
specifiedSkin
);
if
(
skinDirNames
.
contains
(
specifiedSkin
))
{
Templates
.
MAIN_CFG
.
setServletContextForTemplateLoading
(
SoloServletListener
.
getServletContext
(),
"/skins/"
+
specifiedSkin
);
request
.
setAttribute
(
Keys
.
TEMAPLTE_DIR_NAME
,
specifiedSkin
);
}
Skins
.
fillLangs
(
preference
.
optString
(
Option
.
ID_C_LOCALE_STRING
),
(
String
)
request
.
getAttribute
(
Keys
.
TEMAPLTE_DIR_NAME
),
dataModel
);
Skins
.
fillLangs
(
preference
.
optString
(
Option
.
ID_C_LOCALE_STRING
),
(
String
)
request
.
getAttribute
(
Keys
.
TEMAPLTE_DIR_NAME
),
dataModel
);
...
@@ -146,9 +156,11 @@ public class IndexProcessor {
...
@@ -146,9 +156,11 @@ public class IndexProcessor {
statisticMgmtService
.
incBlogViewCount
(
request
,
response
);
statisticMgmtService
.
incBlogViewCount
(
request
,
response
);
// https://github.com/b3log/solo/issues/12060
// https://github.com/b3log/solo/issues/12060
final
Cookie
cookie
=
new
Cookie
(
Skin
.
SKIN
,
specifiedSkin
);
if
(!
preference
.
optString
(
Skin
.
SKIN_DIR_NAME
).
equals
(
specifiedSkin
)
&&
!
Requests
.
mobileRequest
(
request
))
{
cookie
.
setPath
(
"/"
);
final
Cookie
cookie
=
new
Cookie
(
Skin
.
SKIN
,
specifiedSkin
);
response
.
addCookie
(
cookie
);
cookie
.
setPath
(
"/"
);
response
.
addCookie
(
cookie
);
}
}
catch
(
final
ServiceException
e
)
{
}
catch
(
final
ServiceException
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
...
...
src/main/java/org/b3log/solo/service/UserMgmtService.java
View file @
56ef1ba3
...
@@ -47,7 +47,7 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -47,7 +47,7 @@ import javax.servlet.http.HttpServletResponse;
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.1.0.
6, Oct 17, 2015
* @version 1.1.0.
7, May 6, 2017
* @since 0.4.0
* @since 0.4.0
*/
*/
@Service
@Service
...
@@ -56,7 +56,12 @@ public class UserMgmtService {
...
@@ -56,7 +56,12 @@ public class UserMgmtService {
/**
/**
* Logger.
* Logger.
*/
*/
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
UserMgmtService
.
class
.
getName
());
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
UserMgmtService
.
class
);
/**
* Length of hashed password.
*/
private
static
final
int
HASHED_PASSWORD_LENGTH
=
32
;
/**
/**
* User repository.
* User repository.
...
@@ -70,15 +75,10 @@ public class UserMgmtService {
...
@@ -70,15 +75,10 @@ public class UserMgmtService {
@Inject
@Inject
private
LangPropsService
langPropsService
;
private
LangPropsService
langPropsService
;
/**
* Length of hashed password.
*/
private
static
final
int
HASHED_PASSWORD_LENGTH
=
32
;
/**
/**
* Tries to login with cookie.
* Tries to login with cookie.
*
*
* @param request the specified request
* @param request
the specified request
* @param response the specified response
* @param response the specified response
*/
*/
public
void
tryLogInWithCookie
(
final
HttpServletRequest
request
,
final
HttpServletResponse
response
)
{
public
void
tryLogInWithCookie
(
final
HttpServletRequest
request
,
final
HttpServletResponse
response
)
{
...
@@ -91,7 +91,6 @@ public class UserMgmtService {
...
@@ -91,7 +91,6 @@ public class UserMgmtService {
try
{
try
{
for
(
int
i
=
0
;
i
<
cookies
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
cookies
.
length
;
i
++)
{
final
Cookie
cookie
=
cookies
[
i
];
final
Cookie
cookie
=
cookies
[
i
];
if
(!
"b3log-latke"
.
equals
(
cookie
.
getName
()))
{
if
(!
"b3log-latke"
.
equals
(
cookie
.
getName
()))
{
continue
;
continue
;
}
}
...
@@ -99,7 +98,6 @@ public class UserMgmtService {
...
@@ -99,7 +98,6 @@ public class UserMgmtService {
final
JSONObject
cookieJSONObject
=
new
JSONObject
(
cookie
.
getValue
());
final
JSONObject
cookieJSONObject
=
new
JSONObject
(
cookie
.
getValue
());
final
String
userEmail
=
cookieJSONObject
.
optString
(
User
.
USER_EMAIL
);
final
String
userEmail
=
cookieJSONObject
.
optString
(
User
.
USER_EMAIL
);
if
(
Strings
.
isEmptyOrNull
(
userEmail
))
{
if
(
Strings
.
isEmptyOrNull
(
userEmail
))
{
break
;
break
;
}
}
...
@@ -122,10 +120,9 @@ public class UserMgmtService {
...
@@ -122,10 +120,9 @@ public class UserMgmtService {
}
}
}
}
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
WARN
,
"Parses cookie failed, clears the cookie[name=b3log-latke]"
,
e
);
LOGGER
.
log
(
Level
.
TRACE
,
"Parses cookie failed, clears the cookie [name=b3log-latke]"
);
final
Cookie
cookie
=
new
Cookie
(
"b3log-latke"
,
null
);
final
Cookie
cookie
=
new
Cookie
(
"b3log-latke"
,
null
);
cookie
.
setMaxAge
(
0
);
cookie
.
setMaxAge
(
0
);
cookie
.
setPath
(
"/"
);
cookie
.
setPath
(
"/"
);
...
@@ -136,17 +133,13 @@ public class UserMgmtService {
...
@@ -136,17 +133,13 @@ public class UserMgmtService {
/**
/**
* Updates a user by the specified request json object.
* Updates a user by the specified request json object.
*
*
* @param requestJSONObject the specified request json object, for example, <pre>
* @param requestJSONObject the specified request json object, for example,
* {
* "oId": "",
* "oId": "",
* "userName": "",
* "userName": "",
* "userEmail": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userPassword": "", // Unhashed
* "userRole": "", // optional
* "userRole": "", // optional
* "userURL": "", // optional
* "userURL": "", // optional
* }
* </pre>
*
* @throws ServiceException service exception
* @throws ServiceException service exception
*/
*/
public
void
updateUser
(
final
JSONObject
requestJSONObject
)
throws
ServiceException
{
public
void
updateUser
(
final
JSONObject
requestJSONObject
)
throws
ServiceException
{
...
@@ -195,7 +188,7 @@ public class UserMgmtService {
...
@@ -195,7 +188,7 @@ public class UserMgmtService {
if
(!
Strings
.
isEmptyOrNull
(
userURL
))
{
if
(!
Strings
.
isEmptyOrNull
(
userURL
))
{
oldUser
.
put
(
User
.
USER_URL
,
userURL
);
oldUser
.
put
(
User
.
USER_URL
,
userURL
);
}
}
final
String
userAvatar
=
requestJSONObject
.
optString
(
UserExt
.
USER_AVATAR
);
final
String
userAvatar
=
requestJSONObject
.
optString
(
UserExt
.
USER_AVATAR
);
if
(!
StringUtils
.
equals
(
userAvatar
,
oldUser
.
optString
(
UserExt
.
USER_AVATAR
)))
{
if
(!
StringUtils
.
equals
(
userAvatar
,
oldUser
.
optString
(
UserExt
.
USER_AVATAR
)))
{
oldUser
.
put
(
UserExt
.
USER_AVATAR
,
userAvatar
);
oldUser
.
put
(
UserExt
.
USER_AVATAR
,
userAvatar
);
...
@@ -239,6 +232,7 @@ public class UserMgmtService {
...
@@ -239,6 +232,7 @@ public class UserMgmtService {
}
}
userRepository
.
update
(
userId
,
oldUser
);
userRepository
.
update
(
userId
,
oldUser
);
transaction
.
commit
();
transaction
.
commit
();
}
catch
(
final
RepositoryException
e
)
{
}
catch
(
final
RepositoryException
e
)
{
if
(
transaction
.
isActive
())
{
if
(
transaction
.
isActive
())
{
...
@@ -253,17 +247,14 @@ public class UserMgmtService {
...
@@ -253,17 +247,14 @@ public class UserMgmtService {
/**
/**
* Adds a user with the specified request json object.
* Adds a user with the specified request json object.
*
*
* @param requestJSONObject the specified request json object, for example, <pre>
* @param requestJSONObject the specified request json object, for example,
* {
* "userName": "",
* "userName": "",
* "userEmail": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userPassword": "", // Unhashed
* "userURL": "", // optional, uses 'servePath' instead if not specified
* "userURL": "", // optional, uses 'servePath' instead if not specified
* "userRole": "", // optional, uses {@value Role#DEFAULT_ROLE} instead if not specified
* "userRole": "", // optional, uses {@value Role#DEFAULT_ROLE} instead if not specified
* "userAvatar": "" // optional, users generated gravatar url instead if not specified
* "userAvatar": "" // optional, users generated gravatar url instead if not specified
* ,see {@link User} for more details
* }
* </pre>,see {@link User} for more details
*
* @return generated user id
* @return generated user id
* @throws ServiceException service exception
* @throws ServiceException service exception
*/
*/
...
...
src/main/java/org/b3log/solo/util/Skins.java
View file @
56ef1ba3
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
package
org
.
b3log
.
solo
.
util
;
package
org
.
b3log
.
solo
.
util
;
import
freemarker.template.TemplateExceptionHandler
;
import
freemarker.template.TemplateExceptionHandler
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.ioc.LatkeBeanManager
;
import
org.b3log.latke.ioc.LatkeBeanManager
;
import
org.b3log.latke.ioc.Lifecycle
;
import
org.b3log.latke.ioc.Lifecycle
;
...
@@ -25,6 +26,7 @@ import org.b3log.latke.service.LangPropsService;
...
@@ -25,6 +26,7 @@ import org.b3log.latke.service.LangPropsService;
import
org.b3log.latke.service.LangPropsServiceImpl
;
import
org.b3log.latke.service.LangPropsServiceImpl
;
import
org.b3log.latke.service.ServiceException
;
import
org.b3log.latke.service.ServiceException
;
import
org.b3log.latke.util.Locales
;
import
org.b3log.latke.util.Locales
;
import
org.b3log.latke.util.Requests
;
import
org.b3log.latke.util.Stopwatchs
;
import
org.b3log.latke.util.Stopwatchs
;
import
org.b3log.latke.util.Strings
;
import
org.b3log.latke.util.Strings
;
import
org.b3log.latke.util.freemarker.Templates
;
import
org.b3log.latke.util.freemarker.Templates
;
...
@@ -42,7 +44,7 @@ import java.util.*;
...
@@ -42,7 +44,7 @@ import java.util.*;
* Skin utilities.
* Skin utilities.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.
4.8, Nov 2, 2016
* @version 1.1.
5.8, May 7, 2017
* @since 0.3.1
* @since 0.3.1
*/
*/
public
final
class
Skins
{
public
final
class
Skins
{
...
@@ -67,9 +69,9 @@ public final class Skins {
...
@@ -67,9 +69,9 @@ public final class Skins {
* Fills the specified data model with the current skink's (WebRoot/skins/${skinName}/lang/lang_xx_XX.properties)
* Fills the specified data model with the current skink's (WebRoot/skins/${skinName}/lang/lang_xx_XX.properties)
* and core language (WebRoot/WEB-INF/classes/lang_xx_XX.properties) configurations.
* and core language (WebRoot/WEB-INF/classes/lang_xx_XX.properties) configurations.
*
*
* @param localeString the specified locale string
* @param localeString
the specified locale string
* @param currentSkinDirName the specified current skin directory name
* @param currentSkinDirName the specified current skin directory name
* @param dataModel the specified data model
* @param dataModel
the specified data model
* @throws ServiceException service exception
* @throws ServiceException service exception
*/
*/
public
static
void
fillLangs
(
final
String
localeString
,
final
String
currentSkinDirName
,
final
Map
<
String
,
Object
>
dataModel
)
public
static
void
fillLangs
(
final
String
localeString
,
final
String
currentSkinDirName
,
final
Map
<
String
,
Object
>
dataModel
)
...
@@ -157,8 +159,7 @@ public final class Skins {
...
@@ -157,8 +159,7 @@ public final class Skins {
final
Set
<
String
>
ret
=
new
HashSet
<
String
>();
final
Set
<
String
>
ret
=
new
HashSet
<
String
>();
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
final
Set
<
String
>
resourcePaths
=
servletContext
.
getResourcePaths
(
"/skins"
);
final
Set
<
String
>
resourcePaths
=
servletContext
.
getResourcePaths
(
"/skins"
);
for
(
final
String
path
:
resourcePaths
)
{
for
(
final
String
path
:
resourcePaths
)
{
final
String
dirName
=
path
.
substring
(
"/skins"
.
length
()
+
1
,
path
.
length
()
-
1
);
final
String
dirName
=
path
.
substring
(
"/skins"
.
length
()
+
1
,
path
.
length
()
-
1
);
...
@@ -174,7 +175,8 @@ public final class Skins {
...
@@ -174,7 +175,8 @@ public final class Skins {
}
}
/**
/**
* Gets skin directory name from the specified request.
* Gets skin directory name from the specified request. Refers to https://github.com/b3log/solo/issues/12060 for
* more details.
*
*
* @param request the specified request
* @param request the specified request
* @return directory name, or {@code "default"} if not found
* @return directory name, or {@code "default"} if not found
...
@@ -182,16 +184,18 @@ public final class Skins {
...
@@ -182,16 +184,18 @@ public final class Skins {
public
static
String
getSkinDirName
(
final
HttpServletRequest
request
)
{
public
static
String
getSkinDirName
(
final
HttpServletRequest
request
)
{
// https://github.com/b3log/solo/issues/12060
// https://github.com/b3log/solo/issues/12060
if
(
Requests
.
mobileRequest
(
request
))
{
return
(
String
)
request
.
getAttribute
(
Keys
.
TEMAPLTE_DIR_NAME
);
// resolved in listener
}
// 1. Get skin from query
// 1. Get skin from query
final
String
specifiedSkin
=
request
.
getParameter
(
Skin
.
SKIN
);
final
String
specifiedSkin
=
request
.
getParameter
(
Skin
.
SKIN
);
if
(
"default"
.
equals
(
specifiedSkin
))
{
if
(
"default"
.
equals
(
specifiedSkin
))
{
return
"default"
;
return
"default"
;
}
}
if
(!
Strings
.
isEmptyOrNull
(
specifiedSkin
))
{
if
(!
Strings
.
isEmptyOrNull
(
specifiedSkin
))
{
final
Set
<
String
>
skinDirNames
=
Skins
.
getSkinDirNames
();
final
Set
<
String
>
skinDirNames
=
Skins
.
getSkinDirNames
();
if
(
skinDirNames
.
contains
(
specifiedSkin
))
{
if
(
skinDirNames
.
contains
(
specifiedSkin
))
{
return
specifiedSkin
;
return
specifiedSkin
;
}
else
{
}
else
{
...
...
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