-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprac7.js
executable file
·79 lines (79 loc) · 2.53 KB
/
prac7.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var app = angular.module('app', []);
app.controller('PostsCtrl', function ($scope) {
$scope.addPost = function () {
if ($scope.title) {
$scope.posts.unshift({
username:$scope.username,
title:$scope.title,
comment:$scope.comment,
})
console.log("username = "+$scope.username)
console.log("title = "+$scope.title);
$scope.title = null;
$scope.comment = null;
console.log($scope.posts);
$scope.message = null;
}
else{
$scope.message = "Please enter title"
}
}
$scope.deletepost = function(post) {
var index = $scope.posts.indexOf(post);
$scope.posts.splice(index, 1);
}
$scope.notlogged = true;
$scope.login = function(){
for(u in $scope.users){
console.log($scope.users[u].username);
if($scope.users[u].username == $scope.username && $scope.users[u].password==$scope.password){
$scope.notlogged = false;
return
}
}
$scope.message = "incorrect password or username"
}
$scope.logout = function(){
$scope.notlogged = true;
$scope.username = null;
$scope.password = null;
$scope.message = null;
}
$scope.searchbar = true;
$scope.search = function(){
$scope.searchbar = false;
}
$scope.register = function(){
for(u in $scope.users){
if($scope.users[u].username == $scope.username){
$scope.message = "username already taken"
return
}
}
$scope.users.unshift({
username:$scope.username,
password:$scope.password
})
$scope.username = null;
$scope.password = null;
$scope.message = "registered"
}
$scope.users = [
{
username:'Nisarg',
password:'Hello2'
}
]
$scope.posts = [
{
username: 'dickeyxxx',
title: 'Node rules!',
comment: 'Node-rules is a light weight forward chaining Rule Engine, written in JavaScript for both browser and node.js environments',
},
{
username: 'jeffdickey',
title: 'trying out angular.js...',
comment: "As you expand your tests, keep an eye out for locations where you can use beforeEach to tidy up tests. beforeEach isn't the only function of this sort that Jasmine",
}
]
})