本地用户优化, 登录优化

登录只需要user表启动
This commit is contained in:
life
2015-09-23 23:14:36 +08:00
parent 033030d506
commit 6c89ef2fc8
9 changed files with 147 additions and 277 deletions

View File

@@ -44,8 +44,10 @@ if(process.platform != 'darwin') {
<span class="lang localAccount">Create Local Account</span>
</h1>
<!-- 信息 -->
<div class="alert alert-danger" id="loginMsg"></div>
<div class="alert-wrap">
<!-- 信息 -->
<div class="alert alert-danger" id="loginMsg"></div>
</div>
<!-- 创建本地用户 -->
<div class="boxForm local-form">
@@ -59,7 +61,10 @@ if(process.platform != 'darwin') {
</div>
<div class="form-group pwd-group">
<input type="password" required placeholder="Confirm password" class="form-control lang-placeholder" id="pwd2" name="pwd2">
<button id="regBtn" class="btn-embeded" disabled><i class="fa fa-arrow-right"></i></button>
<button id="regBtn" class="btn-embeded" disabled>
<i class="btn-go fa fa-arrow-right"></i>
<i class="btn-loading"><img src="public/images/loading-24.gif"/></i>
</button>
</div>
</div>
</form>
@@ -78,7 +83,10 @@ if(process.platform != 'darwin') {
</div>
<div class="form-group pwd-group">
<input type="password" placeholder="Password" class="form-control lang-placeholder" id="pwd" name="pwd">
<button id="loginBtn" class="btn-embeded" disabled><i class="fa fa-arrow-right"></i></button>
<button id="loginBtn" class="btn-embeded" disabled>
<i class="btn-go fa fa-arrow-right"></i>
<i class="btn-loading"><img src="public/images/loading-24.gif"/></i>
</button>
</div>
</div>
@@ -138,6 +146,9 @@ $(function() {
var $email = $("#email");
var $host = $('#host');
var $body = $('body');
$("#loginBtn").click(function(e) {
e.preventDefault();
var email = $email.val();
@@ -161,7 +172,7 @@ $(function() {
showMsg(getMsg('Invalid host'), 'host');
return;
}
$('#loadingLogo').addClass('loading');
$body.addClass('loading');
hideMsg();
// TODO show loading
// console.log(33);
@@ -172,7 +183,7 @@ $(function() {
UserService.login(email, pwd, function(ret) {
if (ret) {
setTimeout(function(){
$('#loadingLogo').removeClass('loading');
$body.removeClass('loading');
goToMainPage();
gui.getCurrentWindow().close();
}, 2000);
@@ -181,12 +192,12 @@ $(function() {
ApiService.auth(email, pwd, host, function(ret) {
if(ret.Ok) {
setTimeout(function(){
$('#loadingLogo').removeClass('loading');
$body.removeClass('loading');
goToMainPage();
gui.getCurrentWindow().close();
}, 2000);
} else {
$('#loadingLogo').removeClass('loading');
$body.removeClass('loading');
showMsg(getMsg("Email or Password Error"));
}
});
@@ -214,7 +225,7 @@ $(function() {
return;
}
}
$('#loadingLogo').addClass('loading');
$body.addClass('loading');
hideMsg();
var user = {};
user.Username = username;
@@ -225,13 +236,13 @@ $(function() {
dbuser.UserId = dbuser._id;
UserService.saveCurUser(dbuser, function() {
setTimeout(function(){
$('#loadingLogo').removeClass('loading');
$body.removeClass('loading');
goToMainPage();
gui.getCurrentWindow().close();
}, 2000);
})
} else {
$('#loadingLogo').removeClass('loading');
$body.removeClass('loading');
showMsg(getMsg(dbuser));
}
});
@@ -269,9 +280,6 @@ $(function() {
checkDisabled();
});
});
var $body = $('body');
$('#customServer').click(function() {
$body.addClass('custom-server');
$host.focus();
@@ -290,12 +298,6 @@ $(function() {
$email.focus();
hideMsg();
});
// setTimeout(function () {
// var s = $('<script>');
// s.attr('src', 'public/js/app/service_login.js');
// $body.append(s);
// }, 1000);
});
// win.resizeTo(268, 356);

53
src/node_modules/db.js generated vendored
View File

@@ -14,19 +14,46 @@ if(dbPath.length < 6) {
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb2';
}
// 加载DB, 为noteHistories
Datastore.prototype.loadDB = function(callback) {
var me = this;
if (this.__loaded) {
callback();
} else {
this.loadDatabase(function (err) {
me.__loaded = true;
callback(err);
});
}
};
// console.log(dbPath);
// g, 表全局环境
var db = {};
var dbNames = ['users', 'notebooks', 'notes', 'tags', 'images', 'attachs', 'noteHistories', 'g'];
for(var i in dbNames) {
var name = dbNames[i];
var p = path.join(dbPath, name + '.db');
(function (name) {
// 这部分非常慢!, 会卡界面
db[name] = new Datastore({ filename: p, autoload: true , onload: function () {
console.log(name + ' is loaded');
}});
})(name);
}
var db = {
init: function () {
var dbNames = ['users', 'notebooks', 'notes', 'tags', 'images', 'attachs', 'noteHistories', 'g'];
this._init(dbNames);
},
initForLogin: function () {
var dbNames = ['users'];
this._init(dbNames);
},
_init: function (dbNames) {
var me = this;
for(var i in dbNames) {
var name = dbNames[i];
var p = path.join(dbPath, name + '.db');
(function (name) {
// 这部分非常慢!, 会卡界面
me[name] = new Datastore({ filename: p, autoload: name != 'noteHistories' , onload: function () {
console.log(name + ' is loaded');
}});
})(name);
}
console.log('db inited');
}
};
module.exports = db;
console.log('db inited');

48
src/node_modules/note.js generated vendored
View File

@@ -187,34 +187,38 @@ var Note = {
*/
addNoteHistory: function(noteId, content) {
var me = this;
// 先判断是否存在, 不存在则新建之
db.noteHistories.findOne({_id: noteId}, function(err, history) {
// 新建之
if(!history) {
db.noteHistories.insert({_id: noteId, Histories: [content], "UpdatedTime": new Date()});
}
// 更新之
else {
var histories = history.Histories;
histories.push(content);
db.noteHistories.update({_id: noteId}, {$set: {Histories: histories, "UpdatedTime": new Date()}});
}
db.noteHistories.loadDB(function () {
// 先判断是否存在, 不存在则新建之
db.noteHistories.findOne({_id: noteId}, function(err, history) {
// 新建之
if(!history) {
db.noteHistories.insert({_id: noteId, Histories: [content], "UpdatedTime": new Date()});
}
// 更新之
else {
var histories = history.Histories;
histories.push(content);
db.noteHistories.update({_id: noteId}, {$set: {Histories: histories, "UpdatedTime": new Date()}});
}
});
});
},
// 获取笔记历史记录
getNoteHistories: function(noteId, callback) {
var me = this;
db.noteHistories.findOne({_id: noteId}, function(err, doc) {
if(err || !doc) {
callback(false);
}
else {
var histories = [];
for(var i = doc.Histories.length - 1; i >= 0; --i) {
histories.push({Content: doc.Histories[i], UpdatedTime: doc.UpdatedTime || new Date()});
db.noteHistories.loadDB(function () {
db.noteHistories.findOne({_id: noteId}, function(err, doc) {
if(err || !doc) {
callback(false);
}
callback(histories);
}
else {
var histories = [];
for(var i = doc.Histories.length - 1; i >= 0; --i) {
histories.push({Content: doc.Histories[i], UpdatedTime: doc.UpdatedTime || new Date()});
}
callback(histories);
}
});
});
},

View File

@@ -93,114 +93,10 @@ a {
a:hover {
text-decoration: none !important;
}
#headerContainer {
background-color: #fff;
-webkit-box-shadow: 1px 1px 8px -1px rgba(0, 0, 0, 0.1);
box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.1);
margin: 0;
}
#headerContainer .navbar-brand {
padding: 0;
padding-left: 10px;
line-height: 60px;
}
#headerContainer .navbar-brand img {
height: 50px;
display: inline-block;
margin-top: -5px;
}
#headerContainer .navbar-nav a {
line-height: 60px;
padding: 0 10px;
}
#postsContainer,
#suggestion {
background: #f5f5f5 url("../images/noise.png");
}
#postsContainer {
margin-top: 60px;
}
section {
color: #e2f3e5;
margin-top: 60px;
}
.header {
text-align: center;
padding: 30px;
}
.header p {
color: #d0ebd6;
font-size: 16px;
}
.header .btn {
padding: 10px 16px;
font-size: 14px;
font-size: 18px;
line-height: 1.33;
border-radius: 2px;
margin: 20px 0;
}
.header .btn-primary {
background-color: #25313e;
border-color: #1f2a34;
}
.header h2 {
font-size: 32px;
color: #fff;
}
.preview {
margin: auto;
width: 850px;
text-align: center;
overflow: hidden;
}
.preview .img-header {
height: 40px;
width: 750px;
margin: auto;
border-radius: 5px 5px 0 0;
text-align: left;
background-color: #F4F4F4;
}
.preview .img-header img {
box-shadow: none;
margin: 10px;
width: 50px;
}
.preview .mobile {
position: absolute;
bottom: -80px;
right: 0;
}
.preview .mobile .mobile-header {
padding: 8px 15px;
border-radius: 14px 14px 0 0;
text-align: center;
background-color: #2e3e4e;
}
.preview .mobile .mobile-header img {
width: 30px;
}
.preview .mobile img {
border: 3px solid #2e3e4e;
border-bottom: 0;
width: 200px;
}
/* header */
#header {
color: #000000;
position: relative;
background-color: #fff;
}
#header h1 {
margin: 0;
padding: 0;
line-height: 45px;
}
#navbar {
float: right;
background: #fff;
}
#loginBtns {
border-left: 1px solid #eee;
border-color: rgba(200, 200, 200, 0.5);
@@ -777,8 +673,14 @@ btns {
form {
position: relative;
}
.alert-wrap {
position: relative;
}
#loginMsg {
margin: auto;
position: absolute;
top: -25px;
left: 0;
right: 0;
padding: 0;
padding-bottom: 5px;
text-align: center;
@@ -904,3 +806,12 @@ body {
.drag {
left: 50px;
}
.btn-loading {
display: none;
}
body.loading .btn-go {
display: none;
}
body.loading .btn-loading {
display: inline;
}

View File

@@ -69,124 +69,12 @@ a:hover {
text-decoration: none !important;
// color: @aBlackColor;
}
@headerHeight: 60px;
#headerContainer {
// height: @headerHeight;
background-color: #fff;
-webkit-box-shadow: 1px 1px 8px -1px rgba(0, 0, 0, 0.1);
box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.1);
margin: 0;
.navbar-brand {
padding: 0;
padding-left: 10px;
line-height: @headerHeight;
img {
height: 50px;
display: inline-block;
margin-top: -5px;
}
}
.navbar-nav a {
line-height: @headerHeight;
padding: 0 10px;
}
}
#header, #posts, #loginContainer {
}
#postsContainer, #suggestion {
background: #f5f5f5 url("../images/noise.png");
}
#postsContainer {
margin-top: @headerHeight;
}
section {
// background-color: #fff;
color: #e2f3e5;
margin-top: @headerHeight;
}
.header {
text-align: center;
padding: 30px;
p {
color: rgb(208, 235, 214);
font-size: 16px;
}
.btn {
padding: 10px 16px;
font-size: 14px;
font-size: 18px;
line-height: 1.33;
border-radius: 2px;
margin: 20px 0;
}
.btn-primary {
background-color: #25313e;
border-color: #1f2a34;
}
.btn-default {
}
h2 {
font-size: 32px;
color: #fff;
}
}
.preview {
margin: auto;
width: 850px;
text-align: center;
overflow: hidden;
img {
// box-shadow: -15px 10px 0 rgba(0, 0, 0, 0.15);
}
.img-header {
height: 40px;
width: 750px;
margin: auto;
border-radius: 5px 5px 0 0;
text-align: left;
background-color: #F4F4F4;
img {
box-shadow: none;
margin: 10px;
width: 50px;
}
}
.mobile {
position: absolute; bottom: -80px; right: 0;
.mobile-header {
padding: 8px 15px;
border-radius: 14px 14px 0 0;
text-align: center;
background-color: rgb(46, 62, 78);
img {
width: 30px;
}
}
img {
border: 3px solid rgb(46, 62, 78);
border-bottom: 0;
width: 200px;
}
}
}
/* header */
#header {
color: #000000;
position: relative;
h1 {
margin: 0;
padding: 0;
line-height: 45px;
}
background-color: #fff;
}
#navbar {
float: right;
background: #fff;
}
#loginBtns {
border-left: 1px solid #eee;
@@ -854,9 +742,14 @@ body {
form {
position: relative;
}
.alert-wrap {
position: relative;
}
#loginMsg {
//position: absolute;
margin: auto;
position: absolute;
top: -25px;
left: 0;
right: 0;
padding: 0;
padding-bottom: 5px;
text-align: center;
@@ -945,3 +838,16 @@ html, body {
.drag {
left: 50px;
}
.btn-loading {
display: none;
}
body.loading {
.btn-go {
display: none;
}
.btn-loading {
display: inline;
}
}

View File

@@ -11,6 +11,9 @@ if(!/login.html/.test(location.href)) {
Server.start();
}
var db = require('db');
db.init();
// 所有service, 与数据库打交道
var Service = {
notebookService: require('notebook'),

View File

@@ -11,6 +11,9 @@ var Service = {
apiService: require('api'),
};
var db = require('db');
db.initForLogin();
// 全局变量
var ApiService = Service.apiService;
var UserService = Service.userService;

View File

@@ -268,6 +268,13 @@
"Invalid host": "服务地址错误",
"Leanote login": "登录",
"Email is required": "请输入用户名或邮箱",
"Password is required": "请输入密码"
"Password is required": "请输入密码",
"The minimum password length is 6": "密码长度最少6位",
"Self-hosted Service": "自建服务",
"Create Local Account": "创建本地帐户",
"Sign in to Leanote": "登录到Leanote",
"Confirm password": "确认密码",
"Username": "用户名"
}

View File

@@ -268,6 +268,13 @@
"Invalid host": "服務地址錯誤",
"Leanote login": "登錄",
"Email is required": "請輸入用戶名或郵箱",
"Password is required": "請輸入密碼"
"Password is required": "請輸入密碼",
"The minimum password length is 6": "密碼長度最少6位",
"Self-hosted Service": "自建服務",
"Create Local Account": "創建本地帳戶",
"Sign in to Leanote": "登錄到Leanote",
"Confirm password": "確認密碼",
"Username": "用户名"
}