Added new modules to help prevent Cross Site Request Forgery
[sdnc/oam.git] / admportal / views / user / list.ejs
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4   <meta charset="utf-8" />
5   <meta http-equiv="X-UA-Compatible" content="IE=edge">
6   <% include ../partials/head %>
7   <% include ../partials/header %>
8   <script type="text/javascript" src="/javascripts/admportal.js" async></script>
9   <title>AdminPortal</title>
10 <script class="init">
11     $(document).ready(function() {
12     $('#user_admin').DataTable( {
13         "order": [[ 0, "asc" ]]
14     } );
15 } );
16 </script>
17
18 </head>
19
20 <body>
21
22 <div class="well well-sm">
23 <h3>User Administration</h3>
24 </div>
25
26 <% if ( typeof result != 'undefined' ) {
27         if (result.code.length > 0) {
28             if ( result.code == 'success' ) { %>
29                 <div class='alert alert-success' role='alert'><%=result.msg %></div>
30             <% } else { %>
31                 <div class='alert alert-danger' role='danger'><%=result.msg %></div>
32             <% } %>
33         <% } %>
34 <% } %>
35
36 <% if( typeof privilege != 'undefined'){
37     var priv = privilege.privilege;
38 } else {
39     var priv = 'A';
40 } %>
41
42
43 <div class="container-fluid">
44     <div class="actions" style="padding:15px 0px;">
45         <% if(priv == 'A') { %>
46         <button class="btn btn-primary" data-toggle="modal" data-target="#new_user">Add User</button>
47         <% } %>
48
49     </div>
50     <div class="content">
51      <table id="user_admin" class="table table-hover table-condensed">
52       <thead>
53         <tr>
54                         <th>Email</th>
55                 <th>Password</th>
56                 <th>Privilege</th>
57                         <% if(priv == 'A'){ %>
58                 <th>Action</th>
59                         <% } %>
60         </tr>
61       </thead>
62       <tbody>
63     <% if (rows)  {
64          rows.forEach(function(row) { %>
65                         <tr>
66             <td><%= row.email %></td> 
67             <td>**********</td> 
68             <td>
69                                 <% if(row.privilege == 'A'){ %>
70                                         Administrator
71                                 <% } else if (row.privilege == 'R') { %>
72                                         Readonly
73                                 <% } else { %>
74                                         unknown
75                                 <% } %>
76                         </td> 
77                         <% if(priv == 'A') { %>
78                         <td>
79                                 <form name="rowform">
80                                         <button type="button" class="btn btn-default btn-xs"
81                                                 onclick="updateRequest('<%=row.email %>', '<%=row.password %>', '<%=row.privilege %>');">Update</button>
82                                         <button type="button" class="btn btn-default btn-xs"
83                                                 onclick="deleteRequest('<%=row.email %>');">Delete</button>
84                                 </form>
85                         </td>
86                         <% } %>
87                         </tr>
88     <% }); }; %>
89       </tbody>
90     </table>
91    </div>
92
93    <% include ../partials/newuserform %>
94    <% include ../partials/userform %>
95
96     <footer>
97         <% include ../partials/footer %>
98     </footer>
99     
100 <script type="text/javascript">
101
102 function submitUserAdmin(form)
103 {
104         var errorMsg='';
105         var email = '';
106         var password = '';
107         var confirm_password = '';
108         var privilege = '';
109
110     if ( form.name == 'addForm' )
111     {
112         email = form.nf_email;
113         password = form.nf_password;
114         confirm_password = form.nf_confirm_password;
115         privilege = form.nf_privilege;
116
117         if ( (email.value == null) || (email.value == "") || isblank(email.value) )
118         {
119                 errorMsg += 'Email is required.<br>';
120         }
121         if( errorMsg.length > 0 ) {
122                 bootbox.alert(errorMsg);
123                 return;
124         }
125
126         if ( password.value != confirm_password.value )
127         {
128             bootbox.alert('Passwords do not match.');
129             return;
130         }
131     }
132     else
133     {
134         email = form.uf_email;
135         password = form.uf_password;
136         confirm_password = form.uf_confirm_password;
137         privilege = form.uf_privilege;
138
139         if ( (email.value == null) || (email.value == "") || isblank(email.value) )
140         {
141                 errorMsg += 'Email is required.<br>';
142         }
143         if ( password.value != confirm_password.value )
144         {
145             bootbox.alert('Passwords do not match.');
146             return;
147         }
148     }
149     form.submit();
150 }
151
152 function deleteRequest(email) {
153
154         bootbox.confirm({
155                 message: "Are you sure you want to delete user [" + email + "] ?",
156                 callback: function(result) {
157                         if ( result )
158                         {
159                                 location.assign("/user/deleteUser?email=" + email);
160                         }
161                         return;
162                 },
163                 buttons: {
164                 cancel: {
165                         label: "Cancel"
166                 },
167                 confirm: {
168                         label: "Yes"
169                 }
170                 }
171         });
172 }
173 function updateRequest(email,password,privilege) {
174
175         document.getElementById('uf_email').value = email;
176         document.getElementById('uf_key_email').value = email;
177         document.getElementById('uf_password').value = password;
178         document.getElementById('uf_confirm_password').value = password;
179         if ( privilege == "A" ){
180                 document.getElementById('uf_privilege').value = 'admin';
181         }else if (privilege == "R"){
182                 document.getElementById('uf_privilege').value = 'readonly';
183         }else{
184                 document.getElementById('uf_privilege').value = 'admin';
185         }
186         document.getElementById('uf_action').value = "/user/updateUser";
187         $('#myUserModal').modal('show');
188      
189 }
190 </script>
191
192 </body>
193 </html>
194