Commit f271af1b authored by Liang Ding's avatar Liang Ding

注册用户加入 URL 字段

暂时没有加入升级程序,所以需要重新初始化开发库。
parent dcc31bcc
......@@ -60,6 +60,7 @@ import org.json.JSONObject;
@RequestProcessor
// TODO: 060
// 1. Add column Preference.feedOutputCnt
// 2. Add column User.userURL
public final class UpgradeProcessor {
/**
......
......@@ -437,6 +437,7 @@ public final class InitService {
admin.put(User.USER_NAME, requestJSONObject.getString(User.USER_NAME));
admin.put(User.USER_EMAIL, requestJSONObject.getString(User.USER_EMAIL));
admin.put(User.USER_URL, Latkes.getServePath());
admin.put(User.USER_ROLE, Role.ADMIN_ROLE);
admin.put(User.USER_PASSWORD, MD5.hash(requestJSONObject.getString(User.USER_PASSWORD)));
admin.put(UserExt.USER_ARTICLE_COUNT, 0);
......
......@@ -19,6 +19,7 @@ package org.b3log.solo.service;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.model.Role;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.RepositoryException;
......@@ -26,6 +27,7 @@ import org.b3log.latke.repository.Transaction;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.ServiceException;
import org.b3log.latke.util.MD5;
import org.b3log.latke.util.Strings;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.repository.UserRepository;
import org.b3log.solo.repository.impl.UserRepositoryImpl;
......@@ -67,7 +69,8 @@ public final class UserMgmtService {
* "userName": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userRole": ""
* "userRole": "", // optional
* "userURL": "", // optional
* }
* </pre>
* @throws ServiceException service exception
......@@ -99,8 +102,19 @@ public final class UserMgmtService {
oldUser.put(User.USER_EMAIL, userNewEmail);
oldUser.put(User.USER_NAME, userName);
oldUser.put(User.USER_PASSWORD, MD5.hash(userPassword));
// Unchanges the default role
final String userRole = requestJSONObject.optString(User.USER_ROLE);
if (!Strings.isEmptyOrNull(userRole)) {
oldUser.put(User.USER_ROLE, userRole);
}
final String userURL = requestJSONObject.optString(User.USER_URL);
if (!Strings.isEmptyOrNull(userURL)) {
oldUser.put(User.USER_URL, userURL);
}
userRepository.update(oldUserId, oldUser);
transaction.commit();
} catch (final RepositoryException e) {
......@@ -159,8 +173,8 @@ public final class UserMgmtService {
* "userName": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userRole": "" // optional, uses {@value Role#DEFAULT_ROLE} instead,
* if not speciffied
* "userURL": "", // optional, uses 'servePath' instead if not specified
* "userRole": "" // optional, uses {@value Role#DEFAULT_ROLE} instead, if not speciffied
* }
* </pre>,see {@link User} for more details
* @return generated user id
......@@ -182,16 +196,32 @@ public final class UserMgmtService {
throw new ServiceException(langPropsService.get("duplicatedEmailLabel"));
}
user.put(User.USER_EMAIL, userEmail);
final String userName = requestJSONObject.optString(User.USER_NAME);
user.put(User.USER_EMAIL, userEmail);
user.put(User.USER_NAME, userName);
final String userPassword = requestJSONObject.optString(User.USER_PASSWORD);
user.put(User.USER_PASSWORD, MD5.hash(userPassword));
String userURL = requestJSONObject.optString(User.USER_URL);
if (Strings.isEmptyOrNull(userURL)) {
userURL = Latkes.getServePath();
}
if (!Strings.isURL(userURL)) {
throw new ServiceException(langPropsService.get("urlInvalidLabel"));
}
user.put(User.USER_URL, userURL);
final String roleName = requestJSONObject.optString(User.USER_ROLE, Role.DEFAULT_ROLE);
user.put(User.USER_ROLE, roleName);
user.put(UserExt.USER_ARTICLE_COUNT, 0);
user.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
......
{
"description": "Description of repository structures, for generation (DDL: http://en.wikipedia.org/wiki/Data_Definition_Language) of the relational database table and persistence validation.",
"version": "1.0.0.9, Mar 5, 2013",
"version": "1.0.1.0, Apr 2, 2013",
"authors": ["Liang Ding"],
"since": "0.4.0",
......@@ -538,6 +538,11 @@
"type": "String",
"length": 255
},
{
"name": "userURL",
"type": "String",
"length": 255
},
{
"name": "userPassword",
"type": "String",
......
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.model.Role;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.FilterOperator;
import org.b3log.latke.repository.PropertyFilter;
import org.b3log.latke.repository.Query;
import org.b3log.latke.repository.Transaction;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.repository.UserRepository;
import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* {@link UserRepositoryImpl} test case.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.1, Feb 21, 2012
*/
@Test(suiteName = "repository")
public final class UserRepositoryImplTestCase extends AbstractTestCase {
/**
* Tests.
*
* @throws Exception exception
*/
@Test
public void test() throws Exception {
final UserRepository userRepository = getUserRepository();
final JSONObject another = new JSONObject();
another.put(User.USER_NAME, "test1");
another.put(User.USER_EMAIL, "test1@gmail.com");
another.put(User.USER_PASSWORD, "pass1");
another.put(User.USER_ROLE, Role.DEFAULT_ROLE);
another.put(UserExt.USER_ARTICLE_COUNT, 0);
another.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
Transaction transaction = userRepository.beginTransaction();
userRepository.add(another);
transaction.commit();
Assert.assertNull(userRepository.getAdmin());
JSONObject admin = new JSONObject();
admin.put(User.USER_NAME, "test");
admin.put(User.USER_EMAIL, "test@gmail.com");
admin.put(User.USER_PASSWORD, "pass");
admin.put(User.USER_ROLE, Role.ADMIN_ROLE);
admin.put(UserExt.USER_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
transaction = userRepository.beginTransaction();
userRepository.add(admin);
transaction.commit();
Assert.assertTrue(userRepository.isAdminEmail("test@gmail.com"));
Assert.assertFalse(userRepository.isAdminEmail("notFound@gmail.com"));
admin = userRepository.getAdmin();
Assert.assertNotNull(admin);
Assert.assertEquals("test", admin.optString(User.USER_NAME));
final JSONObject result = userRepository.get(new Query().setFilter(
new PropertyFilter(User.USER_NAME, FilterOperator.EQUAL, "test1")));
final JSONArray users = result.getJSONArray(Keys.RESULTS);
Assert.assertEquals(users.length(), 1);
Assert.assertEquals(users.getJSONObject(0).getString(User.USER_EMAIL), "test1@gmail.com");
final JSONObject notFound = userRepository.getByEmail("not.found@gmail.com");
Assert.assertNull(notFound);
final JSONObject found = userRepository.getByEmail("test1@gmail.com");
Assert.assertNotNull(found);
Assert.assertEquals(found.getString(User.USER_PASSWORD), "pass1");
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.model.Role;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.FilterOperator;
import org.b3log.latke.repository.PropertyFilter;
import org.b3log.latke.repository.Query;
import org.b3log.latke.repository.Transaction;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.repository.UserRepository;
import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* {@link UserRepositoryImpl} test case.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.2, Apr 2, 2013
*/
@Test(suiteName = "repository")
public final class UserRepositoryImplTestCase extends AbstractTestCase {
/**
* Tests.
*
* @throws Exception exception
*/
@Test
public void test() throws Exception {
final UserRepository userRepository = getUserRepository();
final JSONObject another = new JSONObject();
another.put(User.USER_NAME, "test1");
another.put(User.USER_EMAIL, "test1@gmail.com");
another.put(User.USER_PASSWORD, "pass1");
another.put(User.USER_URL, "http://b3log.org");
another.put(User.USER_ROLE, Role.DEFAULT_ROLE);
another.put(UserExt.USER_ARTICLE_COUNT, 0);
another.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
Transaction transaction = userRepository.beginTransaction();
userRepository.add(another);
transaction.commit();
Assert.assertNull(userRepository.getAdmin());
JSONObject admin = new JSONObject();
admin.put(User.USER_NAME, "test");
admin.put(User.USER_EMAIL, "test@gmail.com");
admin.put(User.USER_PASSWORD, "pass");
admin.put(User.USER_URL, "http://b3log.org");
admin.put(User.USER_ROLE, Role.ADMIN_ROLE);
admin.put(UserExt.USER_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
transaction = userRepository.beginTransaction();
userRepository.add(admin);
transaction.commit();
Assert.assertTrue(userRepository.isAdminEmail("test@gmail.com"));
Assert.assertFalse(userRepository.isAdminEmail("notFound@gmail.com"));
admin = userRepository.getAdmin();
Assert.assertNotNull(admin);
Assert.assertEquals("test", admin.optString(User.USER_NAME));
final JSONObject result = userRepository.get(new Query().setFilter(
new PropertyFilter(User.USER_NAME, FilterOperator.EQUAL, "test1")));
final JSONArray users = result.getJSONArray(Keys.RESULTS);
Assert.assertEquals(users.length(), 1);
Assert.assertEquals(users.getJSONObject(0).getString(User.USER_EMAIL), "test1@gmail.com");
final JSONObject notFound = userRepository.getByEmail("not.found@gmail.com");
Assert.assertNull(notFound);
final JSONObject found = userRepository.getByEmail("test1@gmail.com");
Assert.assertNotNull(found);
Assert.assertEquals(found.getString(User.USER_PASSWORD), "pass1");
}
}
......@@ -16,7 +16,7 @@
#
# Description: B3log Solo language configurations(en_US).
# Version: 2.1.0.6, Apr 1, 2013
# Version: 2.1.0.7, Apr 2, 2013
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
......@@ -193,6 +193,8 @@ userName1Label=Username:
userLabel=User
userPassword1Label=Password:
userPasswordLabel=Password
userURL1Label=Link:
userURLLabel=Link
categoryLabel=Category
noticeBoard1Label=Notice Board:
noticeBoardLabel=Notice Board
......
......@@ -16,7 +16,7 @@
#
# Description: B3log Solo default language configurations(zh_CN).
# Version: 2.1.1.3, Apr 1, 2013
# Version: 2.1.1.4, Apr 2, 2013
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
......@@ -193,6 +193,8 @@ userName1Label=\u7528\u6237\u540d\uff1a
userLabel=\u7528\u6237
userPassword1Label=\u5bc6\u7801\uff1a
userPasswordLabel=\u5bc6\u7801
userURL1Label=\u94fe\u63a5\uff1a
userURLLabel=\u94fe\u63a5
categoryLabel=\u5206\u7c7b
noticeBoard1Label=\u516c\u544a\uff1a
noticeBoardLabel=\u516c\u544a
......
<div id="userTable"></div>
<div id="userPagination" class="margin12 right"></div>
<div class="clear"></div>
<table class="form" width="100%" cellpadding="0px" cellspacing="9px">
<thead>
<tr>
<th style="text-align: left" colspan="2">
${addUserLabel}
</th>
</tr>
</thead>
<tbody>
<tr>
<th width="48px">
<label for="userName">${commentName1Label}</label>
</th>
<td>
<input id="userName" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userEmail">${commentEmail1Label}</label>
</th>
<td>
<input id="userEmail" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userPassword">${userPassword1Label}</label>
</th>
<td>
<input id="userPassword" type="password"/>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<button onclick="admin.userList.add();">${saveLabel}</button>
</td>
</tr>
</tbody>
</table>
<div id="userUpdate" class="none">
<table class="form" width="100%" cellpadding="0px" cellspacing="9px">
<thead>
<tr>
<th style="text-align: left" colspan="2">
${updateUserLabel}
</th>
</tr>
</thead>
<tbody>
<tr>
<th width="48px">
<label for="userNameUpdate">${commentName1Label}</label>
</th>
<td>
<input id="userNameUpdate" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userEmailUpdate">${commentEmail1Label}</label>
</th>
<td>
<input id="userEmailUpdate" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userPasswordUpdate">${userPassword1Label}</label>
</th>
<td>
<input id="userPasswordUpdate" type="password"/>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<button onclick="admin.userList.update();">${updateLabel}</button>
</td>
</tr>
</tbody>
</table>
</div>
${plugins}
<div id="userTable"></div>
<div id="userPagination" class="margin12 right"></div>
<div class="clear"></div>
<table class="form" width="100%" cellpadding="0px" cellspacing="9px">
<thead>
<tr>
<th style="text-align: left" colspan="2">
${addUserLabel}
</th>
</tr>
</thead>
<tbody>
<tr>
<th width="48px">
<label for="userName">${commentName1Label}</label>
</th>
<td>
<input id="userName" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userEmail">${commentEmail1Label}</label>
</th>
<td>
<input id="userEmail" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userURL">${userURL1Label}</label>
</th>
<td>
<input id="userURL" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userPassword">${userPassword1Label}</label>
</th>
<td>
<input id="userPassword" type="password"/>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<button onclick="admin.userList.add();">${saveLabel}</button>
</td>
</tr>
</tbody>
</table>
<div id="userUpdate" class="none">
<table class="form" width="100%" cellpadding="0px" cellspacing="9px">
<thead>
<tr>
<th style="text-align: left" colspan="2">
${updateUserLabel}
</th>
</tr>
</thead>
<tbody>
<tr>
<th width="48px">
<label for="userNameUpdate">${commentName1Label}</label>
</th>
<td>
<input id="userNameUpdate" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userEmailUpdate">${commentEmail1Label}</label>
</th>
<td>
<input id="userEmailUpdate" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userURLUpdate">${userURL1Label}</label>
</th>
<td>
<input id="userURLUpdate" type="text"/>
</td>
</tr>
<tr>
<th>
<label for="userPasswordUpdate">${userPassword1Label}</label>
</th>
<td>
<input id="userPasswordUpdate" type="password"/>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<button onclick="admin.userList.update();">${updateLabel}</button>
</td>
</tr>
</tbody>
</table>
</div>
${plugins}
......@@ -134,6 +134,7 @@ admin.userList = {
var requestJSONObject = {
"userName": $("#userName").val(),
"userEmail": $("#userEmail").val(),
"userURL": $("#userURL").val(),
"userPassword": $("#userPassword").val()
};
......@@ -151,6 +152,7 @@ admin.userList = {
$("#userName").val("");
$("#userEmail").val("");
$("#userURL").val("");
$("#userPassword").val("");
if (admin.userList.pageInfo.currentCount === Label.PAGE_SIZE &&
admin.userList.pageInfo.currentPage === admin.userList.pageInfo.pageCount) {
......@@ -198,6 +200,8 @@ admin.userList = {
} else {
$userEmailUpdate.removeAttr("disabled");
}
$("#userURLUpdate").val(result.user.userURL);
$("#userPasswordUpdate").val(result.user.userPassword);
$("#loadMsg").text("");
......@@ -217,6 +221,7 @@ admin.userList = {
"userName": $("#userNameUpdate").val(),
"oId": userInfo.oId,
"userEmail": $("#userEmailUpdate").val(),
"userURL": $("#userURLUpdate").val(),
"userRole": userInfo.userRole,
"userPassword": $("#userPasswordUpdate").val()
};
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment