Skip to content

Commit 157bcc3

Browse files
committed
登陆
1 parent c3d3f11 commit 157bcc3

File tree

11 files changed

+50
-46
lines changed

11 files changed

+50
-46
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
6868
**访问网站:**
6969

70-
-http://localhost:3000/ 访问为使用ejs的nodejs模板,使用angularjs作为数据绑定用,由于这是第一次在复杂项目中使用angularjs,所以没有使用好angularjs,文档非常烂。
70+
- http://localhost:3000/ 访问为使用ejs的nodejs模板,使用angularjs作为数据绑定用,由于这是第一次在复杂项目中使用angularjs,所以没有使用好angularjs,文档非常烂。
7171

72-
-http://localhost:3000/app/app.html 是对前端使用angularjs的一个重新规划,目前正在学习angularjs重构中
72+
- http://localhost:3000/app/app.html 是对前端使用angularjs的一个重新规划,目前正在学习angularjs重构中
7373

7474

7575

7676

7777
**备注:**
78-
-由于第一次正式尝试angularjs,所以没有用好,仅仅用上了数据绑定的功能,这个项目如果用angularjs做前端的话,其实做单页更加好,这样可以省掉后端的ejs模板。
79-
-下一步重构可以考虑合并为单页模式。
80-
-另外angularjs的每个控制模块太大,里面包含功能太多,也需要拆分。
78+
- 由于第一次正式尝试angularjs,所以没有用好,仅仅用上了数据绑定的功能,这个项目如果用angularjs做前端的话,其实做单页更加好,这样可以省掉后端的ejs模板。
79+
- 下一步重构可以考虑合并为单页模式。
80+
- 另外angularjs的每个控制模块太大,里面包含功能太多,也需要拆分。

public/app/app.html

+1
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@
9999

100100

101101
<script src="js/app/controllers.js"></script>
102+
<script src="js/app/login.js"></script>
102103
</body>
103104
</html>

public/app/login.html

+9-24
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
</ol>
1111
<div class="carousel-inner">
1212
<div class="item active">
13-
<img src="images/3.jpg">
13+
<img src="images/1.png">
1414
</div>
1515
<div class="item">
16-
<img src="images/3.jpg">
16+
<img src="images/1.png">
1717
</div>
1818
<div class="item">
19-
<img src="images/3.jpg">
19+
<img src="images/1.png">
2020
</div>
2121
</div>
2222
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
@@ -31,15 +31,15 @@
3131

3232
<div class="col-md-3">
3333

34-
<!-- <div class="small red"><%= locals.error %> </div> -->
34+
<div class="small red" ng-show="errorShow">{{ error }}</div>
3535

36-
<form role="form" id="login" action="/login" method="post" ng-show="{{formShow}}">
36+
<form role="form" id="login" ng-submit="loginIn()" ng-show="formShow">
3737
<h3>用户登录</h3>
3838
<div class="form-group">
39-
<input type="text" name="name" class="form-control" placeholder="用户名">
39+
<input type="text" name="name" class="form-control" placeholder="用户名" ng-model="name" />
4040
</div>
4141
<div class="form-group">
42-
<input type="password" name="password" class="form-control" placeholder="密码">
42+
<input type="password" name="password" class="form-control" placeholder="密码" ng-model="password" />
4343
</div>
4444
<div class="row">
4545
<div class="col-md-5 small">
@@ -53,7 +53,7 @@ <h3>用户登录</h3>
5353
<p class="text-primary small point" id="changeSign" ng-click="toggle()">没有账户,点击注册</p>
5454
</form>
5555

56-
<form role="form" id="sign" action="/sign" method="post" ng-hide="{{formShow}}">
56+
<form role="form" id="sign" action="/sign" method="post" ng-hide="formShow">
5757
<h3>用户注册</h3>
5858

5959
<div class="form-group">
@@ -90,19 +90,4 @@ <h4>热门</h4>
9090
<div class="col-md-4">
9191
<h4>新闻</h4>
9292
</div>
93-
</div>
94-
95-
<script>
96-
// $("#changeSign").on("click",function(){
97-
// $("#login").hide();
98-
// $("#sign").show();
99-
// });
100-
// $("#changeLogin").on("click",function(){
101-
// $("#sign").hide();
102-
// $("#login").show();
103-
// });
104-
105-
// $('.carousel').carousel({
106-
// interval: 8000
107-
// })
108-
</script>
93+
</div>

public/images/1.jpg

-27.9 KB
Binary file not shown.

public/images/1.png

251 KB
Loading

public/images/2.jpg

-826 KB
Binary file not shown.

public/images/3.jpg

-18.4 KB
Binary file not shown.

public/js/app/controllers.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var ngRoute=angular.module('ngView', ['ngRoute']);
1+
var app=angular.module('ngView', ['ngRoute']);
22

3-
ngRoute.config(function($routeProvider) {
3+
app.config(function($routeProvider) {
44
$routeProvider.when('/index', {
55
templateUrl: 'app/index.html'
66
});
@@ -20,21 +20,17 @@ ngRoute.config(function($routeProvider) {
2020
});
2121
});
2222

23+
// app.controller('ngView', function ($scope, $http) {
24+
// $scope.resetLogin=function(){
25+
// alert(1);
26+
// }
27+
// })
28+
2329
function IndexCtrl($scope, $http, $templateCache) {
2430

2531
}
2632

27-
function loginCtrl($scope, $http, $templateCache){
28-
$scope.formShow=true;
29-
$scope.toggle=function(){
30-
if($scope.formShow==true){
31-
$scope.formShow=false;
32-
}else{
33-
$scope.formShow=true;
34-
}
35-
36-
}
37-
}
33+
3834

3935
function settingCtrl($scope, $routeParams) {
4036
$scope.name = $routeParams.name;

public/js/app/login.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function loginCtrl($scope, $http, $location){
2+
$scope.formShow=true;
3+
$scope.errorShow=false;
4+
$scope.toggle=function(){
5+
$scope.formShow=$scope.formShow==true?false:true;
6+
}
7+
$scope.loginIn=function(){
8+
if(this.name&&this.password){
9+
$http.post("/loginAjax", {name:this.name,password:this.password}).success(function(data,status){
10+
if(data.ok){
11+
// $scope.$parent.resetLogin();
12+
//http://blog.jobbole.com/54817/
13+
$location.path("/index");
14+
}else{
15+
$scope.errorShow=true;
16+
$scope.error=data.message
17+
}
18+
});
19+
}
20+
21+
}
22+
}

routes/login.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ login.login=function(req,res){
7171
if(user){
7272
//如果存在,就返回用户的所有信息,取出password来和post过来的password比较
7373
if(user.password != password){
74-
req.flash('error','密码不正确');
74+
req.flash('error','密码不正确');
7575
res.redirect('/login');
7676
}else{
7777
req.session.user = user;

views/login.ejs

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@
7272
</ol>
7373
<div class="carousel-inner">
7474
<div class="item active">
75-
<img src="images/3.jpg">
75+
<img src="images/1.png">
7676
</div>
7777
<div class="item">
78-
<img src="images/3.jpg">
78+
<img src="images/1.png">
7979
</div>
8080
<div class="item">
81-
<img src="images/3.jpg">
81+
<img src="images/1.png">
8282
</div>
8383
</div>
8484
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">

0 commit comments

Comments
 (0)