完成注册功能
This commit is contained in:
parent
f3891b0d62
commit
79cfdc9cc0
|
|
@ -179,6 +179,20 @@ db.updateUserLastLogin = function(id) {
|
|||
});
|
||||
};
|
||||
|
||||
db.register = function(user) {
|
||||
console.log('register');
|
||||
var sql = "INSERT INTO `users` (`username`, `password`, `email`) VALUES ('" + user.username + "', '" + user.password + "', '" + user.email + "')";
|
||||
return new Promise(function(resolve, reject) {
|
||||
client.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(result.affectedRows);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
db.getUser = function(username) {
|
||||
console.log('getUser');
|
||||
var sql = "SELECT * FROM `users` WHERE `username` = '" + username + "'";
|
||||
|
|
@ -294,7 +308,7 @@ db.getBookmarksByTag = function(params) {
|
|||
params.currentPage = params.currentPage || 1;
|
||||
params.perPageItems = params.perPageItems || 20;
|
||||
|
||||
var sql = "SELECT bookmarks.id, bookmarks.user_id, bookmarks.title, bookmarks.description, bookmarks.url, bookmarks.public, bookmarks.click_count, DATE_FORMAT(bookmarks.created_at, '%Y-%m-%d') as created_at, DATE_FORMAT(bookmarks.last_click, '%Y-%m-%d') as last_click FROM `tags_bookmarks`, `bookmarks` WHERE tags_bookmarks.tag_id = '"+ tag_id +"' AND tags_bookmarks.bookmark_id = bookmarks.id";
|
||||
var sql = "SELECT bookmarks.id, bookmarks.user_id, bookmarks.title, bookmarks.description, bookmarks.url, bookmarks.public, bookmarks.click_count, DATE_FORMAT(bookmarks.created_at, '%Y-%m-%d') as created_at, DATE_FORMAT(bookmarks.last_click, '%Y-%m-%d') as last_click FROM `tags_bookmarks`, `bookmarks` WHERE tags_bookmarks.tag_id = '" + tag_id + "' AND tags_bookmarks.bookmark_id = bookmarks.id";
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
client.query(sql, (err, result) => {
|
||||
|
|
@ -330,7 +344,7 @@ db.getBookmarksSearch = function(params) {
|
|||
d.setDate(d.getDate() - parseInt(params.dateCreate));
|
||||
sql += " AND `created_at` >= '" + d.format('yyyy-MM-dd') + "'"
|
||||
} else if (params.dateCreateBegin && params.dateCreateEnd) {
|
||||
sql += " AND `created_at` >= '" + params.dateCreateBegin + " 00:00:00" + "' AND `created_at` <= '" + params.dateCreateEnd + " 23:59:59" +"' "
|
||||
sql += " AND `created_at` >= '" + params.dateCreateBegin + " 00:00:00" + "' AND `created_at` <= '" + params.dateCreateEnd + " 23:59:59" + "' "
|
||||
}
|
||||
if (params.dateClick) {
|
||||
var d = new Date();
|
||||
|
|
@ -391,8 +405,9 @@ db.getBookmarksCard = function(user_id) {
|
|||
}
|
||||
|
||||
db.getTagsBookmarks = function(bookmark_ids) {
|
||||
console.log('getTagsBookmarks');
|
||||
var sql = "SELECT * FROM `tags_bookmarks` WHERE bookmark_id in(" + bookmark_ids.toString() + ")"
|
||||
var sql = "SELECT * FROM `tags_bookmarks` WHERE bookmark_id in(" + (bookmark_ids.toString() || ("-1")) + ")"; // 如果是空的,那查一个不存在的就行了。
|
||||
console.log('getTagsBookmarks', sql);
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
client.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,15 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
|||
bookmarkService.clickBookmark({
|
||||
id: id
|
||||
});
|
||||
|
||||
if (params.showStyle != 'navigate') {
|
||||
$scope.bookmarks.forEach(function(bookmark) {
|
||||
if (bookmark.id == id) {
|
||||
bookmark.click_count += 1;
|
||||
bookmark.last_click = $filter("date")(new Date(), "yyyy-MM-dd");
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
$scope.toggleMode = function() {
|
||||
|
|
@ -58,7 +67,7 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
|||
toastr.warning('功能暂未实现。。。', "警告");
|
||||
}
|
||||
$scope.copyBookmark = function(bookmarkUrl) {
|
||||
toastr.warning(bookmarkUrl, "警告");
|
||||
toastr.warning('功能暂未实现。。。', "警告");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -84,8 +93,14 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
|||
if (params.showStyle != 'navigate') {
|
||||
$scope.bookmarks = data.bookmarks;
|
||||
$scope.totalPages = Math.ceil(data.totalItems / perPageItems);
|
||||
if (data.totalItems == 0) {
|
||||
toastr.info('您还没有书签,请点击菜单栏的添加按钮进行添加', "提示");
|
||||
}
|
||||
} else {
|
||||
$scope.bookmarks = data;
|
||||
if ($scope.bookmarks.length == 0) {
|
||||
toastr.info('您还没有书签,请点击菜单栏的添加按钮进行添加', "提示");
|
||||
}
|
||||
}
|
||||
pubSubService.publish('Common.menuActive', {
|
||||
login: true,
|
||||
|
|
@ -96,7 +111,10 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
|||
}
|
||||
|
||||
// TODO: 我要将编辑按钮固定在容器的右上角
|
||||
$(window).resize(function() {
|
||||
$(window).resize(updateEditPos);
|
||||
setTimeout(updateEditPos, 100);
|
||||
|
||||
function updateEditPos() {
|
||||
var top = $('.js-segment-navigate').offset().top;
|
||||
var left = $('.js-segment-navigate').offset().left;
|
||||
var width = $('.js-segment-navigate').width();
|
||||
|
|
@ -105,5 +123,5 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
|||
top: top + 10,
|
||||
left: left + width - 10,
|
||||
})
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ app.controller('loginCtr', ['$scope', '$filter', '$state', '$cookieStore', 'book
|
|||
$scope.showErr = false;
|
||||
$scope.errInfo = '';
|
||||
|
||||
$scope.emailRegister = "";
|
||||
$scope.usernameRegister = "";
|
||||
$scope.passwordRegister1 = "";
|
||||
$scope.passwordRegister2 = "";
|
||||
|
||||
|
||||
$scope.myKeyup = function(e) {
|
||||
var keycode = window.event ? e.keyCode : e.which;
|
||||
if (keycode == 13) {
|
||||
|
|
@ -22,7 +28,7 @@ app.controller('loginCtr', ['$scope', '$filter', '$state', '$cookieStore', 'book
|
|||
var autoLogin = $('.ui.checkbox.js-auto-login').checkbox('is checked');
|
||||
if (!$scope.username || !$scope.password) {
|
||||
$scope.showErr = true;
|
||||
$scope.errInfo = '用户明或者密码不能为空!';
|
||||
$scope.errInfo = '用户名或者密码不能为空!';
|
||||
} else {
|
||||
$scope.showErr = false;
|
||||
$scope.errInfo = '';
|
||||
|
|
@ -52,4 +58,55 @@ app.controller('loginCtr', ['$scope', '$filter', '$state', '$cookieStore', 'book
|
|||
.catch((err) => console.log('login err', err));
|
||||
}
|
||||
}
|
||||
|
||||
$scope.showRegister = function() {
|
||||
$('.ui.modal.js-register').modal({
|
||||
closable: false,
|
||||
}).modal('show');
|
||||
|
||||
$scope.emailRegister = "";
|
||||
$scope.usernameRegister = "";
|
||||
$scope.passwordRegister1 = "";
|
||||
$scope.passwordRegister2 = "";
|
||||
|
||||
}
|
||||
|
||||
$scope.register = function() {
|
||||
if (!$scope.emailRegister || !$scope.usernameRegister || !$scope.passwordRegister1 || !$scope.passwordRegister2) {
|
||||
toastr.error('有必填项为空', "错误");
|
||||
return;
|
||||
}
|
||||
if ($scope.passwordRegister1 !== $scope.passwordRegister2) {
|
||||
toastr.error('两次输入账号密码不一致', "错误");
|
||||
return;
|
||||
}
|
||||
if (!/([0-9a-zA-Z]){3,12}/.test($scope.usernameRegister)) {
|
||||
toastr.error('账号只能是数字字母,且长度必须为3到12位', "错误");
|
||||
return;
|
||||
}
|
||||
if (!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test($scope.emailRegister)) {
|
||||
toastr.error('邮箱格式输入有误', "错误");
|
||||
return;
|
||||
}
|
||||
|
||||
var user = {
|
||||
username: $scope.usernameRegister,
|
||||
email: $scope.emailRegister,
|
||||
password: $scope.passwordRegister1,
|
||||
};
|
||||
|
||||
bookmarkService.register(user)
|
||||
.then((data) => {
|
||||
if (data.retCode == 0) {
|
||||
toastr.success('注册成功', "提示");
|
||||
$('.ui.modal.js-register').modal('hide');
|
||||
} else {
|
||||
toastr.error('注册失败,您的账号或者邮箱可能已经存在了。错误信息:' + data.msg, "错误");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('register err', err);
|
||||
toastr.error('注册失败:' + JSON.stringify(err), "错误");
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
|
|
|||
|
|
@ -19,9 +19,6 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', 'pubSubService',
|
|||
}, {
|
||||
uiSref: 'tags',
|
||||
title: '书签分类'
|
||||
}, {
|
||||
uiSref: 'advice',
|
||||
title: '建议'
|
||||
}, {
|
||||
uiSref: 'settings',
|
||||
title: '设置'
|
||||
|
|
|
|||
|
|
@ -50,6 +50,12 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
|||
bookmarkService.clickBookmark({
|
||||
id: id
|
||||
});
|
||||
$scope.bookmarks.forEach(function(bookmark) {
|
||||
if (bookmark.id == id) {
|
||||
bookmark.click_count += 1;
|
||||
bookmark.last_click = $filter("date")(new Date(), "yyyy-MM-dd");
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +83,10 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
|||
toastr.warning('功能暂未实现。。。', "警告");
|
||||
}
|
||||
|
||||
$scope.copyBookmark = function(bookmarkUrl) {
|
||||
toastr.warning('功能暂未实现。。。', "警告");
|
||||
}
|
||||
|
||||
$scope.search = function() {
|
||||
var params = {}
|
||||
params.userRange = $('.js-user-range').dropdown('get value');
|
||||
|
|
|
|||
|
|
@ -66,6 +66,12 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', 'book
|
|||
bookmarkService.clickBookmark({
|
||||
id: id
|
||||
});
|
||||
$scope.bookmarks.forEach(function(bookmark) {
|
||||
if (bookmark.id == id) {
|
||||
bookmark.click_count += 1;
|
||||
bookmark.last_click = $filter("date")(new Date(), "yyyy-MM-dd");
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,10 +99,15 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', 'book
|
|||
toastr.warning('功能暂未实现。。。', "警告");
|
||||
}
|
||||
|
||||
$scope.copyBookmark = function(bookmarkUrl) {
|
||||
toastr.warning('功能暂未实现。。。', "警告");
|
||||
}
|
||||
|
||||
function getTags(params) {
|
||||
bookmarkService.getTags(params)
|
||||
.then((data) => {
|
||||
$scope.tags = data
|
||||
|
||||
if (!$scope.currentTagId && $scope.tags.length > 0) {
|
||||
$scope.currentTagId = $scope.tags[0].id;
|
||||
$scope.tags[0].bookmarkClicked = true;
|
||||
|
|
@ -104,6 +115,8 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', 'book
|
|||
|
||||
if ($scope.currentTagId) {
|
||||
$scope.getBookmarks($scope.currentTagId, 1);
|
||||
} else {
|
||||
toastr.info('您还没有书签分类,请点击菜单栏的添加按钮进行添加', "提示");
|
||||
}
|
||||
})
|
||||
.catch((err) => console.log('getTags err', err));
|
||||
|
|
|
|||
|
|
@ -27,6 +27,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
|
|||
});
|
||||
return def.promise;
|
||||
},
|
||||
register: function(params) {
|
||||
var def = $q.defer();
|
||||
$http.post('/api/register/', {
|
||||
params: params
|
||||
})
|
||||
.success(function(data) {
|
||||
def.resolve(data);
|
||||
})
|
||||
.error(function(data) {
|
||||
def.reject('register error');
|
||||
});
|
||||
return def.promise;
|
||||
},
|
||||
clickBookmark: function(params) {
|
||||
var def = $q.defer();
|
||||
$http.post('/api/clickBookmark/', {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<div class="required field">
|
||||
<label>用户名</label>
|
||||
<div class="ui icon input">
|
||||
<input type="text" ng-model="username">
|
||||
<input type="text" ng-model="username" ng-keyup="myKeyup($event)">
|
||||
<i class="user icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -24,5 +24,40 @@
|
|||
<label>30天内自动登陆</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui submit button" ng-click="login()">登陆</div>
|
||||
<div class="field">
|
||||
<div class="ui submit button" ng-click="login()">登陆</div>
|
||||
<span>
|
||||
<div style="margin-top:20px;float:right;">没有账号?<a herf="#" ng-click="showRegister()">注册一个!</a>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
<div class="ui modal js-register">
|
||||
<div class="header">
|
||||
账号注册
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="ui form">
|
||||
<div class="required field">
|
||||
<label>邮箱</label>
|
||||
<input type="text" placeholder="" ng-model="emailRegister">
|
||||
</div>
|
||||
<div class="required field">
|
||||
<label>用户名</label>
|
||||
<input type="text" placeholder="只允许大小写字母数字,至少3位" ng-model="usernameRegister">
|
||||
</div>
|
||||
<div class="required field">
|
||||
<label>密码</label>
|
||||
<input type="password" placeholder="" ng-model="passwordRegister1">
|
||||
</div>
|
||||
<div class="required field">
|
||||
<label>确认密码</label>
|
||||
<input type="password" placeholder="" ng-model="passwordRegister2">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui cancel button">取消</div>
|
||||
<div class="ui green button" ng-click="register()">注册</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -145,9 +145,10 @@
|
|||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 5px" ng-src="./images/delete.png" ng-click="delBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 5px" ng-src="./images/edit-bookmark.png" ng-click="editBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 5px" ng-src="./images/detail.png" ng-click="detailBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/delete.png" ng-click="delBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/edit-bookmark.png" ng-click="editBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/detail.png" ng-click="detailBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/copy.png" ng-click="copyBookmark(bookmark.url)" title="复制链接">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<div class="two wide column" ng-class="" ng-mouseover="" ng-mouseleave="" ng-repeat="tag in tags">
|
||||
<div class="ui small label" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
|
||||
{{ tag.name }}
|
||||
({{ tag.cnt }})
|
||||
({{ tag.cnt || 0 }})
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -45,9 +45,10 @@
|
|||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 5px" ng-src="./images/delete.png" ng-click="delBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 5px" ng-src="./images/edit-bookmark.png" ng-click="editBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 5px" ng-src="./images/detail.png" ng-click="detailBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/delete.png" ng-click="delBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/edit-bookmark.png" ng-click="editBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/detail.png" ng-click="detailBookmark(bookmark.id)">
|
||||
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/copy.png" ng-click="copyBookmark(bookmark.url)" title="复制链接">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -46,6 +46,27 @@ api.post('/login', function(req, res) {
|
|||
.catch((err) => console.log('login error', err));
|
||||
});
|
||||
|
||||
api.post('/register', function(req, res) {
|
||||
var params = req.body.params;
|
||||
params.password = md5(params.password); // 进行密码加密
|
||||
|
||||
db.register(params)
|
||||
.then((affectedRows) => {
|
||||
res.json({
|
||||
retCode: 0,
|
||||
msg: params.username + " 注册成功 ",
|
||||
})
|
||||
console.log('register affectedRows ', affectedRows)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('login error', err);
|
||||
res.json({
|
||||
retCode: 1,
|
||||
msg: params.username + " 注册失败: " + JSON.stringify(err),
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
api.get('/autoLogin', function(req, res) {
|
||||
var ret = {
|
||||
logined: false,
|
||||
|
|
@ -161,7 +182,9 @@ api.get('/bookmarks', function(req, res) {
|
|||
tag.bookmarks = [];
|
||||
}
|
||||
tag.click += bookmark.click_count;
|
||||
tag.bookmarks.push(bookmark);
|
||||
if (bookmark.id) {
|
||||
tag.bookmarks.push(bookmark);
|
||||
}
|
||||
});
|
||||
if (result && result.length > 0) {
|
||||
data.push(tag);
|
||||
|
|
|
|||
Loading…
Reference in New Issue