Skip to content

Commit

Permalink
完成登录模块
Browse files Browse the repository at this point in the history
  • Loading branch information
hauk0101 committed Aug 28, 2017
1 parent db84276 commit 27b0c93
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ app.all('*', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
//设置session
//设置session,设置为1天有效
app.use(session({
name:'video-hls-encrypt',
secret:'encrypt',
cookie:{
maxAge:10 * 1000
maxAge:1000 * 60 * 60 * 24
}
}));
//静态资源访问限制,
Expand Down
57 changes: 40 additions & 17 deletions app/views/login.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@
var login_submit = document.getElementById('login-submit');
var login_goon = document.getElementById('login-goon');
var login_tip = document.getElementById('login-tip');
if(login_data.value != ""){
setClickable(login_username,false);
setClickable(login_password,false);
setClickable(login_submit,false);
login_tip.innerHTML='登录状态:已登录!';
setClickable(login_goon,true);
if(login_data.value !=""){
isLogined(true);
}else{
setClickable(login_username,true);
setClickable(login_password,true);
setClickable(login_submit,true);
login_tip.innerHTML='登录状态:未登录!';
setClickable(login_goon,false);
isLogined(false);
}
eventBind(login_goon,'click',function(){
window.location.href='/index';
});
Expand All @@ -61,16 +55,45 @@
password:login_password.value
};
//TODO
// ajax({
// url:'/login',
// type:'post',
// data:data,
//
// });
ajax({
url:'/login',
type:'post',
data:data,
dataType:'json',
success:function(data){
if(data){
data = JSON.parse(data);
if(data.code == 0){
isLogined(true);
}
}else{
isLogined(false);
}
},
fail:function(){
}
});
}else{
alert('账号或密码不能为空!');
}
});
function isLogined(bool){
if(bool){
setClickable(login_username,false);
setClickable(login_password,false);
setClickable(login_submit,false);
login_tip.innerHTML='登录状态:已登录!';
setClickable(login_goon,true);
}else{
setClickable(login_username,true);
setClickable(login_password,true);
setClickable(login_submit,true);
login_tip.innerHTML='登录状态:未登录!';
setClickable(login_goon,false);
}
}
</script>
</html>

0 comments on commit 27b0c93

Please sign in to comment.