登录登出功能完成,前后流程走通

This commit is contained in:
Yang Zhao 2016-12-27 14:44:50 +00:00
parent 4748bd0d92
commit 7f03659a30
139 changed files with 80 additions and 40 deletions

View File

@ -2,14 +2,16 @@ class SessionsController < ApplicationController
# 除登录之外,其余接口必须在登录状态下访问
before_action :authenticate, except: [ :create ]
skip_before_action :verify_authenticity_token, :only => [:create,:destroy,:show]
def create
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
render status: :ok, text: 'login success'
render status: :ok, text: 'ok'
else
render status: :ok, text: 'account or password is not correct'
render status: :unauthorized, text: 'account or password is not correct'
end
end

View File

@ -5,3 +5,10 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
users = [
{:name => '杨诏', :password => '123123123', :email => 'lucio.yang@qq.com', :phone => '15652591529', :created_at => "2016/12/27", :updated_at => "2016/12/27"}
]
users.each do |user|
User.create!(user)
end

View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 121 KiB

View File

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View File

Before

Width:  |  Height:  |  Size: 184 B

After

Width:  |  Height:  |  Size: 184 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 81 KiB

View File

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 112 KiB

View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

@ -84,15 +84,17 @@
<!-- The user image in the navbar-->
<img src="dist/img/avatar5.png" class="user-image" alt="User Image">
<!-- hidden-xs hides the username on small devices so only the image appears. -->
<span>杨诏</span>
<span id="name1">xx</span>
</a>
<ul class="dropdown-menu">
<!-- The user image in the menu -->
<li class="user-header">
<img src="dist/img/avatar5.png" class="img-circle" alt="User Image">
<p>
杨诏
<small>2016年加入</small>
<span id="name2">xx<span>
</p>
<p>
<span id="created_at">xxxx年xx月xx日加入<span>
</p>
</li>
<!-- Menu Footer-->
@ -101,7 +103,7 @@
<a href="#" class="btn btn-primary btn-flat" onclick="change_iframe(4,$(this));return false;">修改信息</a>
</div>
<div class="pull-right">
<a href="#" class="btn btn-danger btn-flat">登出</a>
<a href="#" class="btn btn-danger btn-flat" onclick="logout();return false;">登出</a>
</div>
</li>
</ul>
@ -158,6 +160,39 @@
<script src="dist/js/app.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<script>
$(document).ready(function(){
$.ajax({
type: "get",
dataType: "json",
url:"/session.json",
statusCode: {
200: function(data) {// 请求成功
$("#name1").text(data.name);
$("#name2").text(data.name);
$("#created_at").text(data.created_at.substr(0,10)+"加入");
},
401:function(){// 未授权
alert("未登录!");
window.location.href="pages/login.html";
}
}
});
});
function logout(){
$.ajax({
type: "delete",
dataType: "json",
url:"/session.json",
success:function(){
window.location.href="pages/login.html"
},
error:function(){
window.location.href="pages/login.html"
}
});
}
</script>
</body>
</html>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>DataInsight-数据挖掘可视化平</title>
<title>Ambition-敏捷开发项目管理工具</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Font Awesome -->

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title></title>
<title>Ambition-敏捷开发项目管理工具</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Font Awesome -->

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>DataInsight-数据挖掘可视化平台</title>
<title>Ambition-敏捷开发项目管理工具</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Font Awesome -->

View File

@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>DataInsight-数据挖掘可视化平台</title>
<title>Ambition-敏捷开发项目管理工具</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
@ -26,15 +26,15 @@
<div class="login-box">
<div class="row"> </div>
<div class="login-logo">
<img src="../dist/img/logo1.png" class="img-round"></img>
<span class="logo-lg"><b>Ambition</b></span>
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">请登录</p>
<form id="FormLogin">
<!--<form id="FormLogin">-->
<div class="form-group has-feedback">
<input id="username" type="name" name="username" class="form-control" placeholder="id">
<input id="email" type="name" name="email" class="form-control" placeholder="id">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
@ -44,11 +44,11 @@
<div class="row">
<!-- /.col -->
<div class="col-md-2 col-md-offset-9">
<button id="login" class="btn btn-success">开始</button>
<button id="login" class="btn btn-success">登录</button>
</div>
<!-- /.col -->
</div>
</form>
<!--</form>-->
<!-- 忘记密码 -->
<a href="#" data-toggle="modal" data-target="#myModal">忘记密码</a>
<br/>
@ -92,30 +92,26 @@
<script>
$(document).ready(function(){
$("#login").click(function(){
//alert("666");
if( $("#username").val().length>0 && $("#password").val().length>0 ){
//alert("666");
if( $("#email").val().length>0 && $("#password").val().length>0 ){
//alert($('#FormLogin').serialize());
$.ajax({
type: "get",
dataType: "text",
url:"LoginAction.action",
data: $('#FormLogin').serialize(),
success: function (msg) {
var json_str=eval("("+msg+")");
//alert(json_str.result);
var flag=json_str.result;
//alert(flag);
if( flag==true )//登录成功
window.location.href="../index.jsp";
else
alert("输入有误!请修改");
},
error: function(data) {
alert("error:"+data.responseText);
alert("网络有问题");
//document.getElementById("error").innerHTML="error:"+data.responseText;
}
});
$.ajax({
type: "post",
dataType: "json",
url:"/sessions.json",
data: {
"email":$("#email").val(),
"password":$("#password").val()
},
statusCode: {
200: function() {// 请求成功
window.location.href="../index.html";
},
401:function(){// 未授权
alert("用户名或密码错误!");
}
}
});
}
else{
alert("请输入完整!");

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title></title>
<title>Ambition-敏捷开发项目管理工具</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Font Awesome -->

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title></title>
<title>Ambition-敏捷开发项目管理工具</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Font Awesome -->

Some files were not shown because too many files have changed in this diff Show More