Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo
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
Commits
4486b679
Commit
4486b679
authored
Mar 18, 2013
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#199
完成社区同步更新博客(issue 描述里的第一点:1. 提供文章更新接口给社区)
parent
9e1d40df
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
387 additions
and
275 deletions
+387
-275
core/src/main/java/org/b3log/solo/api/symphony/ArticleReceiver.java
...ain/java/org/b3log/solo/api/symphony/ArticleReceiver.java
+103
-3
core/src/main/java/org/b3log/solo/processor/LoginProcessor.java
...rc/main/java/org/b3log/solo/processor/LoginProcessor.java
+15
-6
core/src/main/java/org/b3log/solo/util/Permalinks.java
core/src/main/java/org/b3log/solo/util/Permalinks.java
+258
-258
core/src/main/java/org/b3log/solo/util/Randoms.java
core/src/main/java/org/b3log/solo/util/Randoms.java
+11
-8
No files found.
core/src/main/java/org/b3log/solo/api/symphony/ArticleReceiver.java
View file @
4486b679
...
...
@@ -33,6 +33,7 @@ import org.b3log.solo.model.Article;
import
org.b3log.solo.model.Common
;
import
org.b3log.solo.model.Preference
;
import
org.b3log.solo.service.ArticleMgmtService
;
import
org.b3log.solo.service.ArticleQueryService
;
import
org.b3log.solo.service.PreferenceQueryService
;
import
org.b3log.solo.service.UserQueryService
;
import
org.b3log.solo.util.QueryResults
;
...
...
@@ -44,7 +45,7 @@ import org.jsoup.Jsoup;
* Article receiver (from B3log Symphony).
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.
4, Jan 4
, 2013
* @version 1.0.0.
5, Mar 18
, 2013
* @since 0.5.5
*/
@RequestProcessor
...
...
@@ -65,6 +66,11 @@ public final class ArticleReceiver {
*/
private
ArticleMgmtService
articleMgmtService
=
ArticleMgmtService
.
getInstance
();
/**
* Article query service.
*/
private
ArticleQueryService
articleQueryService
=
ArticleQueryService
.
getInstance
();
/**
* Article abstract length.
*/
...
...
@@ -101,7 +107,7 @@ public final class ArticleReceiver {
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing
(
value
=
"/apis/symphony/article"
,
method
=
HTTPRequestMethod
.
P
U
T
)
@RequestProcessing
(
value
=
"/apis/symphony/article"
,
method
=
HTTPRequestMethod
.
P
OS
T
)
public
void
addArticle
(
final
HttpServletRequest
request
,
final
HttpServletResponse
response
,
final
HTTPRequestContext
context
)
throws
Exception
{
final
JSONRenderer
renderer
=
new
JSONRenderer
();
...
...
@@ -142,7 +148,7 @@ public final class ArticleReceiver {
final
String
articleId
=
article
.
getString
(
Keys
.
OBJECT_ID
);
content
+=
"<br/><br/><p style='font-size: 12px;'><i>该文章同步自 <a href='http://symphony.b3log.org/article/"
+
articleId
+
"' target='_blank>B3log 社区</a></i></p>"
;
+
"' target='_blank
'
>B3log 社区</a></i></p>"
;
article
.
put
(
Article
.
ARTICLE_CONTENT
,
content
);
articleMgmtService
.
addArticle
(
requestJSONObject
);
...
...
@@ -161,4 +167,98 @@ public final class ArticleReceiver {
jsonObject
.
put
(
Keys
.
MSG
,
e
.
getMessage
());
}
}
/**
* Updates an article with the specified request.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "msg": ""
* }
* </pre>
* </p>
*
* @param request the specified http servlet request, for example,
* <pre>
* {
* "article": {
* "oId": "", // Symphony Article#clientArticleId
* "articleTitle": "",
* "articleContent": "",
* "articleTags": "tag1,tag2,tag3",
* "userB3Key": "",
* "articleEditorType": ""
* }
* }
* </pre>
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing
(
value
=
"/apis/symphony/article"
,
method
=
HTTPRequestMethod
.
PUT
)
public
void
updateArticle
(
final
HttpServletRequest
request
,
final
HttpServletResponse
response
,
final
HTTPRequestContext
context
)
throws
Exception
{
final
JSONRenderer
renderer
=
new
JSONRenderer
();
context
.
setRenderer
(
renderer
);
final
JSONObject
ret
=
new
JSONObject
();
renderer
.
setJSONObject
(
ret
);
try
{
final
JSONObject
requestJSONObject
=
Requests
.
parseRequestJSONObject
(
request
,
response
);
final
JSONObject
article
=
requestJSONObject
.
optJSONObject
(
Article
.
ARTICLE
);
final
String
userB3Key
=
article
.
optString
(
"userB3Key"
);
final
JSONObject
preference
=
preferenceQueryService
.
getPreference
();
if
(!
userB3Key
.
equals
(
preference
.
optString
(
Preference
.
KEY_OF_SOLO
)))
{
LOGGER
.
log
(
Level
.
WARNING
,
"B3 key not match, ignored update article"
);
return
;
}
article
.
remove
(
"userB3Key"
);
final
String
articleId
=
article
.
getString
(
Keys
.
OBJECT_ID
);
if
(
null
==
articleQueryService
.
getArticleById
(
articleId
))
{
ret
.
put
(
Keys
.
MSG
,
"No found article[oId="
+
articleId
+
"] to update"
);
ret
.
put
(
Keys
.
STATUS_CODE
,
false
);
return
;
}
final
String
plainTextContent
=
Jsoup
.
parse
(
article
.
optString
(
Article
.
ARTICLE_CONTENT
)).
text
();
if
(
plainTextContent
.
length
()
>
ARTICLE_ABSTRACT_LENGTH
)
{
article
.
put
(
Article
.
ARTICLE_ABSTRACT
,
plainTextContent
.
substring
(
0
,
ARTICLE_ABSTRACT_LENGTH
)
+
"...."
);
}
else
{
article
.
put
(
Article
.
ARTICLE_ABSTRACT
,
plainTextContent
);
}
article
.
put
(
Article
.
ARTICLE_IS_PUBLISHED
,
true
);
article
.
put
(
Common
.
POST_TO_COMMUNITY
,
false
);
// Do not send to rhythm
article
.
put
(
Article
.
ARTICLE_COMMENTABLE
,
true
);
article
.
put
(
Article
.
ARTICLE_VIEW_PWD
,
""
);
String
content
=
article
.
getString
(
Article
.
ARTICLE_CONTENT
);
content
+=
"<br/><br/><p style='font-size: 12px;'><i>该文章同步自 <a href='http://symphony.b3log.org/article/"
+
articleId
+
"' target='_blank'>B3log 社区</a></i></p>"
;
article
.
put
(
Article
.
ARTICLE_CONTENT
,
content
);
articleMgmtService
.
updateArticle
(
requestJSONObject
);
ret
.
put
(
Keys
.
MSG
,
"update article succ"
);
ret
.
put
(
Keys
.
STATUS_CODE
,
true
);
}
catch
(
final
ServiceException
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
e
.
getMessage
(),
e
);
final
JSONObject
jsonObject
=
QueryResults
.
defaultResult
();
renderer
.
setJSONObject
(
jsonObject
);
jsonObject
.
put
(
Keys
.
MSG
,
e
.
getMessage
());
}
}
}
core/src/main/java/org/b3log/solo/processor/LoginProcessor.java
View file @
4486b679
...
...
@@ -15,6 +15,7 @@
*/
package
org
.
b3log
.
solo
.
processor
;
import
java.io.IOException
;
import
java.util.Calendar
;
import
java.util.Map
;
...
...
@@ -54,6 +55,7 @@ import org.b3log.solo.util.Randoms;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
* Login/logout processor.
*
...
...
@@ -72,30 +74,37 @@ public final class LoginProcessor {
* Logger.
*/
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
LoginProcessor
.
class
.
getName
());
/**
* User query service.
*/
private
static
UserQueryService
userQueryService
=
UserQueryService
.
getInstance
();
/**
* User service.
*/
private
UserService
userService
=
UserServiceFactory
.
getUserService
();
/**
* Mail service.
*/
private
MailService
mailService
=
MailServiceFactory
.
getMailService
();
/**
* User management service.
*/
private
UserMgmtService
userMgmtService
=
UserMgmtService
.
getInstance
();
/**
* Language service.
*/
private
LangPropsService
langPropsService
=
LangPropsService
.
getInstance
();
/**
* Filler.
*/
private
Filler
filler
=
Filler
.
getInstance
();
/**
* Preference query service.
*/
...
...
@@ -142,7 +151,7 @@ public final class LoginProcessor {
*
* @param context the specified context
*/
@RequestProcessing
(
value
=
{
"/login"
},
method
=
HTTPRequestMethod
.
POST
)
@RequestProcessing
(
value
=
{
"/login"
},
method
=
HTTPRequestMethod
.
POST
)
public
void
login
(
final
HTTPRequestContext
context
)
{
final
HttpServletRequest
request
=
context
.
getRequest
();
...
...
@@ -200,7 +209,7 @@ public final class LoginProcessor {
* @param context the specified context
* @throws IOException io exception
*/
@RequestProcessing
(
value
=
{
"/logout"
},
method
=
HTTPRequestMethod
.
GET
)
@RequestProcessing
(
value
=
{
"/logout"
},
method
=
HTTPRequestMethod
.
GET
)
public
void
logout
(
final
HTTPRequestContext
context
)
throws
IOException
{
final
HttpServletRequest
httpServletRequest
=
context
.
getRequest
();
...
...
@@ -249,7 +258,7 @@ public final class LoginProcessor {
*
* @param context the specified context
*/
@RequestProcessing
(
value
=
{
"/forgot"
},
method
=
HTTPRequestMethod
.
POST
)
@RequestProcessing
(
value
=
{
"/forgot"
},
method
=
HTTPRequestMethod
.
POST
)
public
void
forgot
(
final
HTTPRequestContext
context
)
{
final
HttpServletRequest
request
=
context
.
getRequest
();
...
...
@@ -376,7 +385,8 @@ public final class LoginProcessor {
final
String
mailSubject
=
langPropsService
.
get
(
"resetPwdMailSubject"
);
final
String
mailBody
=
langPropsService
.
get
(
"resetPwdMailBody"
)
+
randomPwd
;
final
MailService
.
Message
message
=
new
MailService
.
Message
();
//FIXME whether we should put the ever-hashed password here, rather during updating?
// FIXME whether we should put the ever-hashed password here, rather during updating?
user
.
put
(
User
.
USER_PASSWORD
,
randomPwd
);
userMgmtService
.
updateUser
(
user
);
...
...
@@ -391,8 +401,7 @@ public final class LoginProcessor {
jsonObject
.
put
(
"to"
,
Latkes
.
getServePath
()
+
"/login"
);
jsonObject
.
put
(
Keys
.
MSG
,
langPropsService
.
get
(
"resetPwdSuccessMsg"
));
LOGGER
.
log
(
Level
.
FINER
,
"Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]"
,
new
Object
[]{
mailSubject
,
mailBody
,
userEmail
});
LOGGER
.
log
(
Level
.
FINER
,
"Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]"
,
new
Object
[]
{
mailSubject
,
mailBody
,
userEmail
});
}
/**
...
...
core/src/main/java/org/b3log/solo/util/Permalinks.java
View file @
4486b679
This diff is collapsed.
Click to expand it.
core/src/main/java/org/b3log/solo/util/Randoms.java
View file @
4486b679
...
...
@@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
org
.
b3log
.
solo
.
util
;
import
java.util.Random
;
/**
* Generate random stuff, <p> currently only support random alpha and digital
* string, whose length is also random between 8 and 16.
...
...
@@ -34,27 +33,32 @@ public class Randoms {
* String's length should be positive.
*/
private
static
final
int
LEN_LIM
=
1
;
/**
* String's length maximum limit.
*/
private
static
final
int
MAX_LEN
=
16
;
/**
* String's length minimum limit.
*/
private
static
final
int
MIN_LEN
=
8
;
/**
* String's random length.
*/
private
static
final
int
RANDOM_LEN
=
new
Random
()
.
nextInt
(
MAX_LEN
-
MIN_LEN
+
LEN_LIM
)
+
MIN_LEN
;
private
static
final
int
RANDOM_LEN
=
new
Random
()
.
nextInt
(
MAX_LEN
-
MIN_LEN
+
LEN_LIM
)
+
MIN_LEN
;
/**
* Characters set table, can be extended.
*/
private
final
char
[]
table
;
/**
* String's random seed.
*/
private
final
Random
random
=
new
Random
();
/**
* String's random characters buffer.
*/
...
...
@@ -76,8 +80,7 @@ public class Randoms {
if
(
length
<
LEN_LIM
)
{
throw
new
IllegalArgumentException
(
"length < 1: "
+
length
);
}
table
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
.
toCharArray
();
table
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
.
toCharArray
();
buf
=
new
char
[
length
];
}
...
...
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